From 4e4ac8047b249e0e39d41ae726e731d555e955ab Mon Sep 17 00:00:00 2001 From: simonredfern Date: Fri, 19 Dec 2025 08:05:40 +0100 Subject: [PATCH] Request Entitlement: bank_id on same line as Role --- src/components/Preview.vue | 197 +++++++++++++++++++++++++++++++++---- 1 file changed, 177 insertions(+), 20 deletions(-) diff --git a/src/components/Preview.vue b/src/components/Preview.vue index f6a9d05..e909579 100644 --- a/src/components/Preview.vue +++ b/src/components/Preview.vue @@ -278,6 +278,135 @@ const highlightCode = (json) => { ) } } +const submitSingleEntitlement = async (formRole: any, idx: number) => { + const role = roleForm[`role${formRole.role}${idx}`] + + if (formRole.requires_bank_id) { + // Bank-level entitlement + const bankId = roleForm[`bankId${formRole.role}${idx}`] + + if (!role || !bankId) { + ElNotification({ + duration: elMessageDuration, + title: 'Validation Error', + message: 'Please fill in both Role and Bank ID fields', + position: 'bottom-right', + type: 'warning' + }) + return + } + + try { + const response = await createEntitlement(bankId, role) + + // Check if response is an error object (from superagent) + const isError = response && typeof response === 'object' && 'error' in response + const errorBody = isError ? response.error : null + + if (isError && errorBody && errorBody.code >= 400) { + // Parse error message from body + let errorMessage = 'Failed to create entitlement' + if (errorBody.message) { + // Message might be double-encoded JSON string + try { + const parsed = JSON.parse(errorBody.message) + errorMessage = parsed.message || parsed.error || errorBody.message + } catch { + errorMessage = errorBody.message + } + } + + ElNotification({ + duration: elMessageDuration, + title: 'Request Failed', + message: errorMessage, + position: 'bottom-right', + type: 'error' + }) + } else { + ElNotification({ + duration: elMessageDuration, + title: 'Success', + message: `Entitlement "${role}" requested successfully for bank "${bankId}"`, + position: 'bottom-right', + type: 'success' + }) + // Refresh entitlements after successful request + await refreshEntitlements() + } + } catch (error: any) { + ElNotification({ + duration: elMessageDuration, + title: 'Request Failed', + message: error.message || 'An error occurred while requesting the entitlement', + position: 'bottom-right', + type: 'error' + }) + } + } else { + // System-wide entitlement (no bank_id required) + if (!role) { + ElNotification({ + duration: elMessageDuration, + title: 'Validation Error', + message: 'Please select a role', + position: 'bottom-right', + type: 'warning' + }) + return + } + + try { + // System-wide entitlement uses empty string for bank_id + const response = await createEntitlement('', role) + + // Check if response is an error object (from superagent) + const isError = response && typeof response === 'object' && 'error' in response + const errorBody = isError ? response.error : null + + if (isError && errorBody && errorBody.code >= 400) { + // Parse error message from body + let errorMessage = 'Failed to create entitlement' + if (errorBody.message) { + // Message might be double-encoded JSON string + try { + const parsed = JSON.parse(errorBody.message) + errorMessage = parsed.message || parsed.error || errorBody.message + } catch { + errorMessage = errorBody.message + } + } + + ElNotification({ + duration: elMessageDuration, + title: 'Request Failed', + message: errorMessage, + position: 'bottom-right', + type: 'error' + }) + } else { + ElNotification({ + duration: elMessageDuration, + title: 'Success', + message: `System-wide entitlement "${role}" requested successfully`, + position: 'bottom-right', + type: 'success' + }) + // Refresh entitlements after successful request + await refreshEntitlements() + } + } catch (error: any) { + ElNotification({ + duration: elMessageDuration, + title: 'Request Failed', + message: error.message || 'An error occurred while requesting the entitlement', + position: 'bottom-right', + type: 'error' + }) + } + } +} + const submitEntitlement = async () => { for (const [idx, formRole] of requiredRoles.value.entries()) { const role = roleForm[`role${formRole.role}${idx}`] @@ -581,7 +710,7 @@ const onError = (error) => {

{{ $t('preview.required_roles') }}:

-

Please login to request this Role.

+

Please login to request Roles.

- Request
@@ -708,9 +839,18 @@ input[type='text']:focus { } ul { margin-left: -10px; + list-style: none; + padding: 0; } li { - padding: 5px 0 5px 0; + padding: 15px; + margin-bottom: 15px; + border: 1px solid #414d63; + border-radius: 6px; + background-color: rgba(65, 77, 99, 0.2); +} +li:last-child { + margin-bottom: 0; } .content p a::after { content: ''; @@ -807,9 +947,26 @@ li { display: flex; align-items: center; gap: 15px; + justify-content: space-between; +} +.role-name-section { + display: flex; + align-items: center; + gap: 15px; + flex: 1; +} +.role-bank-id-input { + margin-bottom: 0; +} +.role-bank-id-input input { + width: 200px; +} +.role-request-button { + margin-left: auto; } .role-header p { margin: 0; + white-space: nowrap; } .entitlement-owned-text { color: #67c23a;