Skip to content

Commit

Permalink
BC-7314 Fix resolving of LERNSTORE_VIEW permission (#4997)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyedwiper authored and wolfganggreschus committed May 13, 2024
1 parent f5a36a0 commit 8ae9d24
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
38 changes: 38 additions & 0 deletions apps/server/src/shared/domain/entity/user.entity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,44 @@ describe('User Entity', () => {
});

describe('when user is a student', () => {
describe('when LERNSTORE_VIEW permission is not set for school', () => {
describe('when user has LERNSTORE_VIEW permission from his role', () => {
const setup = () => {
const role = roleFactory.build({ name: RoleName.STUDENT, permissions: [Permission.LERNSTORE_VIEW] });
const school = schoolEntityFactory.build();
const user = userFactory.build({ roles: [role], school });

return { user };
};

it('should return the unchanged permissions of the user', () => {
const { user } = setup();

const result = user.resolvePermissions();

expect(result.sort()).toEqual([Permission.LERNSTORE_VIEW].sort());
});
});

describe('when user does not have LERNSTORE_VIEW permission from his role', () => {
const setup = () => {
const role = roleFactory.build({ name: RoleName.STUDENT, permissions: [permissionA] });
const school = schoolEntityFactory.build();
const user = userFactory.build({ roles: [role], school });

return { user };
};

it('should return the unchanged permissions of the user', () => {
const { user } = setup();

const result = user.resolvePermissions();

expect(result.sort()).toEqual([permissionA].sort());
});
});
});

describe('when school permissions `LERNSTORE_VIEW` is true', () => {
const setup = () => {
const role = roleFactory.build({ name: RoleName.STUDENT, permissions: [permissionA] });
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/shared/domain/entity/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ export class User extends BaseEntityWithTimestamps implements EntityWithSchool {
setOfPermissions: Set<string>,
schoolPermissions?: SchoolRoles
): Set<string> {
if (schoolPermissions?.student?.LERNSTORE_VIEW) {
if (schoolPermissions?.student?.LERNSTORE_VIEW === true) {
setOfPermissions.add(Permission.LERNSTORE_VIEW);
} else {
} else if (schoolPermissions?.student?.LERNSTORE_VIEW === false) {
setOfPermissions.delete(Permission.LERNSTORE_VIEW);
}

Expand Down

0 comments on commit 8ae9d24

Please sign in to comment.