Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow any admin to see workspace settings #23626

Merged
merged 6 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ Onyx.connect({
callback: (val) => (allPersonalDetails = val),
});

let loginList;
Onyx.connect({
key: ONYXKEYS.LOGIN_LIST,
callback: (val) => (loginList = val),
});

/**
* Stores in Onyx the policy ID of the last workspace that was accessed by the user
* @param {String|null} policyID
Expand Down Expand Up @@ -161,16 +155,6 @@ function isAdminOfFreePolicy(policies) {
return _.some(policies, (policy) => policy && policy.type === CONST.POLICY.TYPE.FREE && policy.role === CONST.POLICY.ROLE.ADMIN);
}

/**
* Is the user the owner of the given policy?
*
* @param {Object} policy
* @returns {Boolean}
*/
function isPolicyOwner(policy) {
return _.keys(loginList).includes(policy.owner);
}

/**
* Check if the user has any active free policies (aka workspaces)
*
Expand Down Expand Up @@ -1201,6 +1185,5 @@ export {
openWorkspaceInvitePage,
removeWorkspace,
setWorkspaceInviteMembersDraft,
isPolicyOwner,
clearErrors,
};
4 changes: 2 additions & 2 deletions src/pages/ReimbursementAccount/ReimbursementAccountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import * as ReimbursementAccountProps from './reimbursementAccountPropTypes';
import reimbursementAccountDraftPropTypes from './ReimbursementAccountDraftPropTypes';
import withPolicy from '../workspace/withPolicy';
import FullPageNotFoundView from '../../components/BlockingViews/FullPageNotFoundView';
import * as Policy from '../../libs/actions/Policy';
import * as PolicyUtils from '../../libs/PolicyUtils';

const propTypes = {
/** Plaid SDK token to use to initialize the widget */
Expand Down Expand Up @@ -332,7 +332,7 @@ class ReimbursementAccountPage extends React.Component {
const policyName = lodashGet(this.props.policy, 'name');
const policyID = lodashGet(this.props.route.params, 'policyID');

if (_.isEmpty(this.props.policy) || !Policy.isPolicyOwner(this.props.policy)) {
if (_.isEmpty(this.props.policy) || !PolicyUtils.isPolicyAdmin(this.props.policy)) {
return (
<ScreenWrapper>
<FullPageNotFoundView
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceInitialPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function WorkspaceInitialPage(props) {
{({safeAreaPaddingBottomStyle}) => (
<FullPageNotFoundView
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)}
shouldShow={_.isEmpty(props.policy) || !Policy.isPolicyOwner(props.policy)}
shouldShow={_.isEmpty(props.policy) || !PolicyUtils.isPolicyAdmin(props.policy)}
subtitleKey={_.isEmpty(props.policy) ? undefined : 'workspace.common.notAuthorized'}
>
<HeaderWithBackButton
Expand Down
3 changes: 2 additions & 1 deletion src/pages/workspace/WorkspaceInviteMessagePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import styles from '../../styles/styles';
import compose from '../../libs/compose';
import ONYXKEYS from '../../ONYXKEYS';
import * as Policy from '../../libs/actions/Policy';
import * as PolicyUtils from '../../libs/PolicyUtils';
import TextInput from '../../components/TextInput';
import MultipleAvatars from '../../components/MultipleAvatars';
import CONST from '../../CONST';
Expand Down Expand Up @@ -163,7 +164,7 @@ class WorkspaceInviteMessagePage extends React.Component {
return (
<ScreenWrapper includeSafeAreaPaddingBottom={false}>
<FullPageNotFoundView
shouldShow={_.isEmpty(this.props.policy) || !Policy.isPolicyOwner(this.props.policy)}
shouldShow={_.isEmpty(this.props.policy) || !PolicyUtils.isPolicyAdmin(this.props.policy)}
subtitleKey={_.isEmpty(this.props.policy) ? undefined : 'workspace.common.notAuthorized'}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)}
>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceInvitePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ function WorkspaceInvitePage(props) {
const sections = didScreenTransitionEnd ? getSections() : [];
return (
<FullPageNotFoundView
shouldShow={_.isEmpty(props.policy) || !Policy.isPolicyOwner(props.policy)}
shouldShow={_.isEmpty(props.policy) || !PolicyUtils.isPolicyAdmin(props.policy)}
subtitleKey={_.isEmpty(props.policy) ? undefined : 'workspace.common.notAuthorized'}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)}
>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceMembersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ function WorkspaceMembersPage(props) {
>
{({safeAreaPaddingBottomStyle}) => (
<FullPageNotFoundView
shouldShow={_.isEmpty(props.policy) || !Policy.isPolicyOwner(props.policy)}
shouldShow={_.isEmpty(props.policy) || !PolicyUtils.isPolicyAdmin(props.policy)}
subtitleKey={_.isEmpty(props.policy) ? undefined : 'workspace.common.notAuthorized'}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)}
>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/WorkspacePageWithSections.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {withOnyx} from 'react-native-onyx';
import lodashGet from 'lodash/get';
import _ from 'underscore';
import styles from '../../styles/styles';
import * as PolicyUtils from '../../libs/PolicyUtils';
import Navigation from '../../libs/Navigation/Navigation';
import * as Policy from '../../libs/actions/Policy';
import compose from '../../libs/compose';
import ROUTES from '../../ROUTES';
import HeaderWithBackButton from '../../components/HeaderWithBackButton';
Expand Down Expand Up @@ -105,7 +105,7 @@ function WorkspacePageWithSections({backButtonRoute, children, footer, guidesCal
>
<FullPageNotFoundView
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)}
shouldShow={_.isEmpty(policy) || !Policy.isPolicyOwner(policy)}
shouldShow={_.isEmpty(policy) || !PolicyUtils.isPolicyAdmin(policy)}
subtitleKey={_.isEmpty(policy) ? undefined : 'workspace.common.notAuthorized'}
>
<HeaderWithBackButton
Expand Down