Skip to content

Commit

Permalink
Merge pull request #11774 from Expensify/amechler-make-me-admin-trans…
Browse files Browse the repository at this point in the history
…ition
  • Loading branch information
Alexander Mechler authored Oct 12, 2022
2 parents 97904f4 + f9b0e4a commit 3a6fe30
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/libs/actions/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,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();

Expand All @@ -786,6 +789,8 @@ function createWorkspace() {
announceChatReportID,
adminsChatReportID,
expenseChatReportID,
ownerEmail,
makeMeAdmin,
policyName: workspaceName,
type: CONST.POLICY.TYPE.FREE,
},
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 @@ -267,7 +267,7 @@ class WorkspaceMembersPage extends React.Component {
}}
/>
</View>
{this.props.session.email === item.login && (
{(this.props.session.email === item.login || item.role === 'admin') && (
<View style={styles.peopleRowCell}>
<View style={[styles.badge, styles.peopleBadge]}>
<Text style={[styles.peopleBadgeText]}>
Expand Down

0 comments on commit 3a6fe30

Please sign in to comment.