mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 07:04:45 -04:00
fix(group): add special flag to create method
To make the create method more consistent with the guidelines, this commit adds the `special` flag to the parameters. As this function will only be used to create the two hard-coded groups and to handle API requests at one or two places, adding the parameter should not be too problematic. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
d0239f3a24
commit
178513a3a0
5 changed files with 18 additions and 12 deletions
|
@ -43,11 +43,15 @@ export class Group {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
private constructor() {}
|
private constructor() {}
|
||||||
|
|
||||||
public static create(name: string, displayName: string): Omit<Group, 'id'> {
|
public static create(
|
||||||
|
name: string,
|
||||||
|
displayName: string,
|
||||||
|
special: boolean,
|
||||||
|
): Omit<Group, 'id'> {
|
||||||
const newGroup = new Group();
|
const newGroup = new Group();
|
||||||
newGroup.name = name;
|
newGroup.name = name;
|
||||||
newGroup.displayName = displayName;
|
newGroup.displayName = displayName;
|
||||||
newGroup.special = false; // this attribute should only be true for the two special groups
|
newGroup.special = special; // this attribute should only be true for the two special groups
|
||||||
newGroup.members = [];
|
newGroup.members = [];
|
||||||
return newGroup;
|
return newGroup;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ describe('GroupsService', () => {
|
||||||
|
|
||||||
service = module.get<GroupsService>(GroupsService);
|
service = module.get<GroupsService>(GroupsService);
|
||||||
groupRepo = module.get<Repository<Group>>(getRepositoryToken(Group));
|
groupRepo = module.get<Repository<Group>>(getRepositoryToken(Group));
|
||||||
group = Group.create('testGroup', 'Superheros') as Group;
|
group = Group.create('testGroup', 'Superheros', false) as Group;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be defined', () => {
|
it('should be defined', () => {
|
||||||
|
|
|
@ -35,8 +35,7 @@ export class GroupsService {
|
||||||
displayName: string,
|
displayName: string,
|
||||||
special = false,
|
special = false,
|
||||||
): Promise<Group> {
|
): Promise<Group> {
|
||||||
const group = Group.create(name, displayName);
|
const group = Group.create(name, displayName, special);
|
||||||
group.special = special;
|
|
||||||
try {
|
try {
|
||||||
return await this.groupRepository.save(group);
|
return await this.groupRepository.save(group);
|
||||||
} catch {
|
} catch {
|
||||||
|
|
|
@ -365,6 +365,7 @@ describe('NotesService', () => {
|
||||||
const group = Group.create(
|
const group = Group.create(
|
||||||
groupPermissionUpate.groupname,
|
groupPermissionUpate.groupname,
|
||||||
groupPermissionUpate.groupname,
|
groupPermissionUpate.groupname,
|
||||||
|
false,
|
||||||
) as Group;
|
) as Group;
|
||||||
const note = Note.create(user) as Note;
|
const note = Note.create(user) as Note;
|
||||||
describe('works', () => {
|
describe('works', () => {
|
||||||
|
@ -668,7 +669,7 @@ describe('NotesService', () => {
|
||||||
describe('toNotePermissionsDto', () => {
|
describe('toNotePermissionsDto', () => {
|
||||||
it('works', async () => {
|
it('works', async () => {
|
||||||
const user = User.create('hardcoded', 'Testy') as User;
|
const user = User.create('hardcoded', 'Testy') as User;
|
||||||
const group = Group.create('testGroup', 'testGroup') as Group;
|
const group = Group.create('testGroup', 'testGroup', false) as Group;
|
||||||
const note = Note.create(user) as Note;
|
const note = Note.create(user) as Note;
|
||||||
note.userPermissions = [
|
note.userPermissions = [
|
||||||
{
|
{
|
||||||
|
@ -703,7 +704,7 @@ describe('NotesService', () => {
|
||||||
const user = User.create('hardcoded', 'Testy') as User;
|
const user = User.create('hardcoded', 'Testy') as User;
|
||||||
const author = Author.create(1);
|
const author = Author.create(1);
|
||||||
author.user = user;
|
author.user = user;
|
||||||
const group = Group.create('testGroup', 'testGroup') as Group;
|
const group = Group.create('testGroup', 'testGroup', false) as Group;
|
||||||
const content = 'testContent';
|
const content = 'testContent';
|
||||||
jest
|
jest
|
||||||
.spyOn(noteRepo, 'save')
|
.spyOn(noteRepo, 'save')
|
||||||
|
@ -800,7 +801,7 @@ describe('NotesService', () => {
|
||||||
author.user = user;
|
author.user = user;
|
||||||
const otherUser = User.create('other hardcoded', 'Testy2') as User;
|
const otherUser = User.create('other hardcoded', 'Testy2') as User;
|
||||||
otherUser.username = 'other hardcoded user';
|
otherUser.username = 'other hardcoded user';
|
||||||
const group = Group.create('testGroup', 'testGroup') as Group;
|
const group = Group.create('testGroup', 'testGroup', false) as Group;
|
||||||
const content = 'testContent';
|
const content = 'testContent';
|
||||||
jest
|
jest
|
||||||
.spyOn(noteRepo, 'save')
|
.spyOn(noteRepo, 'save')
|
||||||
|
|
|
@ -265,28 +265,29 @@ describe('PermissionsService', () => {
|
||||||
const everybody: Group = Group.create(
|
const everybody: Group = Group.create(
|
||||||
SpecialGroup.EVERYONE,
|
SpecialGroup.EVERYONE,
|
||||||
SpecialGroup.EVERYONE,
|
SpecialGroup.EVERYONE,
|
||||||
|
true,
|
||||||
) as Group;
|
) as Group;
|
||||||
everybody.special = true;
|
|
||||||
result[SpecialGroup.EVERYONE] = everybody;
|
result[SpecialGroup.EVERYONE] = everybody;
|
||||||
|
|
||||||
const loggedIn = Group.create(
|
const loggedIn = Group.create(
|
||||||
SpecialGroup.LOGGED_IN,
|
SpecialGroup.LOGGED_IN,
|
||||||
SpecialGroup.LOGGED_IN,
|
SpecialGroup.LOGGED_IN,
|
||||||
|
true,
|
||||||
) as Group;
|
) as Group;
|
||||||
loggedIn.special = true;
|
|
||||||
result[SpecialGroup.LOGGED_IN] = loggedIn;
|
result[SpecialGroup.LOGGED_IN] = loggedIn;
|
||||||
|
|
||||||
const user1group = Group.create('user1group', 'user1group') as Group;
|
const user1group = Group.create('user1group', 'user1group', false) as Group;
|
||||||
user1group.members = [user1];
|
user1group.members = [user1];
|
||||||
result['user1group'] = user1group;
|
result['user1group'] = user1group;
|
||||||
|
|
||||||
const user2group = Group.create('user2group', 'user2group') as Group;
|
const user2group = Group.create('user2group', 'user2group', false) as Group;
|
||||||
user2group.members = [user2];
|
user2group.members = [user2];
|
||||||
result['user2group'] = user2group;
|
result['user2group'] = user2group;
|
||||||
|
|
||||||
const user1and2group = Group.create(
|
const user1and2group = Group.create(
|
||||||
'user1and2group',
|
'user1and2group',
|
||||||
'user1and2group',
|
'user1and2group',
|
||||||
|
false,
|
||||||
) as Group;
|
) as Group;
|
||||||
user1and2group.members = [user1, user2];
|
user1and2group.members = [user1, user2];
|
||||||
result['user1and2group'] = user1and2group;
|
result['user1and2group'] = user1and2group;
|
||||||
|
@ -294,6 +295,7 @@ describe('PermissionsService', () => {
|
||||||
const user2and1group = Group.create(
|
const user2and1group = Group.create(
|
||||||
'user2and1group',
|
'user2and1group',
|
||||||
'user2and1group',
|
'user2and1group',
|
||||||
|
false,
|
||||||
) as Group;
|
) as Group;
|
||||||
user2and1group.members = [user2, user1];
|
user2and1group.members = [user2, user1];
|
||||||
result['user2and1group'] = user2and1group;
|
result['user2and1group'] = user2and1group;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue