Skip to content

Commit

Permalink
#231 fix workspace membership errors and settings experience/messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleBlanchette committed Nov 30, 2024
1 parent 4aa5513 commit f00c7cd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
14 changes: 12 additions & 2 deletions src/components/AdminSettingsScreen.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useContext, useEffect, useState } from '@wordpress/element';
import MissingPermissionsBadge from './users/MissingPermissionsBadge';

export default function AdminSettingsScreen() {
const { loadSettings, status, settings, notices, removeNotice, hasConnectedAsana } = useContext(SettingsContext);
const { loadSettings, status, settings, notices, removeNotice, hasConnectedAsana, isWorkspaceMember, userCan } = useContext(SettingsContext);
const [currentScreen, setCurrentScreen] = useState(() => {
const params = new URLSearchParams(window.location.search);
return params.get('tab') || 'account';
Expand Down Expand Up @@ -40,7 +40,17 @@ export default function AdminSettingsScreen() {
case 'workspace':
return (
hasConnectedAsana() ?
<WorkspaceSettings /> :
(
( isWorkspaceMember() || userCan('manage_options') ) ?
<WorkspaceSettings /> :
<Card style={{ textAlign: 'center', padding: '64px' }}>
<CardBody>
<MissingPermissionsBadge label='Missing permissions' />
<h2 style={{ margin: '1em', fontSize: '20px' }}>You are not a member of this site's Asana workspace</h2>
<p style={{ margin: '0 auto 2em', maxWidth: '40em' }}>To view workspace details, you must be a member of the designated Asana workspace or have administrative capabilities to manage options.</p>
</CardBody>
</Card>
) :
<Card style={{ textAlign: 'center', padding: '64px' }}>
<CardBody>
<MissingPermissionsBadge label='Requires Asana account' />
Expand Down
5 changes: 5 additions & 0 deletions src/components/settings/SettingsContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export function SettingsContextProvider({children}) {
// Current user.
//

function isWorkspaceMember() {
return ( true === settings?.user?.is_site_workspace_member );
}

function isFrontendAuthUser() {
return ( settings?.frontend?.auth_user_id === settings?.user?.id );
}
Expand Down Expand Up @@ -156,6 +160,7 @@ export function SettingsContextProvider({children}) {
notices,
loadSettings,
updateSettings,
isWorkspaceMember,
isFrontendAuthUser,
userCan,
hasConnectedAsana,
Expand Down
14 changes: 11 additions & 3 deletions src/includes/class-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -910,9 +910,17 @@ public static function get_settings_for_user( $user_id ) {
$asana = Asana_Interface::get_client( $user_id );

// Get Asana user data.
$asana_profile = Asana_Interface::get_me();
$found_workspace_users = Asana_Interface::find_workspace_users();
$connected_workspace_users = Asana_Interface::get_connected_workspace_users();
$asana_profile = Asana_Interface::get_me();

try {
$found_workspace_users = Asana_Interface::find_workspace_users();
$connected_workspace_users = Asana_Interface::get_connected_workspace_users();
} catch ( \Exception $err ) {
// Probably not a member of the saved workspace,
// so user is not allowed to see users within it.
$found_workspace_users = null;
$connected_workspace_users = null;
}

// Get workspace information.
foreach ( $asana_profile->workspaces as $workspace ) {
Expand Down

0 comments on commit f00c7cd

Please sign in to comment.