[Front-end] Allow group events to be edited by group moderators

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-07-26 17:15:40 +02:00
parent 961f08e27f
commit a3181fd68b
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773

View File

@ -128,7 +128,7 @@
<p>
<router-link
class="participations-link"
v-if="actorIsOrganizer && event.draft === false"
v-if="canManageEvent && event.draft === false"
:to="{
name: RouteName.PARTICIPATIONS,
params: { eventId: event.uuid },
@ -214,7 +214,7 @@
<b-dropdown-item
aria-role="listitem"
has-link
v-if="actorIsOrganizer || event.draft"
v-if="canManageEvent || event.draft"
>
<router-link
:to="{
@ -229,7 +229,7 @@
<b-dropdown-item
aria-role="listitem"
has-link
v-if="actorIsOrganizer || event.draft"
v-if="canManageEvent || event.draft"
>
<router-link
:to="{
@ -243,7 +243,7 @@
</b-dropdown-item>
<b-dropdown-item
aria-role="listitem"
v-if="actorIsOrganizer || event.draft"
v-if="canManageEvent || event.draft"
@click="openDeleteEventModalWrapper"
>
{{ $t("Delete") }}
@ -253,7 +253,7 @@
<hr
class="dropdown-divider"
aria-role="menuitem"
v-if="actorIsOrganizer || event.draft"
v-if="canManageEvent || event.draft"
/>
<b-dropdown-item
aria-role="listitem"
@ -623,6 +623,7 @@ import {
EventJoinOptions,
EventStatus,
EventVisibility,
MemberRole,
ParticipantRole,
RoutingTransportationType,
RoutingType,
@ -633,7 +634,10 @@ import {
FETCH_EVENT,
JOIN_EVENT,
} from "../../graphql/event";
import { CURRENT_ACTOR_CLIENT } from "../../graphql/actor";
import {
CURRENT_ACTOR_CLIENT,
PERSON_MEMBERSHIP_GROUP,
} from "../../graphql/actor";
import { EventModel, IEvent } from "../../types/event.model";
import { IActor, IPerson, Person, usernameWithDomain } from "../../types/actor";
import { GRAPHQL_API_ENDPOINT } from "../../api/_entrypoint";
@ -738,6 +742,22 @@ import { ApolloCache, FetchResult } from "@apollo/client/core";
);
},
},
person: {
query: PERSON_MEMBERSHIP_GROUP,
fetchPolicy: "cache-and-network",
variables() {
return {
id: this.currentActor.id,
group: usernameWithDomain(this.event?.attributedTo),
};
},
skip() {
return (
!this.event?.attributedTo ||
!this.event?.attributedTo?.preferredUsername
);
},
},
config: CONFIG,
},
metaInfo() {
@ -764,6 +784,8 @@ export default class Event extends EventMixin {
config!: IConfig;
person!: IPerson;
participations: IParticipant[] = [];
oldParticipationRole!: string;
@ -1211,6 +1233,19 @@ export default class Event extends EventMixin {
);
}
get hasGroupPrivileges(): boolean {
return (
this.person?.memberships?.total > 0 &&
[MemberRole.MODERATOR, MemberRole.ADMINISTRATOR].includes(
this.person?.memberships?.elements[0].role
)
);
}
get canManageEvent(): boolean {
return this.actorIsOrganizer || this.hasGroupPrivileges;
}
get endDate(): Date {
return this.event.endsOn !== null && this.event.endsOn > this.event.beginsOn
? this.event.endsOn