From 39d7c2ad0be2d754dfc4f1b8075fe4fa25ef4e35 Mon Sep 17 00:00:00 2001 From: Johnathan Storey Date: Thu, 30 Nov 2023 22:34:18 -0800 Subject: [PATCH] Ofmcc 728 view access permissions (#49) * OFMCC-728. 1st draft commit. Backend spoofed until endpoint ready. Merging to recieve updates from main. * Committing changes in prep for merge of role security changes required for OFMCC-728. * update: OFMCC-728 (View access permissions), added a proposed solution to facility header exemption. * Updated implementation of the facility header show/hide change facility. * Added test for Menu to test conditional display. * OFMCC-728: view user/roles/facilities QA code ready checkin. * OFMCC-728 Code QA changes. * Refactored styles. Updated env banner due to h3 change. * QA code changes. * Fixed issue with button styling. * Addressed QA feedback in SettingsView.vue * Minor style updates. --------- Co-authored-by: weskubo-cgi --- backend/src/components/user.js | 35 ++- backend/src/routes/user.js | 4 +- backend/src/util/mapping/Mappings.js | 22 ++ frontend/src/App.vue | 21 +- frontend/src/assets/css/reset.css | 9 + frontend/src/components/TheEnvBar.vue | 7 +- frontend/src/components/TheFacilityHeader.vue | 13 +- frontend/src/components/TheMenu.vue | 6 +- .../messages/CloseRequestBanner.vue | 16 +- frontend/src/components/ui/AppButton.vue | 31 ++- frontend/src/main.js | 2 + frontend/src/router/index.js | 7 +- frontend/src/utils/constants.js | 3 +- frontend/src/views/SettingsView.vue | 211 +++++++++++++++++- frontend/test/components/TheMenu.test.js | 54 +++++ .../__snapshots__/TheMenu.test.js.snap | 187 ++++++++++++++++ 16 files changed, 589 insertions(+), 39 deletions(-) create mode 100644 frontend/test/components/TheMenu.test.js create mode 100644 frontend/test/components/__snapshots__/TheMenu.test.js.snap diff --git a/backend/src/components/user.js b/backend/src/components/user.js index 927096ae..17b45c08 100644 --- a/backend/src/components/user.js +++ b/backend/src/components/user.js @@ -6,7 +6,14 @@ const axios = require('axios') const HttpStatus = require('http-status-codes') const log = require('../components/logger') // TODO... const { ORGANIZATION_PROVIDER_TYPES} = require('../util/constants') -const { UserProfileMappings, UserProfileOrganizationMappings, UserProfileFacilityPermissionMappings, UserProfileFacilityMappings } = require('../util/mapping/Mappings') +const { + UserProfileMappings, + UserProfileOrganizationMappings, + UserProfileFacilityPermissionMappings, + UserProfileFacilityMappings, + UserPermissionMappings, + FacilityMappings, +} = require('../util/mapping/Mappings') const { MappableObjectForFront } = require('../util/mapping/MappableObject') const _ = require('lodash') @@ -157,6 +164,32 @@ function parseFacilityPermissions(userResponse) { .sort((a, b) => a.facilityName.localeCompare(b.facilityName)) } +function mapUsersPermissionsFacilitiesObjectForFront(data) { + const usersPermissionsFacilities = new MappableObjectForFront(data, UserPermissionMappings).toJSON() + if (usersPermissionsFacilities?.facilities) { + usersPermissionsFacilities.facilities = usersPermissionsFacilities.facilities.map((facility) => { + let facilityData = new MappableObjectForFront(facility, FacilityMappings).toJSON() + facilityData.city = facilityData.address.address1_city + facilityData.address = facilityData.address.address1_line1 + return facilityData + }) + } + return usersPermissionsFacilities +} + +async function getUsersPermissionsFacilities(req, res) { + try { + let usersPermissionsFacilities = [] + const operation = `contacts?$select=ccof_userid,ccof_username,contactid,emailaddress1,ofm_first_name,ofm_is_primary_contact,ofm_last_name,ofm_portal_role,telephone1,ofm_is_expense_authority,statecode&$expand=ofm_facility_business_bceid($select=_ofm_bceid_value,ofm_bceid_facilityid,_ofm_facility_value,ofm_name,ofm_portal_access,statecode,statuscode;$expand=ofm_facility($select=address1_line1,address1_line2,address1_line3,address1_city))&$filter=(_parentcustomerid_value eq ${req.params.organizationId})` + const response = await getOperation(operation) + response?.value?.forEach((item) => usersPermissionsFacilities.push(mapUsersPermissionsFacilitiesObjectForFront(item))) + return res.status(HttpStatus.OK).json(usersPermissionsFacilities) + } catch (e) { + return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status) + } +} + module.exports = { getUserInfo, + getUsersPermissionsFacilities, } diff --git a/backend/src/routes/user.js b/backend/src/routes/user.js index 697c854a..6408ffa3 100644 --- a/backend/src/routes/user.js +++ b/backend/src/routes/user.js @@ -6,10 +6,12 @@ const router = express.Router() const auth = require('../components/auth') const isValidBackendToken = auth.isValidBackendToken() -const { getUserInfo } = require('../components/user') +const { getUserInfo, getUsersPermissionsFacilities } = require('../components/user') router.get('/', passport.authenticate('jwt', { session: false }), isValidBackendToken, getUserInfo) router.get('/:queryUserName', passport.authenticate('jwt', { session: false }), isValidBackendToken, getUserInfo) +router.get('/facilities/:organizationId', passport.authenticate('jwt', { session: false }), isValidBackendToken, getUsersPermissionsFacilities) + module.exports = router diff --git a/backend/src/util/mapping/Mappings.js b/backend/src/util/mapping/Mappings.js index 4ff4ae26..facefdbf 100644 --- a/backend/src/util/mapping/Mappings.js +++ b/backend/src/util/mapping/Mappings.js @@ -77,6 +77,26 @@ const NotificationMappings = [ { back: 'ofm_is_read', front: 'isRead' }, ] +const UserPermissionMappings = [ + { back: 'contactid', front: 'contactId' }, + { back: 'ofm_first_name', front: 'firstName' }, + { back: 'ofm_last_name', front: 'lastName' }, + { back: 'emailaddress1', front: 'email' }, + { back: 'ccof_username', front: 'userName' }, + { back: 'ofm_portal_role', front: 'roles' }, + { back: 'ofm_is_expense_authority', front: 'isExpenseAuthority' }, + { back: 'statecode', front: 'stateCode' }, + { back: 'ofm_facility_business_bceid', front: 'facilities' }, +] + +const FacilityMappings = [ + { back: 'ofm_bceid_facilityid', front: 'facilityId' }, + { back: '_ofm_facility_value@OData.Community.Display.V1.FormattedValue', front: 'name' }, + { back: 'statecode', front: 'stateCode' }, + { back: 'statuscode', front: 'statusCode' }, + { back: 'ofm_facility', front: 'address' }, +] + module.exports = { NotificationMappings, UserProfileMappings, @@ -87,4 +107,6 @@ module.exports = { AssistanceRequestMappings, AssistanceRequestFacilityMappings, AssistanceRequestConversationMappings, + UserPermissionMappings, + FacilityMappings, } diff --git a/frontend/src/App.vue b/frontend/src/App.vue index b11d8905..6dd0501e 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -1,7 +1,7 @@