Skip to content

Commit

Permalink
take admin rights away from editors
Browse files Browse the repository at this point in the history
  • Loading branch information
Metauriel committed Dec 13, 2024
1 parent 89bd3b9 commit 9868323
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ export class Migration20241210152600 extends Migration {
{ name: 'roomeditor' },
{
$set: {
permissions: ['ROOM_VIEW', 'ROOM_EDIT', 'ROOM_MEMBERS_ADD', 'ROOM_MEMBERS_REMOVE'],
permissions: ['ROOM_VIEW', 'ROOM_EDIT'],
},
}
);

if (roomEditorRoleUpdate.modifiedCount > 0) {
console.info(
'Permission ROOM_DELETE removed from and ROOM_MEMBERS_ADD and ROOM_MEMBERS_REMOVE added to role roomeditor.'
);
console.info('Permission ROOM_DELETE removed from role roomeditor.');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,18 @@ describe('Room Controller (API)', () => {
const teacherGuestRole = roleFactory.buildWithId({ name: RoleName.GUESTTEACHER });
const studentGuestRole = roleFactory.buildWithId({ name: RoleName.GUESTSTUDENT });
const role = roleFactory.buildWithId({
name: RoleName.ROOMEDITOR,
name: RoleName.ROOMADMIN,
permissions: [
Permission.ROOM_VIEW,
Permission.ROOM_EDIT,
Permission.ROOM_MEMBERS_ADD,
Permission.ROOM_MEMBERS_REMOVE,
],
});
const roomEditorRole = roleFactory.buildWithId({
name: RoleName.ROOMEDITOR,
permissions: [Permission.ROOM_VIEW, Permission.ROOM_EDIT],
});
// TODO: add more than one user
const userGroupEntity = groupEntityFactory.buildWithId({
users: [{ role, user: teacherUser }],
Expand All @@ -82,6 +86,7 @@ describe('Room Controller (API)', () => {
teacherUser,
teacherGuestRole,
studentGuestRole,
roomEditorRole,
otherTeacherUser,
otherTeacherAccount,
userGroupEntity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,42 +52,42 @@ describe('Room Controller (API)', () => {
Permission.ROOM_VIEW,
Permission.ROOM_EDIT,
Permission.ROOM_DELETE,
Permission.ROOM_MEMBERS_ADD, // for now room_editors have these two rights as room_admins are not yet available
Permission.ROOM_MEMBERS_ADD,
Permission.ROOM_MEMBERS_REMOVE,
],
});
const editorRole = roleFactory.buildWithId({
name: RoleName.ROOMEDITOR,
const adminRole = roleFactory.buildWithId({
name: RoleName.ROOMADMIN,
permissions: [
Permission.ROOM_VIEW,
Permission.ROOM_EDIT,
Permission.ROOM_MEMBERS_ADD, // for now room_editors have these two rights as room_admins are not yet available
Permission.ROOM_MEMBERS_ADD,
Permission.ROOM_MEMBERS_REMOVE,
],
});
const viewerRole = roleFactory.buildWithId({
name: RoleName.ROOMVIEWER,
permissions: [Permission.ROOM_VIEW],
});
return { ownerRole, editorRole, viewerRole };
return { ownerRole, adminRole, viewerRole };
};

const setupRoomWithMembers = async () => {
const school = schoolEntityFactory.buildWithId();
const room = roomEntityFactory.buildWithId({ schoolId: school.id });

const { teacherAccount, teacherUser } = UserAndAccountTestFactory.buildTeacher({ school });
const { teacherUser: inRoomEditor2 } = UserAndAccountTestFactory.buildTeacher({ school: teacherUser.school });
const { teacherUser: inRoomEditor3 } = UserAndAccountTestFactory.buildTeacher({ school: teacherUser.school });
const { teacherUser: inRoomAdmin2 } = UserAndAccountTestFactory.buildTeacher({ school: teacherUser.school });
const { teacherUser: inRoomAdmin3 } = UserAndAccountTestFactory.buildTeacher({ school: teacherUser.school });
const { teacherUser: inRoomViewer } = UserAndAccountTestFactory.buildTeacher({ school: teacherUser.school });
const { teacherUser: outTeacher } = UserAndAccountTestFactory.buildTeacher({ school: teacherUser.school });

const users = { teacherUser, inRoomEditor2, inRoomEditor3, inRoomViewer, outTeacher };
const users = { teacherUser, inRoomAdmin2, inRoomAdmin3, inRoomViewer, outTeacher };

const { ownerRole, editorRole, viewerRole } = setupRoomRoles();
const { ownerRole, adminRole, viewerRole } = setupRoomRoles();

const roomUsers = [teacherUser, inRoomEditor2, inRoomEditor3].map((user) => {
return { role: editorRole, user };
const roomUsers = [teacherUser, inRoomAdmin2, inRoomAdmin3].map((user) => {
return { role: adminRole, user };
});
roomUsers.push({ role: viewerRole, user: inRoomViewer });

Expand Down Expand Up @@ -159,9 +159,9 @@ describe('Room Controller (API)', () => {
describe('when the user has the required permissions', () => {
describe('when removing a user from the room', () => {
it('should return OK', async () => {
const { loggedInClient, room, inRoomEditor2 } = await setupRoomWithMembers();
const { loggedInClient, room, inRoomAdmin2 } = await setupRoomWithMembers();

const userIds = [inRoomEditor2.id];
const userIds = [inRoomAdmin2.id];
const response = await loggedInClient.patch(`/${room.id}/members/remove`, { userIds });

expect(response.status).toBe(HttpStatus.OK);
Expand All @@ -170,9 +170,9 @@ describe('Room Controller (API)', () => {

describe('when removing several users from the room', () => {
it('should return OK', async () => {
const { loggedInClient, room, inRoomEditor2, inRoomEditor3 } = await setupRoomWithMembers();
const { loggedInClient, room, inRoomAdmin2, inRoomAdmin3 } = await setupRoomWithMembers();

const userIds = [inRoomEditor2.id, inRoomEditor3.id];
const userIds = [inRoomAdmin2.id, inRoomAdmin3.id];
const response = await loggedInClient.patch(`/${room.id}/members/remove`, { userIds });

expect(response.status).toBe(HttpStatus.OK);
Expand Down
4 changes: 1 addition & 3 deletions backup/setup/roles.json
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,7 @@
"name": "roomeditor",
"permissions": [
"ROOM_VIEW",
"ROOM_EDIT",
"ROOM_MEMBERS_ADD",
"ROOM_MEMBERS_REMOVE"
"ROOM_EDIT"
]
},
{
Expand Down

0 comments on commit 9868323

Please sign in to comment.