diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 265de152b3d5..faa7fe87f5d3 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -188,11 +188,16 @@ function setUpPoliciesAndNavigate(session) { const url = new URL(currentUrl); const exitTo = url.searchParams.get('exitTo'); + // Approved Accountants and Guides can enter a flow where they make a workspace for other users, + // and those are passed as a search parameter when using transition links + const ownerEmail = url.searchParams.get('ownerEmail'); + const makeMeAdmin = url.searchParams.get('makeMeAdmin'); + const shouldCreateFreePolicy = !isLoggingInAsNewUser && Str.startsWith(url.pathname, Str.normalizeUrl(ROUTES.TRANSITION_FROM_OLD_DOT)) && exitTo === ROUTES.WORKSPACE_NEW; if (shouldCreateFreePolicy) { - Policy.createWorkspace(); + Policy.createWorkspace(ownerEmail, makeMeAdmin); return; } if (!isLoggingInAsNewUser && exitTo) { diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 457f3e2cd4e1..dda3b4519fce 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -763,8 +763,11 @@ function generatePolicyID() { /** * Optimistically creates a new workspace and default workspace chats + * + * @param {String} [ownerEmail] Optional, the email of the account to make the owner of the policy + * @param {Boolean} [makeMeAdmin] Optional, leave the calling account as an admin on the policy */ -function createWorkspace() { +function createWorkspace(ownerEmail = '', makeMeAdmin = false) { const policyID = generatePolicyID(); const workspaceName = generateDefaultWorkspaceName(); @@ -785,6 +788,8 @@ function createWorkspace() { announceChatReportID, adminsChatReportID, expenseChatReportID, + ownerEmail, + makeMeAdmin, policyName: workspaceName, type: CONST.POLICY.TYPE.FREE, }, diff --git a/src/pages/workspace/WorkspaceMembersPage.js b/src/pages/workspace/WorkspaceMembersPage.js index 0b3f12570340..5e00fdce8cea 100644 --- a/src/pages/workspace/WorkspaceMembersPage.js +++ b/src/pages/workspace/WorkspaceMembersPage.js @@ -267,7 +267,7 @@ class WorkspaceMembersPage extends React.Component { }} /> - {this.props.session.email === item.login && ( + {(this.props.session.email === item.login || item.role === 'admin') && (