diff --git a/src/redux/reducers/userReducer.js b/src/redux/reducers/userReducer.js index dd434eb71..8ca9233a0 100644 --- a/src/redux/reducers/userReducer.js +++ b/src/redux/reducers/userReducer.js @@ -87,7 +87,10 @@ const userReducer = (state = initialState, action) => { false ); - const subscriptionPermissions = permissions.filter(value => new RegExp(helpers.UI_NAME, 'i').test(value)); + const subscriptionPermissions = permissions.map(value => ({ + permission: value[platformApiTypes.PLATFORM_API_RESPONSE_USER_PERMISSION_TYPES.PERMISSION], + definitions: value[platformApiTypes.PLATFORM_API_RESPONSE_USER_PERMISSION_TYPES.RESOURCE_DEFS] + })); return reduxHelpers.setStateProp( 'session', @@ -127,6 +130,7 @@ const userReducer = (state = initialState, action) => { error: true, errorMessage: reduxHelpers.getMessageFromResults(action), locale: state.session.locale, + permissions: state.session.permissions, status: reduxHelpers.getStatusFromResults(action) }, { diff --git a/src/services/__tests__/__snapshots__/platformServices.test.js.snap b/src/services/__tests__/__snapshots__/platformServices.test.js.snap index 89a73f9e5..32920fdd3 100644 --- a/src/services/__tests__/__snapshots__/platformServices.test.js.snap +++ b/src/services/__tests__/__snapshots__/platformServices.test.js.snap @@ -2,8 +2,6 @@ exports[`PlatformServices should return a failed getUser: failed authorized user 1`] = `[Error: { getUser } = insights.chrome.auth, insights.chrome.auth.getUser is not a function]`; -exports[`PlatformServices should return a failed getUserPermissions: failed user permissions 1`] = `[Error: { getUserPermissions } = insights.chrome, insights.chrome.getUserPermissions is not a function]`; - exports[`PlatformServices should return a failed initializeChrome: failed initializeChrome 1`] = `[Error: { init } = insights.chrome, insights.chrome.init is not a function]`; exports[`PlatformServices should return a failed setAppName: failed setAppName 1`] = `"{ identifyApp } = insights.chrome, insights.chrome.identifyApp is not a function"`; diff --git a/src/services/__tests__/platformServices.test.js b/src/services/__tests__/platformServices.test.js index 1ed9a69ed..4641e6935 100644 --- a/src/services/__tests__/platformServices.test.js +++ b/src/services/__tests__/platformServices.test.js @@ -52,13 +52,12 @@ describe('PlatformServices', () => { }); }); - it('should return a failed getUserPermissions', done => { + it('should return a failed getUserPermissions', () => { window.insights.chrome.getUserPermissions = undefined; - platformServices.getUserPermissions().catch(error => { - expect(error).toMatchSnapshot('failed user permissions'); - done(); - }); + expect(platformServices.getUserPermissions).toThrowError( + '{ getUserPermissions } = insights.chrome, insights.chrome.getUserPermissions is not a function' + ); }); it('should return a failed initializeChrome', done => { diff --git a/src/services/platformServices.js b/src/services/platformServices.js index d2c276fc6..ce863f8bf 100644 --- a/src/services/platformServices.js +++ b/src/services/platformServices.js @@ -28,15 +28,21 @@ const getUser = async () => { } }; +/** + * FixMe: revert this back towards async/await + * Removed because there appears to be some quirky behavior where permissions will not come through + * unless the function, and/or await are specifically returned, i.e. "return await insights.chrome...". + */ /** * Basic user permissions. * + * @param {string} appName * @returns {Promise} */ -const getUserPermissions = async () => { +const getUserPermissions = (appName = '') => { const { insights } = window; try { - await insights.chrome.getUserPermissions(); + return insights.chrome.getUserPermissions(appName); } catch (e) { throw new Error(`{ getUserPermissions } = insights.chrome, ${e.message}`); } diff --git a/src/services/userServices.js b/src/services/userServices.js index 53129ccb7..f262a5b93 100644 --- a/src/services/userServices.js +++ b/src/services/userServices.js @@ -17,7 +17,7 @@ const authorizeUser = async () => { try { userData = await getUser(); - userPermissions = await getUserPermissions(); + userPermissions = await getUserPermissions(helpers.UI_NAME); } catch (e) { message = e.message; } diff --git a/src/types/__tests__/__snapshots__/index.test.js.snap b/src/types/__tests__/__snapshots__/index.test.js.snap index 0d8311bfe..a8eaffdc1 100644 --- a/src/types/__tests__/__snapshots__/index.test.js.snap +++ b/src/types/__tests__/__snapshots__/index.test.js.snap @@ -15,6 +15,10 @@ Object { "PLATFORM_API_RESPONSE_USER_IDENTITY_USER_TYPES": Object { "ORG_ADMIN": "is_org_admin", }, + "PLATFORM_API_RESPONSE_USER_PERMISSION_TYPES": Object { + "PERMISSION": "permission", + "RESOURCE_DEFS": "resourceDefinitions", + }, }, "rhsmApi": Object { "RHSM_API_PATH_ID_TYPES": Object { @@ -101,6 +105,10 @@ Object { "PLATFORM_API_RESPONSE_USER_IDENTITY_USER_TYPES": Object { "ORG_ADMIN": "is_org_admin", }, + "PLATFORM_API_RESPONSE_USER_PERMISSION_TYPES": Object { + "PERMISSION": "permission", + "RESOURCE_DEFS": "resourceDefinitions", + }, }, "rhsmApi": Object { "RHSM_API_PATH_ID_TYPES": Object { @@ -186,6 +194,10 @@ Object { "PLATFORM_API_RESPONSE_USER_IDENTITY_USER_TYPES": Object { "ORG_ADMIN": "is_org_admin", }, + "PLATFORM_API_RESPONSE_USER_PERMISSION_TYPES": Object { + "PERMISSION": "permission", + "RESOURCE_DEFS": "resourceDefinitions", + }, }, "rhsmApiTypes": Object { "RHSM_API_PATH_ID_TYPES": Object { @@ -275,6 +287,10 @@ Object { "PLATFORM_API_RESPONSE_USER_IDENTITY_USER_TYPES": Object { "ORG_ADMIN": "is_org_admin", }, + "PLATFORM_API_RESPONSE_USER_PERMISSION_TYPES": Object { + "PERMISSION": "permission", + "RESOURCE_DEFS": "resourceDefinitions", + }, }, "rhsmApi": Object { "RHSM_API_PATH_ID_TYPES": Object { diff --git a/src/types/platformApiTypes.js b/src/types/platformApiTypes.js index c65150c55..5302dee88 100644 --- a/src/types/platformApiTypes.js +++ b/src/types/platformApiTypes.js @@ -42,6 +42,17 @@ const PLATFORM_API_RESPONSE_USER_IDENTITY_USER_TYPES = { ORG_ADMIN: 'is_org_admin' }; +/** + * Platform response of USER PERMISSION type values. + * Schema/map of expected response identity user permission types. + * + * @type {{PERMISSION: string}} + */ +const PLATFORM_API_RESPONSE_USER_PERMISSION_TYPES = { + PERMISSION: 'permission', + RESOURCE_DEFS: 'resourceDefinitions' +}; + /** * Platform API types. * @@ -55,7 +66,8 @@ const platformApiTypes = { PLATFORM_API_RESPONSE_USER_ENTITLEMENTS_APP_TYPES, PLATFORM_API_RESPONSE_USER_IDENTITY, PLATFORM_API_RESPONSE_USER_IDENTITY_TYPES, - PLATFORM_API_RESPONSE_USER_IDENTITY_USER_TYPES + PLATFORM_API_RESPONSE_USER_IDENTITY_USER_TYPES, + PLATFORM_API_RESPONSE_USER_PERMISSION_TYPES }; export { @@ -65,5 +77,6 @@ export { PLATFORM_API_RESPONSE_USER_ENTITLEMENTS_APP_TYPES, PLATFORM_API_RESPONSE_USER_IDENTITY, PLATFORM_API_RESPONSE_USER_IDENTITY_TYPES, - PLATFORM_API_RESPONSE_USER_IDENTITY_USER_TYPES + PLATFORM_API_RESPONSE_USER_IDENTITY_USER_TYPES, + PLATFORM_API_RESPONSE_USER_PERMISSION_TYPES };