From 0d714f07ecda00a54392f47fe0054e37e269a7d3 Mon Sep 17 00:00:00 2001 From: Ilja Date: Sat, 6 Aug 2022 11:43:06 +0200 Subject: [PATCH 1/5] Add priviliges We can now check what priviliges someone has besides only the role. On older back-ends, privileges aren't provided, so we have a fall-back to list the privileges corresponding to what mods/admins are allowed on older BE's. --- .../entity_normalizer.service.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index 7f831ed9..1be19cf1 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -119,6 +119,33 @@ export const parseUser = (data) => { } else { output.role = 'member' } + + if (data.pleroma.privileges) { + output.privileges = data.pleroma.privileges + } else if (data.pleroma.is_admin) { + output.privileges = [ + 'users_read', + 'users_manage_invites', + 'users_manage_activation_state', + 'users_manage_tags', + 'users_manage_credentials', + 'users_delete', + 'messages_read', + 'messages_delete', + 'instances_delete', + 'reports_manage_reports', + 'moderation_log_read', + 'announcements_manage_announcements', + 'emoji_manage_emoji', + 'statistics_read' + ] + } else if (data.pleroma.is_moderator) { + output.privileges = [ + 'messages_delete' + ] + } else { + output.privileges = [] + } } if (data.source) { From 6c9768b8e2ffb0d1a992689f309020ff3da199d7 Mon Sep 17 00:00:00 2001 From: Ilja Date: Sat, 6 Aug 2022 14:00:29 +0200 Subject: [PATCH 2/5] Option to delete a post is shown when privileged with messages_delete --- src/components/extra_buttons/extra_buttons.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/extra_buttons/extra_buttons.js b/src/components/extra_buttons/extra_buttons.js index 22ffb65a..345402b7 100644 --- a/src/components/extra_buttons/extra_buttons.js +++ b/src/components/extra_buttons/extra_buttons.js @@ -77,8 +77,7 @@ const ExtraButtons = { currentUser () { return this.$store.state.users.currentUser }, canDelete () { if (!this.currentUser) { return } - const superuser = this.currentUser.rights.moderator || this.currentUser.rights.admin - return superuser || this.status.user.id === this.currentUser.id + return this.currentUser.privileges.includes('messages_delete') || this.status.user.id === this.currentUser.id }, ownStatus () { return this.status.user.id === this.currentUser.id From 56d1232588cac825b960782868e2ea3148371f33 Mon Sep 17 00:00:00 2001 From: Ilja Date: Sat, 6 Aug 2022 22:33:38 +0200 Subject: [PATCH 3/5] Show moderation drop down menu and items based on privileges There's a seperator between certain blocks of items. I show/hide the seperator together with the block under it. When a block with a seperator is at the top, the seperator doesn't show, keeping a consistent look with seperators only between blocks. I also hide granting roles for deactivated accounts because that doesn't make much sense to me. For the rest the items are hidden when you're not privileged. When there's no privileges that show items, the menu isn't shown either. --- .../moderation_tools/moderation_tools.js | 16 ++++++++++++++-- .../moderation_tools/moderation_tools.vue | 9 ++++++--- src/components/user_card/user_card.js | 4 ++++ src/components/user_card/user_card.vue | 2 +- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/components/moderation_tools/moderation_tools.js b/src/components/moderation_tools/moderation_tools.js index 2469327a..a5ce8656 100644 --- a/src/components/moderation_tools/moderation_tools.js +++ b/src/components/moderation_tools/moderation_tools.js @@ -41,14 +41,26 @@ const ModerationTools = { tagsSet () { return new Set(this.user.tags) }, - hasTagPolicy () { - return this.$store.state.instance.tagPolicyAvailable + canGrantRole () { + return this.user.is_local && !this.user.deactivated && this.$store.state.users.currentUser.role === 'admin' + }, + canChangeActivationState () { + return this.privileged('users_manage_activation_state') + }, + canDeleteAccount () { + return this.privileged('users_delete') + }, + canUseTagPolicy () { + return this.$store.state.instance.tagPolicyAvailable && this.privileged('users_manage_tags') } }, methods: { hasTag (tagName) { return this.tagsSet.has(tagName) }, + privileged (privilege) { + return this.$store.state.users.currentUser.privileges.includes(privilege) + }, toggleTag (tag) { const store = this.$store if (this.tagsSet.has(tag)) { diff --git a/src/components/moderation_tools/moderation_tools.vue b/src/components/moderation_tools/moderation_tools.vue index 34fe2e7c..8535ef27 100644 --- a/src/components/moderation_tools/moderation_tools.vue +++ b/src/components/moderation_tools/moderation_tools.vue @@ -10,7 +10,7 @@ >