Skip to content

Commit fb95f8d

Browse files
feat: allow deletion of roles (#6343)
Co-authored-by: Areeb Jamal <jamal.areeb@gmail.com>
1 parent 677c74b commit fb95f8d

File tree

6 files changed

+91
-44
lines changed

6 files changed

+91
-44
lines changed

app/components/events/view/overview/manage-roles.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default class ManageRoles extends Component {
6666
}
6767

6868
@action
69-
deleteUserRole(invite) {
69+
deleteUserRoleInvite(invite) {
7070
this.set('isLoading', true);
7171
invite.destroyRecord()
7272
.then(() => {
@@ -86,6 +86,27 @@ export default class ManageRoles extends Component {
8686
});
8787
}
8888

89+
@action
90+
deleteUserRole(eventRole) {
91+
this.set('isLoading', true);
92+
eventRole.destroyRecord()
93+
.then(() => {
94+
this.notify.success(this.l10n.t('Role deleted successfully'), {
95+
id: 'del_role_succ'
96+
});
97+
this.data.usersEventsRoles.removeObject(eventRole);
98+
})
99+
.catch(e => {
100+
console.error('Error while deleting role', e);
101+
this.notify.error(this.l10n.t('Oops something went wrong. Please try again'), {
102+
id: 'err_man_role'
103+
});
104+
})
105+
.finally(() => {
106+
this.set('isLoading', false);
107+
});
108+
}
109+
89110
@action
90111
filter(type) {
91112
this.set('roleType', type);

app/models/event.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export default class Event extends ModelBase.extend(CustomPrimaryKeyMixin, {
132132
trackOrganizers : hasMany('user', { inverse: null }),
133133
registrars : hasMany('user', { inverse: null }),
134134
moderators : hasMany('user', { inverse: null }),
135+
roles : hasMany('users-events-role'),
135136

136137
/**
137138
* The discount code applied to this event [Form(1) discount code]

app/models/users-events-role.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import ModelBase from 'open-event-frontend/models/base';
2+
import { belongsTo } from 'ember-data/relationships';
3+
4+
export default ModelBase.extend({
5+
event : belongsTo('event'),
6+
role : belongsTo('role'),
7+
user : belongsTo('user')
8+
});

app/routes/events/view/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export default class extends Route.extend(EmberTableRouteMixin) {
1919
const roleInvitesPromise = eventDetails.query('roleInvites', {
2020
include: 'role'
2121
});
22+
const usersEventsRolesPromise = eventDetails.query('roles', {
23+
include: 'user,role'
24+
});
2225
const sessionTypesPromise = eventDetails.query('sessionTypes', {});
2326
const tracksPromise = eventDetails.query('tracks', {});
2427
const microlocationsPromise = eventDetails.query('microlocations', {});
@@ -29,8 +32,8 @@ export default class extends Route.extend(EmberTableRouteMixin) {
2932
const ticketsPromise = eventDetails.query('tickets', {});
3033

3134
const [sponsors, roleInvites, sessionTypes, tracks, microlocations, speakersCall, socialLinks,
32-
statistics, orderStat, tickets] = (await allSettled([sponsorsPromise, roleInvitesPromise, sessionTypesPromise, tracksPromise, microlocationsPromise, speakersCallPromise, socialLinksPromise,
33-
statisticsPromise, orderStatPromise, ticketsPromise])).map(result => result.value);
35+
statistics, orderStat, tickets, usersEventsRoles] = (await allSettled([sponsorsPromise, roleInvitesPromise, sessionTypesPromise, tracksPromise, microlocationsPromise, speakersCallPromise, socialLinksPromise,
36+
statisticsPromise, orderStatPromise, ticketsPromise, usersEventsRolesPromise])).map(result => result.value);
3437

3538

3639
return {
@@ -44,7 +47,8 @@ export default class extends Route.extend(EmberTableRouteMixin) {
4447
socialLinks,
4548
statistics,
4649
orderStat,
47-
tickets
50+
tickets,
51+
usersEventsRoles
4852
};
4953
}
5054
}

app/routes/events/view/team/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export default class EventsViewTeamIndex extends Route.extend({
1212
roleInvites: event.query('roleInvites', {
1313
include: 'role'
1414
}),
15+
usersEventsRoles: event.query('roles', {
16+
include: 'user,role'
17+
}),
1518
roles: this.store.findAll('role')
1619
});
1720
}

app/templates/components/events/view/overview/manage-roles.hbs

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,62 @@
1919
<tr>
2020
<th>{{t 'User (Email)'}}</th>
2121
<th>{{t 'Role'}}</th>
22-
{{#if (and @editable (eq this.roleType 'pending'))}}
22+
{{#if @editable}}
2323
<th>{{t 'Options'}}</th>
2424
{{/if}}
2525
</tr>
2626
</thead>
2727
<tbody>
28-
{{#each this.roleInvites as |roleInvite|}}
29-
<tr>
30-
<td>{{roleInvite.email}}</td>
31-
<td>{{t-var roleInvite.role.titleName}}</td>
32-
{{#if (and @editable (eq this.roleType 'pending'))}}
33-
<td>
34-
<div class="ui horizontal compact basic buttons">
35-
{{#if (eq this.roleType 'accepted')}}
36-
<UiPopup
37-
@content={{t "Delete"}}
38-
@class="ui icon button"
39-
@click={{action (confirm (t "Are you sure you would like to delete this role?") (action "deleteUserRole" roleInvite))}}>
40-
<i class="trash icon"></i>
41-
</UiPopup>
42-
{{else}}
43-
<UiPopup
44-
@content={{t "Delete"}}
45-
@class="ui icon button"
46-
@click={{action (confirm (t "Are you sure you would like to cancel this invite?") (action "deleteUserRole" roleInvite))}}>
47-
<i class="trash icon"></i>
48-
</UiPopup>
49-
{{/if}}
50-
{{#if (eq this.roleType 'pending')}}
51-
<UiPopup
52-
@content={{t "Resend invite"}}
53-
@click={{action "resendInvite" roleInvite}}
54-
@class="ui icon button"
55-
@position="top center">
56-
<i class="mail outline icon"></i>
57-
</UiPopup>
58-
{{/if}}
59-
</div>
60-
</td>
61-
{{/if}}
62-
</tr>
28+
{{#if (eq this.roleType 'pending')}}
29+
{{#each this.roleInvites as |roleInvite|}}
30+
<tr>
31+
<td>{{roleInvite.email}}</td>
32+
<td>{{t-var roleInvite.role.titleName}}</td>
33+
{{#if (and @editable (eq this.roleType 'pending'))}}
34+
<td>
35+
<div class="ui horizontal compact basic buttons">
36+
<UiPopup
37+
@content={{t "Delete"}}
38+
@class="ui icon button"
39+
@click={{action (confirm (t "Are you sure you would like to cancel this invite?") (action "deleteUserRole" roleInvite))}}>
40+
<i class="trash icon"></i>
41+
</UiPopup>
42+
<UiPopup
43+
@content={{t "Resend invite"}}
44+
@click={{action "resendInvite" roleInvite}}
45+
@class="ui icon button"
46+
@position="top center">
47+
<i class="mail outline icon"></i>
48+
</UiPopup>
49+
</div>
50+
</td>
51+
{{/if}}
52+
</tr>
53+
{{else}}
54+
<div class="ui basic segment">
55+
{{t 'No records to show'}}
56+
</div>
57+
{{/each}}
6358
{{else}}
64-
<div class="ui basic segment">
65-
{{t 'No records to show'}}
66-
</div>
67-
{{/each}}
59+
{{#each this.data.usersEventsRoles as |eventRole|}}
60+
<tr>
61+
<td>{{eventRole.user.email}}</td>
62+
<td>{{eventRole.role.titleName}}</td>
63+
{{#if (and @editable (not-eq eventRole.role.name 'owner'))}}
64+
<td>
65+
<div class="ui horizontal compact basic buttons">
66+
<UiPopup
67+
@content={{t "Delete"}}
68+
@class="ui icon button"
69+
@click={{action (confirm (t "Are you sure you would like to delete this role?") (action "deleteUserRole" eventRole))}}>
70+
<i class="trash icon"></i>
71+
</UiPopup>
72+
</div>
73+
</td>
74+
{{/if}}
75+
</tr>
76+
{{/each}}
77+
{{/if}}
6878
</tbody>
6979
</table>
7080
</div>

0 commit comments

Comments
 (0)