@@ -30,7 +30,7 @@ import { ref, reactive, inject, onBeforeMount } from 'vue'
3030import { onBeforeRouteUpdate , useRoute } from ' vue-router'
3131import { getOperationDetails } from ' ../obp/resource-docs'
3232import { ElNotification , FormInstance } from ' element-plus'
33- import { OBP_API_DEFAULT_RESOURCE_DOC_VERSION , get , create , update , discard , createEntitlement , getCurrentUser } from ' ../obp'
33+ import { OBP_API_DEFAULT_RESOURCE_DOC_VERSION , get , create , update , discard , createEntitlement , getCurrentUser , getUserEntitlements } from ' ../obp'
3434import { obpResourceDocsKey } from ' @/obp/keys'
3535import JsonEditorVue from ' json-editor-vue'
3636import { Mode } from ' vanilla-jsoneditor'
@@ -57,6 +57,7 @@ const showValidations = ref(true)
5757const showPossibleErrors = ref (true )
5858const showConnectorMethods = ref (true )
5959const isUserLogon = ref (true )
60+ const userEntitlements = ref ([])
6061const type = ref (' ' )
6162const resourceDocs = inject (obpResourceDocsKey )
6263const footNote = ref ({
@@ -118,6 +119,34 @@ const setRoleForm = () => {
118119 }
119120}
120121
122+ const refreshEntitlements = async () => {
123+ const currentUser = await getCurrentUser ()
124+ if (currentUser .username ) {
125+ const entitlements = await getUserEntitlements ()
126+ if (entitlements && entitlements .list ) {
127+ userEntitlements .value = entitlements .list
128+ }
129+ }
130+ }
131+
132+ const hasEntitlement = (roleName : string , bankId : string = ' ' , requiresBankId : boolean = false ): boolean => {
133+ if (! userEntitlements .value || userEntitlements .value .length === 0 ) {
134+ return false
135+ }
136+
137+ if (requiresBankId ) {
138+ // For bank-level roles, check if user has the role for the specific bank
139+ // Only return true if bankId is provided and matches
140+ if (! bankId ) {
141+ return false
142+ }
143+ return userEntitlements .value .some (e => e .role_name === roleName && e .bank_id === bankId )
144+ } else {
145+ // For system-wide roles, just check if user has the role
146+ return userEntitlements .value .some (e => e .role_name === roleName )
147+ }
148+ }
149+
121150const setType = (method ) => {
122151 switch (method ) {
123152 case ' POST' : {
@@ -316,6 +345,8 @@ const submitEntitlement = async () => {
316345 position: ' bottom-right' ,
317346 type: ' success'
318347 })
348+ // Refresh entitlements after successful request
349+ await refreshEntitlements ()
319350 }
320351 } catch (error : any ) {
321352 ElNotification ({
@@ -388,6 +419,8 @@ const submitEntitlement = async () => {
388419 position: ' bottom-right' ,
389420 type: ' success'
390421 })
422+ // Refresh entitlements after successful request
423+ await refreshEntitlements ()
391424 }
392425 } catch (error : any ) {
393426 ElNotification ({
@@ -412,9 +445,18 @@ onBeforeMount(async () => {
412445
413446 const currentUser = await getCurrentUser ()
414447 isUserLogon .value = currentUser .username
448+
449+ // Fetch user entitlements
450+ if (currentUser .username ) {
451+ const entitlements = await getUserEntitlements ()
452+ if (entitlements && entitlements .list ) {
453+ userEntitlements .value = entitlements .list
454+ }
455+ }
456+
415457 setRoleForm ()
416458})
417- onBeforeRouteUpdate ((to ) => {
459+ onBeforeRouteUpdate (async (to ) => {
418460 const version = to .params .version ? to .params .version : configVersion
419461
420462 // Only set operation details if operationid exists
@@ -423,6 +465,9 @@ onBeforeRouteUpdate((to) => {
423465 responseHeaderTitle .value = ' TYPICAL SUCCESSFUL RESPONSE'
424466 }
425467
468+ // Refresh entitlements on route change
469+ await refreshEntitlements ()
470+
426471 setRoleForm ()
427472})
428473
@@ -547,19 +592,28 @@ const onError = (error) => {
547592 >
548593 <p >{{ role.role }}</p >
549594 <div class =" flex-role-preview-panel" id =" request-role-button-panel" >
550- <el-form-item v-show =" role.requires_bank_id" :prop =" `bankId${role.role}${idx}`" >
595+ <el-form-item
596+ v-show =" role.requires_bank_id && !hasEntitlement(role.role, roleForm[`bankId${role.role}${idx}`], role.requires_bank_id)"
597+ :prop =" `bankId${role.role}${idx}`"
598+ >
551599 <input
552600 type =" text"
553601 v-model =" roleForm[`bankId${role.role}${idx}`]"
554602 placeholder =" Bank ID"
555603 />
556604 </el-form-item >
605+ <span
606+ v-if =" hasEntitlement(role.role, roleForm[`bankId${role.role}${idx}`], role.requires_bank_id)"
607+ class =" entitlement-owned-text"
608+ >
609+ You have this Entitlement
610+ </span >
557611 </div >
558612 </li >
559613 </ul >
560614 <el-button
561615 id =" request-role-button"
562- v-show =" isUserLogon"
616+ v-show =" isUserLogon && requiredRoles.some((role, idx) => !hasEntitlement(role.role, roleForm[`bankId${role.role}${idx}`], role.requires_bank_id)) "
563617 @click =" submit(roleFormRef, submitEntitlement)"
564618 >Request</el-button
565619 >
@@ -747,6 +801,12 @@ li {
747801 width : 95% ;
748802 margin : 0 0 -30px 0 ;
749803}
804+ .entitlement-owned-text {
805+ color : #67c23a ;
806+ font-weight : 500 ;
807+ font-size : 14px ;
808+ margin-left : 10px ;
809+ }
750810
751811#conector-method-link {
752812 color : white !important ;
0 commit comments