mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-23 19:47:03 -04:00
fix(permissions): remove composite primary keys
TypeORM promises to support composite primary keys, but that does not work in reality. This replaces the composite key used in the permission entities with a single generated primary key and a unique index on the relation columns. See https://github.com/typeorm/typeorm/issues/8513 Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
2689f9f3dc
commit
d1c3058655
7 changed files with 199 additions and 143 deletions
|
@ -57,6 +57,8 @@ describe('NotesService', () => {
|
|||
const content = 'testContent';
|
||||
jest
|
||||
.spyOn(noteRepo, 'save')
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
.mockImplementation(async (note: Note): Promise<Note> => note);
|
||||
const note = await service.createNote(content, null);
|
||||
const revisions = await note.revisions;
|
||||
|
@ -94,19 +96,17 @@ describe('NotesService', () => {
|
|||
note.owner = Promise.resolve(user);
|
||||
note.userPermissions = Promise.resolve([
|
||||
{
|
||||
noteId: note.id,
|
||||
note: note,
|
||||
userId: user.id,
|
||||
user: user,
|
||||
id: 1,
|
||||
note: Promise.resolve(note),
|
||||
user: Promise.resolve(user),
|
||||
canEdit: true,
|
||||
},
|
||||
]);
|
||||
note.groupPermissions = Promise.resolve([
|
||||
{
|
||||
noteId: note.id,
|
||||
note: note,
|
||||
groupId: group.id,
|
||||
group: group,
|
||||
id: 1,
|
||||
note: Promise.resolve(note),
|
||||
group: Promise.resolve(group),
|
||||
canEdit: true,
|
||||
},
|
||||
]);
|
||||
|
@ -291,6 +291,8 @@ describe('NotesService', () => {
|
|||
beforeEach(() => {
|
||||
jest
|
||||
.spyOn(noteRepo, 'save')
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
.mockImplementation(async (note: Note): Promise<Note> => note);
|
||||
});
|
||||
it('without alias, without owner', async () => {
|
||||
|
@ -368,6 +370,8 @@ describe('NotesService', () => {
|
|||
const content = 'testContent';
|
||||
jest
|
||||
.spyOn(noteRepo, 'save')
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
.mockImplementation(async (note: Note): Promise<Note> => note);
|
||||
const newNote = await service.createNote(content, null);
|
||||
const revisions = await newNote.revisions;
|
||||
|
|
|
@ -285,14 +285,18 @@ export class NotesService {
|
|||
const groupPermissions = await note.groupPermissions;
|
||||
return {
|
||||
owner: owner ? owner.username : null,
|
||||
sharedToUsers: userPermissions.map((noteUserPermission) => ({
|
||||
username: noteUserPermission.user.username,
|
||||
canEdit: noteUserPermission.canEdit,
|
||||
})),
|
||||
sharedToGroups: groupPermissions.map((noteGroupPermission) => ({
|
||||
groupName: noteGroupPermission.group.name,
|
||||
canEdit: noteGroupPermission.canEdit,
|
||||
})),
|
||||
sharedToUsers: await Promise.all(
|
||||
userPermissions.map(async (noteUserPermission) => ({
|
||||
username: (await noteUserPermission.user).username,
|
||||
canEdit: noteUserPermission.canEdit,
|
||||
})),
|
||||
),
|
||||
sharedToGroups: await Promise.all(
|
||||
groupPermissions.map(async (noteGroupPermission) => ({
|
||||
groupName: (await noteGroupPermission.group).name,
|
||||
canEdit: noteGroupPermission.canEdit,
|
||||
})),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue