mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 01:35:18 -04:00
feat(config): add config vars for default permissions for special groups
Co-authored-by: Tilman Vatteroth <git@tilmanvatteroth.de> Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de> Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
7dd093a44f
commit
df976b5fe1
10 changed files with 518 additions and 36 deletions
|
@ -96,6 +96,26 @@ export class NotesService {
|
|||
HistoryEntry.create(owner, newNote as Note) as HistoryEntry,
|
||||
]);
|
||||
}
|
||||
|
||||
const everyonePermission = this.createGroupPermission(
|
||||
newNote as Note,
|
||||
await this.groupsService.getEveryoneGroup(),
|
||||
owner === null
|
||||
? DefaultAccessPermission.WRITE
|
||||
: this.noteConfig.permissions.default.everyone,
|
||||
);
|
||||
|
||||
const loggedInPermission = this.createGroupPermission(
|
||||
newNote as Note,
|
||||
await this.groupsService.getLoggedInGroup(),
|
||||
this.noteConfig.permissions.default.loggedIn,
|
||||
);
|
||||
|
||||
newNote.groupPermissions = Promise.resolve([
|
||||
...Optional.ofNullable(everyonePermission).wrapInArray(),
|
||||
...Optional.ofNullable(loggedInPermission).wrapInArray(),
|
||||
]);
|
||||
|
||||
try {
|
||||
return await this.noteRepository.save(newNote);
|
||||
} catch (e) {
|
||||
|
@ -113,6 +133,20 @@ export class NotesService {
|
|||
}
|
||||
}
|
||||
|
||||
private createGroupPermission(
|
||||
note: Note,
|
||||
group: Group,
|
||||
permission: DefaultAccessPermission,
|
||||
): NoteGroupPermission | null {
|
||||
return permission === DefaultAccessPermission.NONE
|
||||
? null
|
||||
: NoteGroupPermission.create(
|
||||
group,
|
||||
note,
|
||||
permission === DefaultAccessPermission.WRITE,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @async
|
||||
* Get the current content of the note.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue