From d3629d191f1cb1b47b872caed1ea303240ec26bd Mon Sep 17 00:00:00 2001 From: Emelia Smith Date: Mon, 26 Aug 2024 18:42:46 +0200 Subject: [PATCH] [Glitch] Add quick links to Administration and Moderation Reports from Web UI Port d820c0883d5557f011b4de8fafa1ff9f68b0d5de to glitch-soc Signed-off-by: Claire --- .../glitch/features/getting_started/index.jsx | 13 +++++++++---- .../ui/components/navigation_panel.jsx | 13 ++++++++++--- app/javascript/flavours/glitch/permissions.ts | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/app/javascript/flavours/glitch/features/getting_started/index.jsx b/app/javascript/flavours/glitch/features/getting_started/index.jsx index 2d13d3d584..af6dc313ad 100644 --- a/app/javascript/flavours/glitch/features/getting_started/index.jsx +++ b/app/javascript/flavours/glitch/features/getting_started/index.jsx @@ -12,11 +12,12 @@ import { connect } from 'react-redux'; import BookmarksIcon from '@/material-icons/400-24px/bookmarks-fill.svg?react'; import ExploreIcon from '@/material-icons/400-24px/explore.svg?react'; +import ModerationIcon from '@/material-icons/400-24px/gavel.svg?react'; import PeopleIcon from '@/material-icons/400-24px/group.svg?react'; import HomeIcon from '@/material-icons/400-24px/home-fill.svg?react'; import ListAltIcon from '@/material-icons/400-24px/list_alt.svg?react'; import MailIcon from '@/material-icons/400-24px/mail.svg?react'; -import ManufacturingIcon from '@/material-icons/400-24px/manufacturing.svg?react'; +import AdministrationIcon from '@/material-icons/400-24px/manufacturing.svg?react'; import MenuIcon from '@/material-icons/400-24px/menu.svg?react'; import MoreHorizIcon from '@/material-icons/400-24px/more_horiz.svg?react'; import NotificationsIcon from '@/material-icons/400-24px/notifications.svg?react'; @@ -29,9 +30,9 @@ import { openModal } from 'flavours/glitch/actions/modal'; import Column from 'flavours/glitch/features/ui/components/column'; import LinkFooter from 'flavours/glitch/features/ui/components/link_footer'; import { identityContextPropShape, withIdentity } from 'flavours/glitch/identity_context'; +import { canManageReports, canViewAdminDashboard } from 'flavours/glitch/permissions'; import { preferencesLink } from 'flavours/glitch/utils/backend_links'; - import { me, showTrends } from '../../initial_state'; import { NavigationBar } from '../compose/components/navigation_bar'; import ColumnLink from '../ui/components/column_link'; @@ -51,6 +52,8 @@ const messages = defineMessages({ direct: { id: 'navigation_bar.direct', defaultMessage: 'Private mentions' }, bookmarks: { id: 'navigation_bar.bookmarks', defaultMessage: 'Bookmarks' }, preferences: { id: 'navigation_bar.preferences', defaultMessage: 'Preferences' }, + administration: { id: 'navigation_bar.administration', defaultMessage: 'Administration' }, + moderation: { id: 'navigation_bar.moderation', defaultMessage: 'Moderation' }, settings: { id: 'navigation_bar.app_settings', defaultMessage: 'App settings' }, follow_requests: { id: 'navigation_bar.follow_requests', defaultMessage: 'Follow requests' }, lists: { id: 'navigation_bar.lists', defaultMessage: 'Lists' }, @@ -131,7 +134,7 @@ class GettingStarted extends ImmutablePureComponent { render () { const { intl, myAccount, columns, multiColumn, unreadFollowRequests, unreadNotifications, lists, openSettings } = this.props; - const { signedIn } = this.props.identity; + const { signedIn, permissions } = this.props.identity; const navItems = []; let listItems = []; @@ -196,7 +199,9 @@ class GettingStarted extends ImmutablePureComponent { {listItems} { preferencesLink !== undefined && } - + + {canManageReports(permissions) && } + {canViewAdminDashboard(permissions) && } )} diff --git a/app/javascript/flavours/glitch/features/ui/components/navigation_panel.jsx b/app/javascript/flavours/glitch/features/ui/components/navigation_panel.jsx index 6153b3ceaa..33c2db8278 100644 --- a/app/javascript/flavours/glitch/features/ui/components/navigation_panel.jsx +++ b/app/javascript/flavours/glitch/features/ui/components/navigation_panel.jsx @@ -10,13 +10,14 @@ import BookmarksActiveIcon from '@/material-icons/400-24px/bookmarks-fill.svg?re import BookmarksIcon from '@/material-icons/400-24px/bookmarks.svg?react'; import ExploreActiveIcon from '@/material-icons/400-24px/explore-fill.svg?react'; import ExploreIcon from '@/material-icons/400-24px/explore.svg?react'; +import ModerationIcon from '@/material-icons/400-24px/gavel.svg?react'; import HomeActiveIcon from '@/material-icons/400-24px/home-fill.svg?react'; import HomeIcon from '@/material-icons/400-24px/home.svg?react'; import ListAltActiveIcon from '@/material-icons/400-24px/list_alt-fill.svg?react'; import ListAltIcon from '@/material-icons/400-24px/list_alt.svg?react'; import MailActiveIcon from '@/material-icons/400-24px/mail-fill.svg?react'; import MailIcon from '@/material-icons/400-24px/mail.svg?react'; -import ManufacturingIcon from '@/material-icons/400-24px/manufacturing.svg?react'; +import AdministrationIcon from '@/material-icons/400-24px/manufacturing.svg?react'; import MoreHorizIcon from '@/material-icons/400-24px/more_horiz.svg?react'; import NotificationsActiveIcon from '@/material-icons/400-24px/notifications-fill.svg?react'; import NotificationsIcon from '@/material-icons/400-24px/notifications.svg?react'; @@ -33,6 +34,7 @@ import { NavigationPortal } from 'flavours/glitch/components/navigation_portal'; import { identityContextPropShape, withIdentity } from 'flavours/glitch/identity_context'; import { timelinePreview, trendsEnabled } from 'flavours/glitch/initial_state'; import { transientSingleColumn } from 'flavours/glitch/is_mobile'; +import { canManageReports, canViewAdminDashboard } from 'flavours/glitch/permissions'; import { selectUnreadNotificationGroupsCount } from 'flavours/glitch/selectors/notifications'; import { preferencesLink } from 'flavours/glitch/utils/backend_links'; @@ -51,6 +53,8 @@ const messages = defineMessages({ bookmarks: { id: 'navigation_bar.bookmarks', defaultMessage: 'Bookmarks' }, lists: { id: 'navigation_bar.lists', defaultMessage: 'Lists' }, preferences: { id: 'navigation_bar.preferences', defaultMessage: 'Preferences' }, + administration: { id: 'navigation_bar.administration', defaultMessage: 'Administration' }, + moderation: { id: 'navigation_bar.moderation', defaultMessage: 'Moderation' }, followsAndFollowers: { id: 'navigation_bar.follows_and_followers', defaultMessage: 'Follows and followers' }, about: { id: 'navigation_bar.about', defaultMessage: 'About' }, search: { id: 'navigation_bar.search', defaultMessage: 'Search' }, @@ -116,7 +120,7 @@ class NavigationPanel extends Component { render () { const { intl, onOpenSettings } = this.props; - const { signedIn, disabledAccountId } = this.props.identity; + const { signedIn, disabledAccountId, permissions } = this.props.identity; let banner = undefined; @@ -174,7 +178,10 @@ class NavigationPanel extends Component {
{!!preferencesLink && } - + + + {canManageReports(permissions) && } + {canViewAdminDashboard(permissions) && } )} diff --git a/app/javascript/flavours/glitch/permissions.ts b/app/javascript/flavours/glitch/permissions.ts index b583535c00..8f015610ea 100644 --- a/app/javascript/flavours/glitch/permissions.ts +++ b/app/javascript/flavours/glitch/permissions.ts @@ -1,4 +1,23 @@ export const PERMISSION_INVITE_USERS = 0x0000000000010000; export const PERMISSION_MANAGE_USERS = 0x0000000000000400; export const PERMISSION_MANAGE_FEDERATION = 0x0000000000000020; + export const PERMISSION_MANAGE_REPORTS = 0x0000000000000010; +export const PERMISSION_VIEW_DASHBOARD = 0x0000000000000008; + +// These helpers don't quite align with the names/categories in UserRole, +// but are likely "good enough" for the use cases at present. +// +// See: https://docs.joinmastodon.org/entities/Role/#permission-flags + +export function canViewAdminDashboard(permissions: number) { + return ( + (permissions & PERMISSION_VIEW_DASHBOARD) === PERMISSION_VIEW_DASHBOARD + ); +} + +export function canManageReports(permissions: number) { + return ( + (permissions & PERMISSION_MANAGE_REPORTS) === PERMISSION_MANAGE_REPORTS + ); +}