Skip to content

Commit

Permalink
Innkeeper edit tenant config
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas ONeil <lucasoneil@gmail.com>
  • Loading branch information
loneil committed May 31, 2023
1 parent 21ed35a commit 340f36b
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 32 deletions.
15 changes: 6 additions & 9 deletions services/tenant-ui/frontend/src/components/LoginForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,12 @@ const handleSubmit = async (isFormValid: boolean) => {
tenantStore.getTenantConfig(),
tenantStore.getIssuanceStatus(),
]);
const rejected = results.filter(
(result): result is PromiseRejectedResult =>
result.status === 'rejected'
);
if (rejected.length > 0) {
console.error(rejected);
throw new Error(rejected[0].reason);
}
// if any the Tenant details fetch fails, throw the first error
results.forEach((result) => {
if (result.status === 'rejected') {
throw result.reason;
}
});
} catch (err) {
console.error(err);
toast.error(`Failure getting tenant info: ${err}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
<Column :expander="true" header-style="width: 3rem" />
<Column :sortable="false" :header="$t('common.actions')">
<template #body="{ data }">
<EditConfig :id="data.tenant_id" />
<EditContact :connection-id="data.connection_id" />
<EditConfig :tenant="data" />
</template>
</Column>
<Column :sortable="true" field="tenant_name" header="Name" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@update:visible="handleClose"
>
<EditConfigForm
:id="props.id"
:tenant="props.tenant"
@success="$emit('success')"
@closed="handleClose"
/>
Expand All @@ -23,6 +23,9 @@
</template>

<script setup lang="ts">
// Types
import { TenantRecord } from '@/types/acapyApi/acapyInterface';
// Vue
import { ref } from 'vue';
// PrimeVue
Expand All @@ -35,7 +38,7 @@ defineEmits(['success']);
// Props
const props = defineProps<{
id: string;
tenant: TenantRecord;
}>();
const displayModal = ref(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<template>
<form @submit.prevent="handleSubmit(!v$.$invalid)">
<p class="my-0">
<strong>{{ $t('tenants.settings.ledgerName') }} </strong>
{{ config.frontend?.ariesDetails?.ledgerName }}
</p>
<p class="mt-0">
<strong> {{ $t('tenants.settings.endorserAlias') }} </strong>
{{ endorserInfo?.endorser_name }}
</p>
<!-- Can Connect to endorser -->
<div class="field">
<label for="canConnectEndorser">
Expand All @@ -23,36 +31,46 @@
type="submit"
:label="$t('common.submit')"
class="w-full"
:disabled="loading"
:disabled="loading || loadingEndorser"
/>
</form>
</template>

<script setup lang="ts">
// Types
import { TenantConfig } from '@/types/acapyApi/acapyInterface';
import { TenantRecord } from '@/types/acapyApi/acapyInterface';

// Vue
import { reactive, ref } from 'vue';
import { onMounted, reactive, ref } from 'vue';
// PrimeVue / Validation
import Button from 'primevue/button';
import InputSwitch from 'primevue/inputswitch';
import { useVuelidate } from '@vuelidate/core';
import { useToast } from 'vue-toastification';
// State
import { useInnkeeperTenantsStore } from '@/store';
import {
useConfigStore,
useInnkeeperTenantsStore,
useTenantStore,
} from '@/store';
import { storeToRefs } from 'pinia';

const toast = useToast();

const emit = defineEmits(['closed', 'success']);

const { config } = storeToRefs(useConfigStore());
const { loading } = storeToRefs(useInnkeeperTenantsStore());
const innkeeperTenantsStore = useInnkeeperTenantsStore();
// For the innkeeper tenant, reuse here for getting configured endorser
const tenantStore = useTenantStore();
const { endorserInfo, loading: loadingEndorser } = storeToRefs(
useTenantStore()
);

// Props
const props = defineProps<{
id: string;
tenant: TenantRecord;
}>();

// Validation
Expand All @@ -76,14 +94,18 @@ const handleSubmit = async (isFormValid: boolean) => {
}

try {
await innkeeperTenantsStore.updateTenantConfig(props.id, {
connect_to_endorser: [
{
endorser_alias: 'endorser',
ledger_id: 'bcovrin-test',
},
],
create_public_did: ['bcovrin-test'],
await innkeeperTenantsStore.updateTenantConfig(props.tenant.tenant_id, {
connect_to_endorser: formFields.canConnectEndorser
? [
{
endorser_alias: endorserInfo.value?.endorser_name || '',
ledger_id: config.value.frontend?.ariesDetails?.ledgerName,
},
]
: [],
create_public_did: formFields.canRegisterDid
? [config.value.frontend?.ariesDetails?.ledgerName]
: [],
});
toast.success('Tenant Settings Updated');
emit('success');
Expand All @@ -95,4 +117,15 @@ const handleSubmit = async (isFormValid: boolean) => {
submitted.value = false;
}
};

onMounted(() => {
// Determine if the Tenant already has the config permission
// This will change in the future for multi-ledger support but
// for now determine by the fields being set.
formFields.canConnectEndorser = !!props.tenant.connected_to_endorsers?.length;
formFields.canRegisterDid = !!props.tenant.created_public_did?.length;

// Fetch the configured instance endorser details
tenantStore.getEndorserInfo();
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
</div>
</div>
<p v-else class="my-1">
<i class="pi pi-info-circle"></i>
<i class="pi pi-times-circle"></i>
{{ $t('profile.connectTenantToEndorserNotAllowed') }}
</p>
</template>

<script setup lang="ts">
import { computed, ref } from 'vue';
import { computed } from 'vue';
import InputSwitch from 'primevue/inputswitch';
import Accordion from 'primevue/accordion';
import AccordionTab from 'primevue/accordiontab';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</div>
</div>
<p v-else class="my-1">
<i class="pi pi-info-circle"></i>
<i class="pi pi-times-circle"></i>
{{ $t('profile.registerPublicDidNotAllowed') }}
</p>
</template>
Expand Down
5 changes: 4 additions & 1 deletion services/tenant-ui/frontend/src/plugins/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,10 @@
"settings": {
"canConnectEndorser": "Tenant allowed to connect to Endorser",
"canRegisterDid": "Tenant allowed to register public DID",
"editSettings": "Edit Tenant Config"
"editSettings": "Edit Tenant Config",
"endorserAlias": "Endorser Alias:",
"ledgerName": "Ledger Name:",
"success": "Tenant Config Updated"
},
"tenants": "Tenants"
},
Expand Down
5 changes: 4 additions & 1 deletion services/tenant-ui/frontend/src/plugins/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,10 @@
"settings": {
"canConnectEndorser": "Tenant allowed to connect to Endorser <FR>",
"canRegisterDid": "Tenant allowed to register public DID <FR>",
"editSettings": "Edit Tenant Config <FR>"
"editSettings": "Edit Tenant Config <FR>",
"endorserAlias": "Endorser Alias <FR>",
"ledgerName": "Ledger Name <FR>",
"success": "Tenant Config Updated <FR>"
},
"tenants": "Tenants <FR>"
},
Expand Down
5 changes: 4 additions & 1 deletion services/tenant-ui/frontend/src/plugins/i18n/locales/jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,10 @@
"settings": {
"canConnectEndorser": "Tenant allowed to connect to Endorser <JP>",
"canRegisterDid": "Tenant allowed to register public DID <JP>",
"editSettings": "Edit Tenant Config <JP>"
"editSettings": "Edit Tenant Config <JP>",
"endorserAlias": "Endorser Alias <JP>",
"ledgerName": "Ledger Name <JP>",
"success": "Tenant Config Updated <FR>"
},
"tenants": "Tenants <JP>"
},
Expand Down

0 comments on commit 340f36b

Please sign in to comment.