From becbb0a73f48621062457f344c52e990512aa73f Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 26 Jan 2020 22:04:56 +0100 Subject: [PATCH 1/2] Add instant group admin update --- src/app/models/group.ts | 28 +++++++++++++++---------- src/app/services/group/group.service.ts | 22 +++++-------------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/app/models/group.ts b/src/app/models/group.ts index 908613e..6314ee5 100644 --- a/src/app/models/group.ts +++ b/src/app/models/group.ts @@ -2,6 +2,7 @@ import { User } from 'src/app/models/user'; import { Event } from 'src/app/models/event'; import { IGroup } from './interfaces/IGroup'; import { environment } from 'src/environments/environment'; +import { IUser } from './interfaces/IUser'; export class Group { id: number; @@ -32,17 +33,7 @@ export class Group { } } if (groupDataResponse.admins) { - for (const admin of groupDataResponse.admins) { - user = new User(); - this.admins.push(user.assignFromResponse(admin)); - } - for (const admin of this.admins) { - for (const member of this.members) { - if (member.userID === admin.userID) { - member.isGroupAdmin = true; - } - } - } + this.updateAdmins(groupDataResponse.admins); } if (groupDataResponse.events) { for (const event of groupDataResponse.events) { @@ -55,6 +46,21 @@ export class Group { return this; } + public updateAdmins(admins: IUser[]) { + // this.admins = []; + for (const admin of admins) { + const user = new User(); + this.admins.push(user.assignFromResponse(admin)); + } + for (const admin of this.admins) { + for (const member of this.members) { + if (member.userID === admin.userID) { + member.isGroupAdmin = true; + } + } + } + } + buildPictureUrl(path: string): string { if (path) { return environment.greenvironmentUrl + path; diff --git a/src/app/services/group/group.service.ts b/src/app/services/group/group.service.ts index 3f1c935..eba4b1f 100644 --- a/src/app/services/group/group.service.ts +++ b/src/app/services/group/group.service.ts @@ -87,22 +87,17 @@ export class GroupService extends BaseService { const body = { query: `mutation($groupId: ID!, $userId: ID!) { addGroupAdmin(groupId: $groupId, userId: $userId) { - admins{id name handle profilePicture} + admins{id name handle} } }`, variables: { userId, groupId } }; - return this.postGraphql(body, null, 0) .pipe(tap(response => { - const admins: User[] = []; - for (const admin of response.data.addGroupAdmin) { - admins.push(admin.assignFromResponse(admin)); - } const group = this.group.getValue(); - group.admins = admins; + group.updateAdmins(response.data.addGroupAdmin); this.group.next(group); })); } @@ -111,22 +106,17 @@ export class GroupService extends BaseService { const body = { query: `mutation($groupId: ID!, $userId: ID!) { removeGroupAdmin(groupId: $groupId, userId: $userId) { - admins{id name handle profilePicture} + admins{id name handle} } }`, variables: { userId, groupId } }; - return this.postGraphql(body, null, 0) .pipe(tap(response => { - const admins: User[] = []; - for (const admin of response.data.addGroupAdmin) { - admins.push(admin.assignFromResponse(admin)); - } const group = this.group.getValue(); - group.admins = admins; + group.updateAdmins(response.data.removeGroupAdmin); this.group.next(group); })); } @@ -162,9 +152,7 @@ export class GroupService extends BaseService { public deleteEvent(eventId: string) { const body = { query: `mutation($eventId: ID!) { - deleteEvent(eventId: $eventId) { - joined - } + deleteEvent(eventId: $eventId) }`, variables: { eventId } From 787008ebfb1367fd7b9bc32d592b7cfcb6b866e4 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 26 Jan 2020 22:15:34 +0100 Subject: [PATCH 2/2] Fix only creator can remove/add admins --- src/app/components/group/group.component.html | 2 +- src/app/components/group/group.component.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app/components/group/group.component.html b/src/app/components/group/group.component.html index bb4c11a..132e5b1 100644 --- a/src/app/components/group/group.component.html +++ b/src/app/components/group/group.component.html @@ -136,7 +136,7 @@ {{user.handle}} [admin] -
+
diff --git a/src/app/components/group/group.component.ts b/src/app/components/group/group.component.ts index fa81f61..d9ef4d7 100644 --- a/src/app/components/group/group.component.ts +++ b/src/app/components/group/group.component.ts @@ -76,6 +76,7 @@ export class GroupComponent implements OnInit { self: User; id: string; isAdmin = false; + isCreator = false; groupNotFound = false; loading = false; @@ -120,6 +121,11 @@ export class GroupComponent implements OnInit { this.isAdmin = true; } } + if (this.groupProfile.creator.userID === this.self.userID) { + this.isCreator = true; + } else { + this.isCreator = false; + } for (const member of this.groupProfile.members) { member.allowedToSendRequest = this.requestService.isAllowedToSendRequest(member.userID, this.self); }