Fix accessing a discussion without being a member

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-03-31 10:06:13 +02:00
parent be20cb807c
commit 356f69cef2
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
2 changed files with 23 additions and 5 deletions

View File

@ -18,7 +18,7 @@
}" }"
>{{ discussion.actor.name }}</router-link >{{ discussion.actor.name }}</router-link
> >
<b-skeleton v-else animated /> <b-skeleton v-else-if="$apollo.loading" animated />
</li> </li>
<li> <li>
<router-link <router-link
@ -31,7 +31,7 @@
}" }"
>{{ $t("Discussions") }}</router-link >{{ $t("Discussions") }}</router-link
> >
<b-skeleton animated v-else /> <b-skeleton animated v-else-if="$apollo.loading" />
</li> </li>
<li class="is-active"> <li class="is-active">
<router-link <router-link
@ -41,6 +41,9 @@
</li> </li>
</ul> </ul>
</nav> </nav>
<b-message v-if="error" type="is-danger">
{{ error }}
</b-message>
<section> <section>
<div class="discussion-title"> <div class="discussion-title">
<h2 class="title" v-if="discussion.title && !editTitleMode"> <h2 class="title" v-if="discussion.title && !editTitleMode">
@ -60,8 +63,16 @@
<b-icon icon="pencil" /> <b-icon icon="pencil" />
</span> </span>
</h2> </h2>
<b-skeleton v-else-if="!editTitleMode" height="50px" animated /> <b-skeleton
<form v-else @submit.prevent="updateDiscussion" class="title-edit"> v-else-if="!editTitleMode && $apollo.loading"
height="50px"
animated
/>
<form
v-else-if="!$apollo.loading && !error"
@submit.prevent="updateDiscussion"
class="title-edit"
>
<b-input :value="discussion.title" v-model="newTitle" /> <b-input :value="discussion.title" v-model="newTitle" />
<div class="buttons"> <div class="buttons">
<b-button <b-button
@ -100,7 +111,7 @@
@click="loadMoreComments" @click="loadMoreComments"
>{{ $t("Fetch more") }}</b-button >{{ $t("Fetch more") }}</b-button
> >
<form @submit.prevent="reply"> <form @submit.prevent="reply" v-if="!error">
<b-field :label="$t('Text')"> <b-field :label="$t('Text')">
<editor v-model="newComment" /> <editor v-model="newComment" />
</b-field> </b-field>
@ -217,6 +228,7 @@ export default class discussion extends mixins(GroupMixin) {
RouteName = RouteName; RouteName = RouteName;
usernameWithDomain = usernameWithDomain; usernameWithDomain = usernameWithDomain;
error: string | null = null;
async reply(): Promise<void> { async reply(): Promise<void> {
if (this.newComment === "") return; if (this.newComment === "") return;
@ -422,6 +434,11 @@ export default class discussion extends mixins(GroupMixin) {
if (errors[0].message.includes("No such discussion")) { if (errors[0].message.includes("No such discussion")) {
await this.$router.push({ name: RouteName.PAGE_NOT_FOUND }); await this.$router.push({ name: RouteName.PAGE_NOT_FOUND });
} }
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (errors[0].code === "unauthorized") {
this.error = errors[0].message;
}
} }
mounted(): void { mounted(): void {

View File

@ -60,6 +60,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Discussion do
{:ok, discussion} {:ok, discussion}
else else
nil -> {:error, dgettext("errors", "Discussion not found")} nil -> {:error, dgettext("errors", "Discussion not found")}
{:member, false} -> {:error, :unauthorized}
end end
end end