From e060ae5e5b1374099570f1ff52b31a5b6b88e137 Mon Sep 17 00:00:00 2001 From: xaralis <filip.varecha@fragaria.cz> Date: Wed, 30 Dec 2020 18:16:13 +0100 Subject: [PATCH] feat: do not allow banned users to edit their posts --- src/actions/posts.js | 17 ++++++++++++++++- src/components/posts/Post.jsx | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/actions/posts.js b/src/actions/posts.js index 8bfbf4c..eab9e29 100644 --- a/src/actions/posts.js +++ b/src/actions/posts.js @@ -3,7 +3,7 @@ import property from "lodash/property"; import { createAsyncAction, errorResult, successResult } from "pullstate"; import { fetch } from "api"; -import { PostStore } from "stores"; +import { AuthStore, PostStore } from "stores"; import { createSeenWriter, filterPosts, @@ -176,6 +176,21 @@ export const edit = createAsyncAction( } catch (err) { return errorResult([], err.toString()); } + }, + { + shortCircuitHook: ({ args }) => { + const { user } = AuthStore.getRawState(); + + if (!user) { + return errorResult(); + } + + if (user && user.isBanned) { + return errorResult(); + } + + return false; + }, } ); diff --git a/src/components/posts/Post.jsx b/src/components/posts/Post.jsx index 3f178c7..73505a8 100644 --- a/src/components/posts/Post.jsx +++ b/src/components/posts/Post.jsx @@ -163,7 +163,8 @@ const Post = ({ type === "procedure-proposal" && ["announced", "pending"].includes(state); const showEditAction = - isChairman || (currentUser && currentUser.id === author.id); + isChairman || + (currentUser && currentUser.id === author.id && !currentUser.isBanned); const showBanAction = isChairman && !author.isBanned; const showUnbanAction = isChairman && author.isBanned; const showHideAction = isChairman && !archived; -- GitLab