-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from vtex-apps/fix/B2BTEAM-1689-check-user-pe…
…rmission-error fix: check user permission error
- Loading branch information
Showing
5 changed files
with
103 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -313,22 +313,26 @@ const costCenters = { | |
throw new Error('This organization is not active') | ||
} | ||
|
||
const { | ||
data: { checkUserPermission }, | ||
}: any = await storefrontPermissions | ||
.checkUserPermission('[email protected]') | ||
.catch((error: any) => { | ||
logger.error({ | ||
error, | ||
message: 'checkUserPermission-error', | ||
let checkUserPermission = null | ||
|
||
if (sessionData?.namespaces) { | ||
const checkUserPermissionResult = await storefrontPermissions | ||
.checkUserPermission('[email protected]') | ||
.catch((error: any) => { | ||
logger.error({ | ||
error, | ||
message: 'checkUserPermission-error', | ||
}) | ||
|
||
return { | ||
data: { | ||
checkUserPermission: null, | ||
}, | ||
} | ||
}) | ||
|
||
return { | ||
data: { | ||
checkUserPermission: null, | ||
}, | ||
} | ||
}) | ||
checkUserPermission = checkUserPermissionResult?.data?.checkUserPermission | ||
} | ||
|
||
const isSalesAdmin = checkUserPermission?.role.slug.match(/sales-admin/) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,42 +189,47 @@ const Organizations = { | |
) => { | ||
const organizationFilters: string[] = [] | ||
let fromSession = false | ||
const { | ||
data: { checkUserPermission }, | ||
}: any = await storefrontPermissions | ||
.checkUserPermission('[email protected]') | ||
|
||
const sessionData = await session | ||
.getSession(sessionToken as string, ['*']) | ||
.then((currentSession: any) => { | ||
return currentSession.sessionData | ||
}) | ||
.catch((error: any) => { | ||
logger.error({ | ||
logger.warn({ | ||
error, | ||
message: 'checkUserPermission-error', | ||
message: 'getOrganizationsByEmail-session-error', | ||
}) | ||
|
||
return { | ||
data: { | ||
checkUserPermission: null, | ||
}, | ||
} | ||
return null | ||
}) | ||
|
||
if ( | ||
(!adminUserAuthToken && | ||
!checkUserPermission?.permissions.includes('add-sales-users-all')) || | ||
!(email?.length > 0) | ||
) { | ||
const sessionData = await session | ||
.getSession(sessionToken as string, ['*']) | ||
.then((currentSession: any) => { | ||
return currentSession.sessionData | ||
}) | ||
let checkUserPermission = null | ||
|
||
if (sessionData?.namespaces) { | ||
const checkUserPermissionResult = await storefrontPermissions | ||
.checkUserPermission('[email protected]') | ||
.catch((error: any) => { | ||
logger.warn({ | ||
logger.error({ | ||
error, | ||
message: 'getOrganizationsByEmail-session-error', | ||
message: 'checkUserPermission-error', | ||
}) | ||
|
||
return null | ||
return { | ||
data: { | ||
checkUserPermission: null, | ||
}, | ||
} | ||
}) | ||
|
||
checkUserPermission = checkUserPermissionResult?.data?.checkUserPermission | ||
} | ||
|
||
if ( | ||
(!adminUserAuthToken && | ||
!checkUserPermission?.permissions.includes('add-sales-users-all')) || | ||
!(email?.length > 0) | ||
) { | ||
if (checkUserPermission?.permissions.includes('add-users-organization')) { | ||
const orgId = | ||
sessionData?.namespaces?.['storefront-permissions']?.organization | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,23 +35,27 @@ const getUserAndPermissions = async (ctx: Context) => { | |
throw new ForbiddenError('Access denied') | ||
} | ||
|
||
const { | ||
data: { checkUserPermission }, | ||
}: any = await storefrontPermissions | ||
// It is necessary to send the app name, because the check user return the permissions relative to orders-history to access the page. | ||
.checkUserPermission('[email protected]') | ||
.catch((error: any) => { | ||
logger.error({ | ||
message: 'checkUserPermission-error', | ||
error, | ||
let checkUserPermission = null | ||
|
||
if (sessionData?.namespaces) { | ||
const checkUserPermissionResult = await storefrontPermissions | ||
// It is necessary to send the app name, because the check user return the permissions relative to orders-history to access the page. | ||
.checkUserPermission('[email protected]') | ||
.catch((error: any) => { | ||
logger.error({ | ||
message: 'checkUserPermission-error', | ||
error, | ||
}) | ||
|
||
return { | ||
data: { | ||
checkUserPermission: null, | ||
}, | ||
} | ||
}) | ||
|
||
return { | ||
data: { | ||
checkUserPermission: null, | ||
}, | ||
} | ||
}) | ||
checkUserPermission = checkUserPermissionResult?.data?.checkUserPermission | ||
} | ||
|
||
const organizationId = | ||
sessionData?.namespaces['storefront-permissions']?.organization?.value | ||
|