From 2d0da587933331874aede2504497d9b2a35f1645 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 23 May 2022 15:22:15 -0400 Subject: [PATCH] Add posting restricted to mods (#642) * Adding only mods can post. Fixes #641 * Fixing canPost check --- package.json | 2 +- .../components/community/community-form.tsx | 30 +++++++++++++++++-- .../components/community/create-community.tsx | 3 +- src/shared/components/community/sidebar.tsx | 20 ++++++++----- src/shared/components/post/post-form.tsx | 3 +- yarn.lock | 8 ++--- 6 files changed, 49 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index d928bf9..6b0090c 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "eslint-plugin-prettier": "^4.0.0", "husky": "^7.0.4", "import-sort-style-module": "^6.0.0", - "lemmy-js-client": "0.17.0-rc.5", + "lemmy-js-client": "0.16.4-rc.2", "lint-staged": "^12.4.1", "mini-css-extract-plugin": "^2.6.0", "node-fetch": "^2.6.1", diff --git a/src/shared/components/community/community-form.tsx b/src/shared/components/community/community-form.tsx index 9de05bf..0f12a25 100644 --- a/src/shared/components/community/community-form.tsx +++ b/src/shared/components/community/community-form.tsx @@ -14,7 +14,6 @@ import { authField, capitalizeFirstLetter, randomStr, - toast, wsClient, wsJsonToRes, wsSubscribe, @@ -51,6 +50,7 @@ export class CommunityForm extends Component< nsfw: false, icon: null, banner: null, + posting_restricted_to_mods: false, auth: authField(false), }, loading: false, @@ -79,6 +79,7 @@ export class CommunityForm extends Component< nsfw: cv.community.nsfw, icon: cv.community.icon, banner: cv.community.banner, + posting_restricted_to_mods: cv.community.posting_restricted_to_mods, auth: authField(), }; } @@ -227,6 +228,25 @@ export class CommunityForm extends Component< )} +
+ + {i18n.t("only_mods_can_post_in_community")} + +
+
+ +
+
+
@@ -250,16 +250,14 @@ export class Sidebar extends Component { } createPost() { - let community_view = this.props.community_view; + let cv = this.props.community_view; return ( - community_view.subscribed && ( + cv.subscribed && ( {i18n.t("create_a_post")} @@ -536,6 +534,14 @@ export class Sidebar extends Component { ); } + get canPost(): boolean { + return ( + !this.props.community_view.community.posting_restricted_to_mods || + this.canMod || + this.canAdmin + ); + } + handleModRemoveShow(i: Sidebar) { i.state.showRemoveDialog = true; i.setState(i.state); diff --git a/src/shared/components/post/post-form.tsx b/src/shared/components/post/post-form.tsx index e9c2218..de0b765 100644 --- a/src/shared/components/post/post-form.tsx +++ b/src/shared/components/post/post-form.tsx @@ -636,7 +636,8 @@ export class PostForm extends Component { let op = wsUserOp(msg); console.log(msg); if (msg.error) { - toast(i18n.t(msg.error), "danger"); + // Errors handled by top level pages + // toast(i18n.t(msg.error), "danger"); this.state.loading = false; this.setState(this.state); return; diff --git a/yarn.lock b/yarn.lock index 19ddfcc..2e326f1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4813,10 +4813,10 @@ lcid@^1.0.0: dependencies: invert-kv "^1.0.0" -lemmy-js-client@0.17.0-rc.5: - version "0.17.0-rc.5" - resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.5.tgz#8065ddca68acfbccc7a693ae0f31d6ab66dce972" - integrity sha512-IuSYaK4//KVFg+s4Av/PaxMM2tQpP3sL6G3zXfzbrZfCEtBp9ZlOEMFAu/neRgNumVh+R/koIwf8iLh4UdYCdg== +lemmy-js-client@0.16.4-rc.2: + version "0.16.4-rc.2" + resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.16.4-rc.2.tgz#849b054ff37668c242db0202070bdb35f357f069" + integrity sha512-7ftHxpecqhHddfTJJC02eMB6N0jrtUBZVjt6CGC74J06kplBrsBQVETBqm33G1h1/SPHRHU1mqQ+f03PwsL+Ng== levn@^0.4.1: version "0.4.1" -- 2.44.1