Skip to content

Commit

Permalink
Add sergeant role (second LEO supervisor)
Browse files Browse the repository at this point in the history
  • Loading branch information
glxgxr committed Jun 18, 2024
1 parent 5c00213 commit 3ecaec6
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 0 deletions.
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/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
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

0 comments on commit 3ecaec6

Please sign in to comment.