[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> <p>
<router-link <router-link
class="participations-link" class="participations-link"
v-if="actorIsOrganizer && event.draft === false" v-if="canManageEvent && event.draft === false"
:to="{ :to="{
name: RouteName.PARTICIPATIONS, name: RouteName.PARTICIPATIONS,
params: { eventId: event.uuid }, params: { eventId: event.uuid },
@ -214,7 +214,7 @@
<b-dropdown-item <b-dropdown-item
aria-role="listitem" aria-role="listitem"
has-link has-link
v-if="actorIsOrganizer || event.draft" v-if="canManageEvent || event.draft"
> >
<router-link <router-link
:to="{ :to="{
@ -229,7 +229,7 @@
<b-dropdown-item <b-dropdown-item
aria-role="listitem" aria-role="listitem"
has-link has-link
v-if="actorIsOrganizer || event.draft" v-if="canManageEvent || event.draft"
> >
<router-link <router-link
:to="{ :to="{
@ -243,7 +243,7 @@
</b-dropdown-item> </b-dropdown-item>
<b-dropdown-item <b-dropdown-item
aria-role="listitem" aria-role="listitem"
v-if="actorIsOrganizer || event.draft" v-if="canManageEvent || event.draft"
@click="openDeleteEventModalWrapper" @click="openDeleteEventModalWrapper"
> >
{{ $t("Delete") }} {{ $t("Delete") }}
@ -253,7 +253,7 @@
<hr <hr
class="dropdown-divider" class="dropdown-divider"
aria-role="menuitem" aria-role="menuitem"
v-if="actorIsOrganizer || event.draft" v-if="canManageEvent || event.draft"
/> />
<b-dropdown-item <b-dropdown-item
aria-role="listitem" aria-role="listitem"
@ -623,6 +623,7 @@ import {
EventJoinOptions, EventJoinOptions,
EventStatus, EventStatus,
EventVisibility, EventVisibility,
MemberRole,
ParticipantRole, ParticipantRole,
RoutingTransportationType, RoutingTransportationType,
RoutingType, RoutingType,
@ -633,7 +634,10 @@ import {
FETCH_EVENT, FETCH_EVENT,
JOIN_EVENT, JOIN_EVENT,
} from "../../graphql/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 { EventModel, IEvent } from "../../types/event.model";
import { IActor, IPerson, Person, usernameWithDomain } from "../../types/actor"; import { IActor, IPerson, Person, usernameWithDomain } from "../../types/actor";
import { GRAPHQL_API_ENDPOINT } from "../../api/_entrypoint"; 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, config: CONFIG,
}, },
metaInfo() { metaInfo() {
@ -764,6 +784,8 @@ export default class Event extends EventMixin {
config!: IConfig; config!: IConfig;
person!: IPerson;
participations: IParticipant[] = []; participations: IParticipant[] = [];
oldParticipationRole!: string; 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 { get endDate(): Date {
return this.event.endsOn !== null && this.event.endsOn > this.event.beginsOn return this.event.endsOn !== null && this.event.endsOn > this.event.beginsOn
? this.event.endsOn ? this.event.endsOn