2021-03-05 11:23:17 +01:00
|
|
|
import {
|
|
|
|
CURRENT_ACTOR_CLIENT,
|
|
|
|
GROUP_MEMBERSHIP_SUBSCRIPTION_CHANGED,
|
|
|
|
PERSON_MEMBERSHIP_GROUP,
|
|
|
|
} from "@/graphql/actor";
|
2020-10-09 15:26:37 +02:00
|
|
|
import { FETCH_GROUP } from "@/graphql/group";
|
2020-10-12 12:16:36 +02:00
|
|
|
import RouteName from "@/router/name";
|
2021-03-29 18:23:03 +02:00
|
|
|
import {
|
|
|
|
Group,
|
|
|
|
IActor,
|
|
|
|
IGroup,
|
|
|
|
IPerson,
|
|
|
|
usernameWithDomain,
|
|
|
|
} from "@/types/actor";
|
2020-11-27 19:27:44 +01:00
|
|
|
import { MemberRole } from "@/types/enums";
|
2020-10-09 15:26:37 +02:00
|
|
|
import { Component, Vue } from "vue-property-decorator";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
apollo: {
|
|
|
|
group: {
|
|
|
|
query: FETCH_GROUP,
|
|
|
|
fetchPolicy: "cache-and-network",
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
name: this.$route.params.preferredUsername,
|
2020-12-09 09:56:53 +01:00
|
|
|
beforeDateTime: null,
|
|
|
|
afterDateTime: new Date(),
|
2020-10-09 15:26:37 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
skip() {
|
|
|
|
return !this.$route.params.preferredUsername;
|
|
|
|
},
|
2020-10-12 12:16:36 +02:00
|
|
|
error({ graphQLErrors }) {
|
|
|
|
this.handleErrors(graphQLErrors);
|
|
|
|
},
|
2020-10-09 15:26:37 +02:00
|
|
|
},
|
|
|
|
person: {
|
2021-03-05 11:23:17 +01:00
|
|
|
query: PERSON_MEMBERSHIP_GROUP,
|
2020-10-09 15:26:37 +02:00
|
|
|
fetchPolicy: "cache-and-network",
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
id: this.currentActor.id,
|
2021-03-29 18:23:03 +02:00
|
|
|
group: usernameWithDomain(this.group),
|
2020-10-09 15:26:37 +02:00
|
|
|
};
|
|
|
|
},
|
2020-11-06 11:34:32 +01:00
|
|
|
subscribeToMore: {
|
|
|
|
document: GROUP_MEMBERSHIP_SUBSCRIPTION_CHANGED,
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
actorId: this.currentActor.id,
|
2021-03-23 16:17:08 +01:00
|
|
|
group: this.group.preferredUsername,
|
2020-11-06 11:34:32 +01:00
|
|
|
};
|
|
|
|
},
|
|
|
|
skip() {
|
2021-03-05 11:23:17 +01:00
|
|
|
return (
|
|
|
|
!this.currentActor ||
|
|
|
|
!this.currentActor.id ||
|
2021-03-23 16:17:08 +01:00
|
|
|
!this.group.preferredUsername
|
2021-03-05 11:23:17 +01:00
|
|
|
);
|
2020-11-06 11:34:32 +01:00
|
|
|
},
|
|
|
|
},
|
2020-10-09 15:26:37 +02:00
|
|
|
skip() {
|
2021-03-05 11:23:17 +01:00
|
|
|
return (
|
|
|
|
!this.currentActor ||
|
|
|
|
!this.currentActor.id ||
|
2021-03-23 16:17:08 +01:00
|
|
|
!this.group.preferredUsername
|
2021-03-05 11:23:17 +01:00
|
|
|
);
|
2020-10-09 15:26:37 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
currentActor: CURRENT_ACTOR_CLIENT,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
export default class GroupMixin extends Vue {
|
|
|
|
group: IGroup = new Group();
|
2020-10-15 14:23:55 +02:00
|
|
|
|
2020-10-09 15:26:37 +02:00
|
|
|
currentActor!: IActor;
|
|
|
|
|
|
|
|
person!: IPerson;
|
|
|
|
|
|
|
|
get isCurrentActorAGroupAdmin(): boolean {
|
2020-10-22 09:37:30 +02:00
|
|
|
return this.hasCurrentActorThisRole(MemberRole.ADMINISTRATOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
get isCurrentActorAGroupModerator(): boolean {
|
2020-11-30 10:24:11 +01:00
|
|
|
return this.hasCurrentActorThisRole([
|
|
|
|
MemberRole.MODERATOR,
|
|
|
|
MemberRole.ADMINISTRATOR,
|
|
|
|
]);
|
2020-10-22 09:37:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hasCurrentActorThisRole(givenRole: string | string[]): boolean {
|
|
|
|
const roles = Array.isArray(givenRole) ? givenRole : [givenRole];
|
2021-03-16 17:36:30 +01:00
|
|
|
return (
|
|
|
|
this.person?.memberships?.total > 0 &&
|
|
|
|
roles.includes(this.person?.memberships?.elements[0].role)
|
|
|
|
);
|
2020-10-09 15:26:37 +02:00
|
|
|
}
|
2020-10-12 12:16:36 +02:00
|
|
|
|
2020-10-15 14:23:55 +02:00
|
|
|
handleErrors(errors: any[]): void {
|
2020-10-12 12:16:36 +02:00
|
|
|
if (
|
|
|
|
errors.some((error) => error.status_code === 404) ||
|
|
|
|
errors.some(({ message }) => message.includes("has invalid value $uuid"))
|
|
|
|
) {
|
|
|
|
this.$router.replace({ name: RouteName.PAGE_NOT_FOUND });
|
|
|
|
}
|
|
|
|
}
|
2020-10-09 15:26:37 +02:00
|
|
|
}
|