Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add per-category blocked roles-list #495

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions db/mysql/migrations/20230309144248_4_0_0/migration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ CREATE TABLE `archivedUsers` (

-- CreateTable
CREATE TABLE `categories` (
`blockedRoles` JSON NOT NULL,
`channelName` VARCHAR(191) NOT NULL,
`claiming` BOOLEAN NOT NULL DEFAULT false,
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
Expand Down
3 changes: 2 additions & 1 deletion db/mysql/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ model ArchivedMessage {

model ArchivedRole {
archivedUsers ArchivedUser[]
colour String @default("5865F2") @db.Char(6) // 7289DA
colour String @default("5865F2") @db.Char(6) // 7289DA
createdAt DateTime @default(now())
name String
roleId String @db.VarChar(19)
Expand Down Expand Up @@ -69,6 +69,7 @@ model ArchivedUser {
}

model Category {
blockedRoles Json @default("[]")
channelName String
claiming Boolean @default(false)
createdAt DateTime @default(now())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ CREATE TABLE "archivedUsers" (

-- CreateTable
CREATE TABLE "categories" (
"blockedRoles" JSONB NOT NULL DEFAULT '[]',
"channelName" TEXT NOT NULL,
"claiming" BOOLEAN NOT NULL DEFAULT false,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
Expand Down
3 changes: 2 additions & 1 deletion db/postgresql/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ model ArchivedMessage {

model ArchivedRole {
archivedUsers ArchivedUser[]
colour String @default("5865F2") @db.Char(6) // 7289DA
colour String @default("5865F2") @db.Char(6) // 7289DA
createdAt DateTime @default(now())
name String
roleId String @db.VarChar(19)
Expand Down Expand Up @@ -68,6 +68,7 @@ model ArchivedUser {
}

model Category {
blockedRoles Json @default("[]")
channelName String
claiming Boolean @default(false)
createdAt DateTime @default(now())
Expand Down
1 change: 1 addition & 0 deletions db/sqlite/migrations/20230309142817_4_0_0/migration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ CREATE TABLE "archivedUsers" (

-- CreateTable
CREATE TABLE "categories" (
"blockedRoles" TEXT NOT NULL DEFAULT '[]',
"channelName" TEXT NOT NULL,
"claiming" BOOLEAN NOT NULL DEFAULT false,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
Expand Down
1 change: 1 addition & 0 deletions db/sqlite/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ model ArchivedUser {
}

model Category {
blockedRoles String @default("[]")
channelName String
claiming Boolean @default(false)
createdAt DateTime @default(now())
Expand Down
1 change: 1 addition & 0 deletions src/lib/middleware/prisma-sqlite.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const jsonFields = [
'pingRoles',
'requiredRoles',
'blockedRoles',
'staffRoles',
'autoTag',
'blocklist',
Expand Down
5 changes: 5 additions & 0 deletions src/lib/tickets/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ module.exports = class TicketManager {
if (blocked) return await sendError('blocked');
}

if (category.blockedRoles.length !== 0) {
const blocked = category.blockedRoles.some(r => member.roles.cache.has(r));
if (blocked) return await sendError('blocked');
}

if (category.requiredRoles.length !== 0) {
const missing = category.requiredRoles.some(r => !member.roles.cache.has(r));
if (missing) return await sendError('missing_roles');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ module.exports.patch = fastify => ({
const data = req.body;

const select = {
blockedRoles: true,
channelName: true,
claiming: true,
// createdAt: true,
Expand Down
1 change: 1 addition & 0 deletions src/routes/api/admin/guilds/[guild]/categories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports.get = fastify => ({
select: {
categories: {
select: {
blockedRoles: true,
createdAt: true,
description: true,
discordCategory: true,
Expand Down