Skip to content

Commit 6e7d5f7

Browse files
hoeppner-dataportNFriedo
authored andcommitted
BC-11309 - ensure permission GROUP_FULL_ADMIN for all superheros and administrators (#6128)
* ensure permission GROUP_FULL_ADMIN is set for all superheros and administrators
1 parent ad506ed commit 6e7d5f7

File tree

3 files changed

+92
-13
lines changed

3 files changed

+92
-13
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { Migration } from '@mikro-orm/migrations-mongodb';
2+
3+
const config = {
4+
superhero: {
5+
old: [],
6+
new: ['GROUP_FULL_ADMIN'],
7+
},
8+
administrator: {
9+
old: [],
10+
new: ['GROUP_FULL_ADMIN'],
11+
},
12+
};
13+
14+
export class Migration20260216141637 extends Migration {
15+
private async addPermissions(roleName: string, permissions: string | string[]): Promise<void> {
16+
if (typeof permissions === 'string') {
17+
permissions = [permissions];
18+
}
19+
const roleUpdate = await this.getCollection('roles').updateOne(
20+
{ name: roleName },
21+
{
22+
$addToSet: {
23+
permissions: {
24+
$each: permissions,
25+
},
26+
},
27+
}
28+
);
29+
30+
if (roleUpdate.modifiedCount > 0) {
31+
console.info(` Permission added to '${roleName}':\n ${permissions.join(', ')}.\n`);
32+
}
33+
}
34+
35+
private async removePermissions(roleName: string, permissions: string | string[]): Promise<void> {
36+
if (typeof permissions === 'string') {
37+
permissions = [permissions];
38+
}
39+
const roleUpdate = await this.getCollection('roles').updateOne(
40+
{ name: roleName },
41+
{
42+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
43+
// @ts-ignore // MongoDB types are wrong here
44+
$pull: {
45+
permissions: {
46+
$in: permissions,
47+
},
48+
},
49+
}
50+
);
51+
52+
if (roleUpdate.modifiedCount > 0) {
53+
console.info(` Permissions removed from '${roleName}':\n ${permissions.join(', ')}.\n`);
54+
}
55+
}
56+
57+
public async up(): Promise<void> {
58+
for (const [roleName, permissions] of Object.entries(config)) {
59+
await this.removePermissions(roleName, permissions.old);
60+
await this.addPermissions(roleName, permissions.new);
61+
}
62+
}
63+
64+
public async down(): Promise<void> {
65+
for (const [roleName, permissions] of Object.entries(config)) {
66+
await this.removePermissions(roleName, permissions.new);
67+
await this.addPermissions(roleName, permissions.old);
68+
}
69+
}
70+
}

backup/setup/migrations.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,14 @@
9797
"created_at": {
9898
"$date": "2026-02-02T12:44:13.220Z"
9999
}
100+
},
101+
{
102+
"_id": {
103+
"$oid": "6993293e81878b214983a8e7"
104+
},
105+
"name": "Migration20260216141637",
106+
"executed_at": {
107+
"$date": "2026-02-16T14:27:10.822Z"
108+
}
100109
}
101-
]
110+
]

backup/setup/roles.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@
138138
"START_MEETING",
139139
"JOIN_MEETING",
140140
"GROUP_LIST",
141-
"GROUP_FULL_ADMIN",
142141
"SCHOOL_SYSTEM_EDIT",
143142
"SCHOOL_SYSTEM_VIEW",
144143
"USER_CHANGE_OWN_NAME",
145144
"MEDIA_SCHOOL_LICENSE_ADMIN",
146145
"SCHOOL_LIST_DISCOVERABLE_TEACHERS",
147146
"SCHOOL_ADMINISTRATE_ROOMS",
148-
"SCHOOL_LIST_ROOM_MEMBERS"
147+
"SCHOOL_LIST_ROOM_MEMBERS",
148+
"GROUP_FULL_ADMIN"
149149
],
150150
"__v": 2
151151
},
@@ -203,15 +203,15 @@
203203
"TOOL_EDIT",
204204
"YEARS_EDIT",
205205
"GROUP_LIST",
206-
"GROUP_FULL_ADMIN",
207206
"USER_CHANGE_OWN_NAME",
208207
"ACCOUNT_VIEW",
209208
"ACCOUNT_DELETE",
210209
"USER_LOGIN_MIGRATION_FORCE",
211210
"USER_LOGIN_MIGRATION_ROLLBACK",
212211
"MEDIA_SOURCE_ADMIN",
213212
"INSTANCE_EDIT",
214-
"CAN_EXECUTE_INSTANCE_OPERATIONS"
213+
"CAN_EXECUTE_INSTANCE_OPERATIONS",
214+
"GROUP_FULL_ADMIN"
215215
],
216216
"__v": 2
217217
},
@@ -221,7 +221,7 @@
221221
},
222222
"name": "teacher",
223223
"updatedAt": {
224-
"$date": "2025-07-31T12:29:47.091Z"
224+
"$date": "2026-02-16T14:26:29.665Z"
225225
},
226226
"createdAt": {
227227
"$date": "2017-01-01T00:06:37.148Z"
@@ -646,13 +646,6 @@
646646
"name": "guestTeacher",
647647
"permissions": []
648648
},
649-
{
650-
"_id": {
651-
"$oid": "68ece70b963025351f0a98c4"
652-
},
653-
"name": "guestExternalPerson",
654-
"permissions": []
655-
},
656649
{
657650
"_id": {
658651
"$oid": "675abdb4e76b1142cd4c89e3"
@@ -702,5 +695,12 @@
702695
},
703696
"name": "roomapplicant",
704697
"permissions": []
698+
},
699+
{
700+
"_id": {
701+
"$oid": "68ece70b963025351f0a98c4"
702+
},
703+
"name": "guestExternalPerson",
704+
"permissions": []
705705
}
706706
]

0 commit comments

Comments
 (0)