mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 17:56:30 -05:00
fix: permissions service use new SpecialGroup enum
instead of random strings the permissions service now uses the SpecialGroup enum Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
5fd9750d68
commit
bcf35c61a5
2 changed files with 31 additions and 13 deletions
|
@ -11,6 +11,7 @@ import { AuthToken } from '../auth/auth-token.entity';
|
||||||
import { Author } from '../authors/author.entity';
|
import { Author } from '../authors/author.entity';
|
||||||
import appConfigMock from '../config/mock/app.config.mock';
|
import appConfigMock from '../config/mock/app.config.mock';
|
||||||
import { Group } from '../groups/group.entity';
|
import { Group } from '../groups/group.entity';
|
||||||
|
import { SpecialGroup } from '../groups/groups.special';
|
||||||
import { Identity } from '../identity/identity.entity';
|
import { Identity } from '../identity/identity.entity';
|
||||||
import { LoggerModule } from '../logger/logger.module';
|
import { LoggerModule } from '../logger/logger.module';
|
||||||
import { Alias } from '../notes/alias.entity';
|
import { Alias } from '../notes/alias.entity';
|
||||||
|
@ -134,7 +135,7 @@ describe('PermissionsService', () => {
|
||||||
note7.userPermissions.push(noteUserPermission2);
|
note7.userPermissions.push(noteUserPermission2);
|
||||||
|
|
||||||
const everybody = {} as Group;
|
const everybody = {} as Group;
|
||||||
everybody.name = 'everybody';
|
everybody.name = SpecialGroup.EVERYONE;
|
||||||
everybody.special = true;
|
everybody.special = true;
|
||||||
const noteEverybodyRead = createNote(user1);
|
const noteEverybodyRead = createNote(user1);
|
||||||
|
|
||||||
|
@ -261,13 +262,19 @@ describe('PermissionsService', () => {
|
||||||
function createGroups(): { [id: string]: Group } {
|
function createGroups(): { [id: string]: Group } {
|
||||||
const result: { [id: string]: Group } = {};
|
const result: { [id: string]: Group } = {};
|
||||||
|
|
||||||
const everybody: Group = Group.create('everybody', 'Everybody');
|
const everybody: Group = Group.create(
|
||||||
|
SpecialGroup.EVERYONE,
|
||||||
|
SpecialGroup.EVERYONE,
|
||||||
|
);
|
||||||
everybody.special = true;
|
everybody.special = true;
|
||||||
result['everybody'] = everybody;
|
result[SpecialGroup.EVERYONE] = everybody;
|
||||||
|
|
||||||
const loggedIn = Group.create('loggedIn', 'loggedIn');
|
const loggedIn = Group.create(
|
||||||
|
SpecialGroup.LOGGED_IN,
|
||||||
|
SpecialGroup.LOGGED_IN,
|
||||||
|
);
|
||||||
loggedIn.special = true;
|
loggedIn.special = true;
|
||||||
result['loggedIn'] = loggedIn;
|
result[SpecialGroup.LOGGED_IN] = loggedIn;
|
||||||
|
|
||||||
const user1group = Group.create('user1group', 'user1group');
|
const user1group = Group.create('user1group', 'user1group');
|
||||||
user1group.members = [user1];
|
user1group.members = [user1];
|
||||||
|
@ -304,11 +311,23 @@ describe('PermissionsService', () => {
|
||||||
return NoteGroupPermission.create(group, write);
|
return NoteGroupPermission.create(group, write);
|
||||||
}
|
}
|
||||||
|
|
||||||
const everybodyRead = createNoteGroupPermission(groups['everybody'], false);
|
const everybodyRead = createNoteGroupPermission(
|
||||||
const everybodyWrite = createNoteGroupPermission(groups['everybody'], true);
|
groups[SpecialGroup.EVERYONE],
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
const everybodyWrite = createNoteGroupPermission(
|
||||||
|
groups[SpecialGroup.EVERYONE],
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
const loggedInRead = createNoteGroupPermission(groups['loggedIn'], false);
|
const loggedInRead = createNoteGroupPermission(
|
||||||
const loggedInWrite = createNoteGroupPermission(groups['loggedIn'], true);
|
groups[SpecialGroup.LOGGED_IN],
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
const loggedInWrite = createNoteGroupPermission(
|
||||||
|
groups[SpecialGroup.LOGGED_IN],
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
const user1groupRead = createNoteGroupPermission(
|
const user1groupRead = createNoteGroupPermission(
|
||||||
groups['user1group'],
|
groups['user1group'],
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
import { SpecialGroup } from '../groups/groups.special';
|
||||||
import { Note } from '../notes/note.entity';
|
import { Note } from '../notes/note.entity';
|
||||||
import { User } from '../users/user.entity';
|
import { User } from '../users/user.entity';
|
||||||
|
|
||||||
|
@ -102,16 +103,14 @@ export class PermissionsService {
|
||||||
if (groupPermission.canEdit || !wantEdit) {
|
if (groupPermission.canEdit || !wantEdit) {
|
||||||
// Handle special groups
|
// Handle special groups
|
||||||
if (groupPermission.group.special) {
|
if (groupPermission.group.special) {
|
||||||
if (groupPermission.group.name == 'loggedIn') {
|
if (groupPermission.group.name == SpecialGroup.LOGGED_IN) {
|
||||||
// TODO: Name of group for logged in users
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
groupPermission.group.name == 'everybody' &&
|
groupPermission.group.name == SpecialGroup.EVERYONE &&
|
||||||
(groupPermission.canEdit || !wantEdit) &&
|
(groupPermission.canEdit || !wantEdit) &&
|
||||||
guestsAllowed
|
guestsAllowed
|
||||||
) {
|
) {
|
||||||
// TODO: Name of group in which everybody even guests can edit
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue