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

Add sergeant role (second LEO supervisor) #1949

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- AlterTable
ALTER TABLE "DiscordRoles" ADD COLUMN "sergeantRolePermissions" TEXT[];

-- CreateTable
CREATE TABLE "_sergeantRoles" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "_sergeantRoles_AB_unique" ON "_sergeantRoles"("A", "B");

-- CreateIndex
CREATE INDEX "_sergeantRoles_B_index" ON "_sergeantRoles"("B");

-- AddForeignKey
ALTER TABLE "_sergeantRoles" ADD CONSTRAINT "_sergeantRoles_A_fkey" FOREIGN KEY ("A") REFERENCES "DiscordRole"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_sergeantRoles" ADD CONSTRAINT "_sergeantRoles_B_fkey" FOREIGN KEY ("B") REFERENCES "DiscordRoles"("id") ON DELETE CASCADE ON UPDATE CASCADE;
3 changes: 3 additions & 0 deletions apps/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ model DiscordRoles {

leoRoles DiscordRole[] @relation("leoRoles")
leoSupervisorRoles DiscordRole[] @relation("leoSupervisorRoles")
sergeantRoles DiscordRole[] @relation("sergeantRoles")
emsFdRoles DiscordRole[] @relation("emsFdRoles")
dispatchRoles DiscordRole[] @relation("dispatchRoles")
towRoles DiscordRole[] @relation("towRoles")
Expand All @@ -204,6 +205,7 @@ model DiscordRoles {
adminRolePermissions String[]
leoRolePermissions String[]
leoSupervisorRolePermissions String[]
sergeantRolePermissions String[]
emsFdRolePermissions String[]
dispatchRolePermissions String[]
towRolePermissions String[]
Expand All @@ -227,6 +229,7 @@ model DiscordRole {
whitelistedRoles DiscordRoles[] @relation("whitelistedRole")
dispatchRolesArr DiscordRoles[] @relation("dispatchRoles")
leoSupervisorRolesArr DiscordRoles[] @relation("leoSupervisorRoles")
sergeantRolesArr DiscordRoles[] @relation("sergeantRoles")
taxiRolesArr DiscordRoles[] @relation("taxiRoles")
towRolesArr DiscordRoles[] @relation("towRoles")
courthouseRoles DiscordRoles[] @relation("courthouseRoles")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class DiscordSettingsController {
leoRoles: data.leoRoles,
emsFdRoles: data.emsFdRoles,
leoSupervisorRoles: data.leoSupervisorRoles,
sergeantRoles: data.sergeantRoles,
dispatchRoles: data.dispatchRoles,
courthouseRoles: data.courthouseRoles,
towRoles: data.towRoles,
Expand All @@ -132,6 +133,7 @@ export class DiscordSettingsController {
adminRolePermissions: data.adminRolePermissions ?? [],
leoRolePermissions: data.leoRolePermissions ?? [],
leoSupervisorRolePermissions: data.leoSupervisorRolePermissions ?? [],
sergeantRolePermissions: data.sergeantRolePermissions ?? [],
emsFdRolePermissions: data.emsFdRolePermissions ?? [],
dispatchRolePermissions: data.dispatchRolePermissions ?? [],
towRolePermissions: data.towRolePermissions ?? [],
Expand All @@ -148,6 +150,7 @@ export class DiscordSettingsController {
leoRoles: true,
emsFdRoles: true,
leoSupervisorRoles: true,
sergeantRoles: true,
towRoles: true,
taxiRoles: true,
dispatchRoles: true,
Expand Down Expand Up @@ -180,6 +183,12 @@ export class DiscordSettingsController {
newRoles: (data.leoSupervisorRoles as string[] | null) ?? [],
type: "leoSupervisorRoles",
}),
...this.updateRoles({
discordRoleId: discordRoles.id,
discordRoles: discordRoles.sergeantRoles,
newRoles: (data.sergeantRoles as string[] | null) ?? [],
type: "sergeantRoles",
}),
...this.updateRoles({
discordRoleId: discordRoles.id,
discordRoles: discordRoles.towRoles,
Expand Down Expand Up @@ -217,6 +226,7 @@ export class DiscordSettingsController {
leoRoles: true,
emsFdRoles: true,
leoSupervisorRoles: true,
sergeantRoles: true,
towRoles: true,
taxiRoles: true,
dispatchRoles: true,
Expand Down Expand Up @@ -269,6 +279,7 @@ interface UpdateRolesOptions {
| "leoRoles"
| "emsFdRoles"
| "leoSupervisorRoles"
| "sergeantRoles"
| "dispatchRoles"
| "towRoles"
| "taxiRoles"
Expand Down
3 changes: 3 additions & 0 deletions apps/api/src/lib/discord/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export async function updateMemberRolesLogin<
towRoles: true,
taxiRoles: true,
leoSupervisorRoles: true,
sergeantRoles: true,
courthouseRoles: true,
},
});
Expand All @@ -83,6 +84,7 @@ export async function updateMemberRolesLogin<
const isTow = doesDiscordMemberHaveCADRole(discordRoles.towRoles, memberObj);
const isTaxi = doesDiscordMemberHaveCADRole(discordRoles.taxiRoles, memberObj);
const isSupervisor = doesDiscordMemberHaveCADRole(discordRoles.leoSupervisorRoles, memberObj);
const isSergeant = doesDiscordMemberHaveCADRole(discordRoles.sergeantRoles, memberObj);
const isCourthouse = doesDiscordMemberHaveCADRole(discordRoles.courthouseRoles, memberObj);
const isAdmin = doesDiscordMemberHaveCADRole(discordRoles.adminRoles, memberObj);
const hasWhitelistAccess = doesDiscordMemberHaveCADRole(
Expand All @@ -93,6 +95,7 @@ export async function updateMemberRolesLogin<
const grantablePermissions = {
leo: { permissions: discordRoles.leoRolePermissions, value: isLeo },
supervisor: { permissions: discordRoles.leoSupervisorRolePermissions, value: isSupervisor },
sergeant: { permissions: discordRoles.sergeantRolePermissions, value: isSergeant },
emsFd: { permissions: discordRoles.emsFdRolePermissions, value: isEmsFd },
dispatch: { permissions: discordRoles.dispatchRolePermissions, value: isDispatch },
tow: { permissions: discordRoles.towRolePermissions, value: isTow },
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/middlewares/auth/is-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export function CAD_SELECT(options: CadSelectOptions) {
leoRoles: true,
emsFdRoles: true,
leoSupervisorRoles: true,
sergeantRoles: true,
towRoles: true,
taxiRoles: true,
dispatchRoles: true,
Expand Down
2 changes: 2 additions & 0 deletions apps/client/locales/cn/cad-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"leoRoleInfo": "The Discord Role that will represent set LEO permissions in the CAD.",
"leoSupervisorRole": "LEO Supervisor Role",
"leoSupervisorRoleInfo": "The Discord Role that will represent set LEO Supervisor permissions in the CAD.",
"sergeantRole": "Sergeant Role",
"sergeantRoleInfo": "The Discord Role that will represent set Sergeant permissions in the CAD.",
"emsFdRole": "EMS/FD Role",
"emsFdRoleInfo": "The Discord Role that will represent set EMS/FD permissions in the CAD.",
"dispatchRole": "Dispatch Role",
Expand Down
2 changes: 2 additions & 0 deletions apps/client/locales/cs-CZ/cad-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"leoRoleInfo": "The Discord Role that will represent set LEO permissions in the CAD.",
"leoSupervisorRole": "LEO Supervisor Role",
"leoSupervisorRoleInfo": "The Discord Role that will represent set LEO Supervisor permissions in the CAD.",
"sergeantRole": "Sergeant Role",
"sergeantRoleInfo": "The Discord Role that will represent set Sergeant permissions in the CAD.",
"emsFdRole": "EMS/FD Role",
"emsFdRoleInfo": "The Discord Role that will represent set EMS/FD permissions in the CAD.",
"dispatchRole": "Dispatch Role",
Expand Down
2 changes: 2 additions & 0 deletions apps/client/locales/de-DE/cad-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"leoRoleInfo": "Die Discord-Rolle, die die gesetzten PD-Berechtigungen im CAD repräsentiert.",
"leoSupervisorRole": "PD-Supervisor-Rolle",
"leoSupervisorRoleInfo": "Die Discord-Rolle, die die gesetzten LEO-Supervisor-Berechtigungen im CAD repräsentieren wird.",
"sergeantRole": "Sergeant-Rolle",
"sergeantRoleInfo": "Die Discord-Rolle, die die gesetzten Sergeant-Berechtigungen im CAD repräsentiert.",
"emsFdRole": "EMS/FD-Rolle",
"emsFdRoleInfo": "Die Discord-Rolle, die die eingestellten EMS/FD-Berechtigungen im CAD darstellt",
"dispatchRole": "Dispatch Role",
Expand Down
2 changes: 2 additions & 0 deletions apps/client/locales/en-gb/cad-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"leoRoleInfo": "The Discord Role that will represent set police permissions in the CAD.",
"leoSupervisorRole": "Senior Policing Role",
"leoSupervisorRoleInfo": "The Discord Role that will represent set senior policing permissions in the CAD.",
"sergeantRole": "Sergeant Role",
"sergeantRoleInfo": "The Discord Role that will represent set Sergeant permissions in the CAD.",
"emsFdRole": "Emergency Services Role",
"emsFdRoleInfo": "The Discord Role that will represent set emergency services permissions in the CAD.",
"dispatchRole": "Control Role",
Expand Down
2 changes: 2 additions & 0 deletions apps/client/locales/en/cad-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"leoRoleInfo": "The Discord Role that will represent set LEO permissions in the CAD.",
"leoSupervisorRole": "LEO Supervisor Role",
"leoSupervisorRoleInfo": "The Discord Role that will represent set LEO Supervisor permissions in the CAD.",
"sergeantRole": "Sergeant Role",
"sergeantRoleInfo": "The Discord Role that will represent set Sergeant permissions in the CAD.",
"emsFdRole": "EMS/FD Role",
"emsFdRoleInfo": "The Discord Role that will represent set EMS/FD permissions in the CAD.",
"dispatchRole": "Dispatch Role",
Expand Down
2 changes: 2 additions & 0 deletions apps/client/locales/fr-FR/cad-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"leoRoleInfo": "Le rôle Discord qui représentera les autorisations LEO définies dans le CAD.",
"leoSupervisorRole": "Rôle superviseur LEO",
"leoSupervisorRoleInfo": "Le rôle Discord qui représentera les autorisations définies du superviseur LEO dans le CAD.",
"sergeantRole": "Rôle de sergent",
"sergeantRoleInfo": "Le rôle Discord qui représentera les permissions du sergent dans le CAO.",
"emsFdRole": "Rôle EMS/FD",
"emsFdRoleInfo": "Le rôle Discord qui représentera les autorisations EMS/FD définies dans le CAD.",
"dispatchRole": "Rôle de répartition",
Expand Down
2 changes: 2 additions & 0 deletions apps/client/locales/nl-BE/cad-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"leoRoleInfo": "De Discord Rol die de ingestelde LEO rechten in de CAD weergeeft.",
"leoSupervisorRole": "Rol van LEO Supervisor",
"leoSupervisorRoleInfo": "De Discord Rol die staat voor ingestelde LEO Supervisor permissies in de CAD.",
"sergeantRole": "Sergeant Rol",
"sergeantRoleInfo": "De Discord-rol die staat voor ingestelde sergeant-rechten in de CAD.",
"emsFdRole": "EMS/FD Rol",
"emsFdRoleInfo": "De Discord Rol die staat voor ingestelde EMS/FD rechten in de CAD.",
"dispatchRole": "Dispatch Rol",
Expand Down
2 changes: 2 additions & 0 deletions apps/client/locales/pt-BR/cad-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"leoRoleInfo": "O Cargo do Discord que representará as permissões policiais definidas no CAD.",
"leoSupervisorRole": "Cargo de Supervisor Policial",
"leoSupervisorRoleInfo": "O Cargo do Discord que representará as permissões do Supervisor policial definidas no CAD.",
"sergeantRole": "Função de Sargento",
"sergeantRoleInfo": "A função do Discord que representará as permissões definidas do Sargento no CAD.",
"emsFdRole": "Cargo Médico/Bombeiro",
"emsFdRoleInfo": "O Cargo do Discord que representará o conjunto de permissões Médico/Bombeiro no CAD.",
"dispatchRole": "Cargo da Central",
Expand Down
2 changes: 2 additions & 0 deletions apps/client/locales/ru/cad-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"leoRoleInfo": "Роль Discord, которая будет устанавливать права LEO в CAD.",
"leoSupervisorRole": "Роль супервайзера LEO",
"leoSupervisorRoleInfo": "Роль Discord, которая будет устанавливать права супервайзера LEO в CAD.",
"sergeantRole": "Роль сержанта",
"sergeantRoleInfo": "Роль Discord, которая будет представлять набор полномочий сержанта в CAD.",
"emsFdRole": "Роль EMS/FD",
"emsFdRoleInfo": "Роль Discord, которая будет устанавливать права EMS/FD в CAD.",
"dispatchRole": "Роль диспетчера",
Expand Down
2 changes: 2 additions & 0 deletions apps/client/locales/sv/cad-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"leoRoleInfo": "The Discord Role that will represent set LEO permissions in the CAD.",
"leoSupervisorRole": "LEO Supervisor Role",
"leoSupervisorRoleInfo": "The Discord Role that will represent set LEO Supervisor permissions in the CAD.",
"sergeantRole": "Sergeantroll",
"sergeantRoleInfo": "Den Discord-roll som kommer att representera fastställda Sergeant-behörigheter i CAD.",
"emsFdRole": "EMS/FD Role",
"emsFdRoleInfo": "The Discord Role that will represent set EMS/FD permissions in the CAD.",
"dispatchRole": "Dispatch Role",
Expand Down
2 changes: 2 additions & 0 deletions apps/client/locales/tc/cad-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"leoRoleInfo": "Роль Discord, которая будет устанавливать права LEO в CAD.",
"leoSupervisorRole": "Роль супервайзера LEO",
"leoSupervisorRoleInfo": "Роль Discord, которая будет устанавливать права супервайзера LEO в CAD.",
"sergeantRole": "Çavuş Rolü",
"sergeantRoleInfo": "CAD'de ayarlanmış Çavuş izinlerini temsil edecek Discord Rolü.",
"emsFdRole": "Роль EMS/FD",
"emsFdRoleInfo": "Роль Discord, которая будет устанавливать права EMS/FD в CAD.",
"dispatchRole": "Роль диспетчера",
Expand Down
2 changes: 2 additions & 0 deletions apps/client/locales/zh-CN/cad-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"leoRoleInfo": "在CAD中代表设置执法权限的Discord身份组。",
"leoSupervisorRole": "执法人员主管身份组",
"leoSupervisorRoleInfo": "在CAD中代表设置执法监管权限的Discord身份组。",
"sergeantRole": "中士角色",
"sergeantRoleInfo": "代表 CAD 中士官权限设置的 Discord 角色",
"emsFdRole": "EMS/FD身份组",
"emsFdRoleInfo": "在CAD中代表设置EMS/FD权限的Discord身份组。",
"dispatchRole": "调度身份组",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ export function DiscordRolesTab() {
emsFdRoles: makeRoleValues(discordRoles.emsFdRoles),
dispatchRoles: makeRoleValues(discordRoles.dispatchRoles),
leoSupervisorRoles: makeRoleValues(discordRoles.leoSupervisorRoles),
sergeantRoles: makeRoleValues(discordRoles.sergeantRoles),
towRoles: makeRoleValues(discordRoles.towRoles),
taxiRoles: makeRoleValues(discordRoles.taxiRoles),
courthouseRoles: makeRoleValues(discordRoles.courthouseRoles),
whitelistedRoleId: discordRoles.whitelistedRoleId,
adminRolePermissions: makeValue(discordRoles.adminRolePermissions, tPermission),
leoRolePermissions: makeValue(discordRoles.leoRolePermissions, tPermission),
leoSupervisorRolePermissions: makeValue(discordRoles.leoSupervisorRolePermissions, tPermission),
sergeantRolePermissions: makeValue(discordRoles.sergeantRolePermissions, tPermission),
emsFdRolePermissions: makeValue(discordRoles.emsFdRolePermissions, tPermission),
dispatchRolePermissions: makeValue(discordRoles.dispatchRolePermissions, tPermission),
towRolePermissions: makeValue(discordRoles.towRolePermissions, tPermission),
Expand Down Expand Up @@ -97,9 +99,11 @@ export function DiscordRolesTab() {
taxiRoles: toValue(values.taxiRoles),
courthouseRoles: toValue(values.courthouseRoles),
leoSupervisorRoles: toValue(values.leoSupervisorRoles),
sergeantRoles: toValue(values.sergeantRoles),
adminRolePermissions: toValue(values.adminRolePermissions),
leoRolePermissions: toValue(values.leoRolePermissions),
leoSupervisorRolePermissions: toValue(values.leoSupervisorRolePermissions),
sergeantRolePermissions: toValue(values.sergeantRolePermissions),
emsFdRolePermissions: toValue(values.emsFdRolePermissions),
dispatchRolePermissions: toValue(values.dispatchRolePermissions),
towRolePermissions: toValue(values.towRolePermissions),
Expand Down Expand Up @@ -231,6 +235,31 @@ export function DiscordRolesTab() {
/>
</SettingsFormField>

<SettingsFormField
description={t("sergeantRoleInfo")}
errorMessage={errors.sergeantRoles as string}
label={t("sergeantRole")}
>
<Select
isClearable
disabled={Boolean(fetchError)}
isMulti
values={roles.map((role) => ({
value: role.id,
label: role.name,
}))}
value={values.sergeantRoles}
name="sergeantRoles"
onChange={handleChange}
/>

<SelectPermissionsField
disabled={Boolean(fetchError)}
name="sergeantRolePermissions"
permissions={defaultPermissions.defaultSergeantRoles}
/>
</SettingsFormField>

<SettingsFormField
description={t("emsFdRoleInfo")}
errorMessage={errors.emsFdRoles as string}
Expand Down
5 changes: 5 additions & 0 deletions packages/permissions/src/defaults/leo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export const defaultLeoPermissions = [
Permissions.LeoManageCitizenProfile,
];

export const defaultSergeantRoles = [
Permissions.ManageValueOfficerRank,
Permissions.ManageUnitCallsigns,
];

export const defaultDispatchPermissions = [Permissions.Dispatch, Permissions.LiveMap];

export const defaultEmsFdPermissions = [
Expand Down
2 changes: 2 additions & 0 deletions packages/schemas/src/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const DISCORD_SETTINGS_SCHEMA = z.object({
leoRoles: z.array(z.any()).nullish(),
emsFdRoles: z.array(z.any()).nullish(),
leoSupervisorRoles: z.array(z.any()).nullish(),
sergeantRoles: z.array(z.any()).nullish(),
dispatchRoles: z.array(z.any()).nullish(),
towRoles: z.array(z.any()).nullish(),
taxiRoles: z.array(z.any()).nullish(),
Expand All @@ -100,6 +101,7 @@ export const DISCORD_SETTINGS_SCHEMA = z.object({
adminRolePermissions: z.array(z.string()).nullish(),
leoRolePermissions: z.array(z.string()).nullish(),
leoSupervisorRolePermissions: z.array(z.string()).nullish(),
sergeantRolePermissions: z.array(z.string()).nullish(),
emsFdRolePermissions: z.array(z.string()).nullish(),
dispatchRolePermissions: z.array(z.string()).nullish(),
towRolePermissions: z.array(z.string()).nullish(),
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/api/cad-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export type PostCADDiscordRolesData = Prisma.DiscordRoles & {
adminRoles?: Prisma.DiscordRole[];
leoRoles?: Prisma.DiscordRole[];
leoSupervisorRoles?: Prisma.DiscordRole[];
sergeantRoles?: Prisma.DiscordRole[];
emsFdRoles?: Prisma.DiscordRole[];
dispatchRoles?: Prisma.DiscordRole[];
towRoles?: Prisma.DiscordRole[];
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export type DiscordRoles = Prisma.DiscordRoles & {
emsFdRoles?: DiscordRole[];
dispatchRoles?: DiscordRole[];
leoSupervisorRoles?: DiscordRole[];
sergeantRoles?: DiscordRole[];
towRoles?: DiscordRole[];
taxiRoles?: DiscordRole[];
courthouseRoles?: DiscordRole[];
Expand All @@ -83,6 +84,7 @@ export type DiscordRoles = Prisma.DiscordRoles & {
adminRolePermissions: Permissions[];
leoRolePermissions: Permissions[];
leoSupervisorRolePermissions: Permissions[];
sergeantRolePermissions: Permissions[];
emsFdRolePermissions: Permissions[];
dispatchRolePermissions: Permissions[];
towRolePermissions: Permissions[];
Expand Down