forked from bcgov/common-hosted-form-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
forms-1782 Call Tenant API Post Successful CHEFS Login
- Loading branch information
1 parent
e4dbf43
commit 00881bb
Showing
16 changed files
with
320 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { appAxios } from '~/services/interceptors'; | ||
import { ApiRoutes } from '~/utils/constants'; | ||
|
||
export default { | ||
/** | ||
* @function getTenantsForUser | ||
* Get the list of tenants current user belongs | ||
* @returns {Promise} An axios response | ||
*/ | ||
getTenantsForUser(params = {}) { | ||
return appAxios().get(`${ApiRoutes.TENANTS}/me`, { params }); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { defineStore } from 'pinia'; | ||
import { tenantService } from '~/services'; | ||
|
||
export const useTenantStore = defineStore('tenant', { | ||
state: () => ({ | ||
tenants: [], | ||
selectedTenant: null, | ||
}), | ||
getters: { | ||
hasTenants: (state) => state.tenants.length > 0, | ||
}, | ||
actions: { | ||
// | ||
// Current User | ||
// | ||
// | ||
async getTenantsForUser() { | ||
try { | ||
// Get the forms based on the user's permissions | ||
const response = await tenantService.getTenantsForUser(); | ||
const data = response.data; | ||
this.tenants = data; | ||
} catch (error) { | ||
throw new Error('something went wrong while getting tenants ', error); | ||
} | ||
}, | ||
setSelectedTenant(tenant) { | ||
this.selectedTenant = tenant; | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
<template> | ||
<div class="tenancy-container"> | ||
<div class="alert-box"> | ||
<span class="close-btn" @click="dismissAlert">×</span> | ||
<h2> | ||
<strong>New Feature Alert!</strong> CHEFS now supports Multi-Tenancy | ||
</h2> | ||
<p> | ||
You can now manage forms across multiple teams (tenancies) while keeping | ||
data, settings, and permissions separate. | ||
</p> | ||
<ul> | ||
<li> | ||
🔹 Switch Between Tenancies – Select the tenancy you want to work in | ||
from your available list. | ||
</li> | ||
<li> | ||
🔹 Access the Older Version – Choose "Non-tenanted CHEFS" to return to | ||
the previous setup. | ||
</li> | ||
</ul> | ||
<a href="#">Learn more about Multi-Tenancy</a> | ||
</div> | ||
|
||
<div class="selection-container"> | ||
<label for="tenantSelect">Choose a Tenancy</label> | ||
<select id="tenantSelect" v-model="selectedTenant"> | ||
<option disabled value="">Select an option...</option> | ||
<option | ||
v-for="tenant in tenantStore.tenants" | ||
:key="tenant.id" | ||
:value="tenant" | ||
> | ||
{{ tenant.name }} | ||
</option> | ||
</select> | ||
<button | ||
:disabled="!selectedTenant" | ||
class="confirm-btn" | ||
@click="confirmTenantSelection" | ||
> | ||
Go to Tenanted CHEFS → | ||
</button> | ||
<a href="#" class="old-chefs-link">Non-tenanted CHEFS ("Old" CHEFS)</a> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { useTenantStore } from '~/store/tenant'; | ||
import { useRouter } from 'vue-router'; | ||
import { ref, onMounted } from 'vue'; | ||
export default { | ||
setup() { | ||
const tenantStore = useTenantStore(); | ||
const router = useRouter(); | ||
const selectedTenant = ref(null); | ||
onMounted(async () => { | ||
if (!tenantStore.hasTenants) { | ||
await tenantStore.getTenantsForUser(); | ||
} | ||
}); | ||
const confirmTenantSelection = () => { | ||
if (selectedTenant.value) { | ||
tenantStore.setSelectedTenant(selectedTenant.value); | ||
router.push('/'); // Redirect to the About page | ||
} | ||
}; | ||
const dismissAlert = () => { | ||
document.querySelector('.alert-box').style.display = 'none'; | ||
}; | ||
return { | ||
tenantStore, | ||
selectedTenant, | ||
confirmTenantSelection, | ||
dismissAlert, | ||
}; | ||
}, | ||
}; | ||
</script> | ||
|
||
<style scoped> | ||
.tenancy-container { | ||
max-width: 700px; | ||
margin: auto; | ||
text-align: center; | ||
padding: 20px; | ||
} | ||
.alert-box { | ||
background: #eef5ff; | ||
padding: 15px; | ||
border-left: 5px solid #0053a0; | ||
margin-bottom: 20px; | ||
position: relative; | ||
text-align: left; | ||
} | ||
.alert-box h2 { | ||
color: #003366; | ||
} | ||
.close-btn { | ||
position: absolute; | ||
top: 10px; | ||
right: 15px; | ||
font-size: 20px; | ||
cursor: pointer; | ||
} | ||
.selection-container { | ||
margin-top: 20px; | ||
} | ||
select { | ||
width: 100%; | ||
padding: 10px; | ||
margin-bottom: 15px; | ||
} | ||
.confirm-btn { | ||
background: #0053a0; | ||
color: white; | ||
padding: 10px 15px; | ||
border: none; | ||
cursor: pointer; | ||
} | ||
.confirm-btn:disabled { | ||
background: #ccc; | ||
cursor: not-allowed; | ||
} | ||
.old-chefs-link { | ||
display: block; | ||
margin-top: 10px; | ||
text-decoration: underline; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const config = require('config'); | ||
const errorToProblem = require('./errorToProblem'); | ||
const SERVICE = 'tenantManagement'; | ||
|
||
class tenantManagementService { | ||
constructor(apiUrl) { | ||
if (!apiUrl) { | ||
throw new Error('tenantManagementService is not configured. Check configuration.'); | ||
} | ||
this.apiUrl = apiUrl; | ||
} | ||
|
||
async getTenantsByUserId() { | ||
try { | ||
const data = { | ||
data: { | ||
tenants: [ | ||
{ | ||
id: '31632dff-96f1-478e-bd77-24ebf2c93094', | ||
name: 'Tenant 1', | ||
ministryName: 'Ministry of Something', | ||
createdDateTime: '2025-02-13T04:08:16.105Z', | ||
updatedDateTime: '2025-02-13T04:08:16.105Z', | ||
}, | ||
{ | ||
id: 'd46a6548-ba5e-47d8-b1b6-de2a6d447650', | ||
name: 'Tenant 2', | ||
ministryName: 'Ministry of Something', | ||
createdDateTime: '2025-02-13T05:18:13.987Z', | ||
updatedDateTime: '2025-02-13T05:18:13.987Z', | ||
}, | ||
{ | ||
id: '8b802d2f-7001-47f4-ade8-b01ff868149b', | ||
name: 'Tenant 3', | ||
ministryName: 'Ministry of Something', | ||
createdDateTime: '2025-02-13T05:31:41.749Z', | ||
updatedDateTime: '2025-02-13T05:31:41.749Z', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
return data.data.tenants; | ||
} catch (e) { | ||
errorToProblem(SERVICE, e); | ||
return { data: { tenants: [] } }; | ||
} | ||
} | ||
} | ||
|
||
const endpoint = config.get('serviceClient.commonServices.tenantManagementService.endpoint'); | ||
|
||
let tmsService = new tenantManagementService(endpoint); | ||
module.exports = tmsService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const service = require('./service'); | ||
|
||
module.exports = { | ||
getTenantsByUserId: async (req, res, next) => { | ||
try { | ||
const response = await service.getTenantsByUserId(req.currentUser); | ||
res.status(200).json(response); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const routes = require('./routes'); | ||
const setupMount = require('../common/utils').setupMount; | ||
|
||
module.exports.mount = (app) => { | ||
return setupMount('tenant', app, routes); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const routes = require('express').Router(); | ||
const { currentUser } = require('../auth/middleware/userAccess'); | ||
const validateParameter = require('../common/middleware/validateParameter'); | ||
|
||
const controller = require('./controller'); | ||
|
||
routes.use(currentUser); | ||
|
||
routes.param('formId', validateParameter.validateFormId); | ||
|
||
routes.get('/me', async (req, res, next) => { | ||
await controller.getTenantsByUserId(req, res, next); | ||
}); | ||
|
||
module.exports = routes; |
Oops, something went wrong.