diff --git a/src/security-server/admin-service/ui/src/main.ts b/src/security-server/admin-service/ui/src/main.ts index a2a4a5807f..9d6d60046b 100644 --- a/src/security-server/admin-service/ui/src/main.ts +++ b/src/security-server/admin-service/ui/src/main.ts @@ -69,12 +69,16 @@ import '@fontsource/open-sans'; import '@niis/shared-ui/dist/style.css'; import i18n from './plugins/i18n'; import { createPinia } from 'pinia'; -import piniaPluginPersistedState from 'pinia-plugin-persistedstate'; +import { createPersistedState } from 'pinia-plugin-persistedstate'; import { createFilters } from '@/filters'; import { createValidators } from '@/plugins/vee-validate'; const pinia = createPinia(); -pinia.use(piniaPluginPersistedState); +pinia.use( + createPersistedState({ + storage: sessionStorage, + }), +); axios.defaults.baseURL = import.meta.env.VITE_VUE_APP_BASE_URL; axios.defaults.headers.get.Accepts = 'application/json'; diff --git a/src/security-server/admin-service/ui/src/store/modules/services.ts b/src/security-server/admin-service/ui/src/store/modules/services.ts index d9d1ee44c5..efdac7d398 100644 --- a/src/security-server/admin-service/ui/src/store/modules/services.ts +++ b/src/security-server/admin-service/ui/src/store/modules/services.ts @@ -57,6 +57,9 @@ export const useServices = defineStore('services', { serviceDescriptions: [], }; }, + persist: { + paths: ['service', 'serviceClients', 'serviceDescriptions'], + }, getters: { descExpanded: (state) => (id: string) => { return state.expandedServiceDescriptions.includes(id); @@ -94,16 +97,7 @@ export const useServices = defineStore('services', { }, setService(service: Service) { - service.endpoints = service.endpoints?.sort( - (a: Endpoint, b: Endpoint) => { - const sortByGenerated = - a.generated === b.generated ? 0 : a.generated ? -1 : 1; - const sortByPathSlashCount = - a.path.split('/').length - b.path.split('/').length; - const sortByPathLength = a.path.length - b.path.length; - return sortByGenerated || sortByPathSlashCount || sortByPathLength; - }, - ); + service.endpoints = sortEndpoints(service.endpoints); this.service = service; }, @@ -126,5 +120,55 @@ export const useServices = defineStore('services', { throw error; }); }, + deleteEndpoint(id: string) { + return api + .remove(`/endpoints/${encodePathParameter(id)}`) + .then((res) => { + this.service.endpoints?.forEach((item, index) => { + if (item.id === id) { + this.service.endpoints?.splice(index, 1); + } + }); + }) + .catch((error) => { + throw error; + }); + }, + updateEndpoint(endpoint: Endpoint) { + if (!endpoint.id) { + throw new Error('Unable to save endpoint: Endpoint id not defined!'); + } + return api + .patch( + `/endpoints/${encodePathParameter(endpoint.id)}`, + endpoint, + ) + .then((res) => { + if (this.service.endpoints) { + const endpointIndex = this.service.endpoints.findIndex( + (e) => e.id === endpoint.id, + ); + if (endpointIndex) { + const endpoints = [...this.service.endpoints]; + endpoints[endpointIndex] = res.data; + this.service.endpoints = sortEndpoints(endpoints); + } + } + }) + .catch((error) => { + throw error; + }); + }, }, }); + +function sortEndpoints(endpoints: Endpoint[] | undefined) { + return endpoints?.sort((a: Endpoint, b: Endpoint) => { + const sortByGenerated = + a.generated === b.generated ? 0 : a.generated ? -1 : 1; + const sortByPathSlashCount = + a.path.split('/').length - b.path.split('/').length; + const sortByPathLength = a.path.length - b.path.length; + return sortByGenerated || sortByPathSlashCount || sortByPathLength; + }); +} diff --git a/src/security-server/admin-service/ui/src/store/modules/system.ts b/src/security-server/admin-service/ui/src/store/modules/system.ts index 55a4a7b687..cb46a2a6de 100644 --- a/src/security-server/admin-service/ui/src/store/modules/system.ts +++ b/src/security-server/admin-service/ui/src/store/modules/system.ts @@ -35,7 +35,9 @@ export const useSystem = defineStore('system', { securityServerNodeType: undefined as undefined | NodeType, }; }, - persist: true, // This store is saved into browser local storage (pinia-plugin-persistedstate) + persist: { + storage: localStorage, + }, getters: { isSecondaryNode(state) { return state.securityServerNodeType === NodeType.SECONDARY; diff --git a/src/security-server/admin-service/ui/src/store/modules/tokens.ts b/src/security-server/admin-service/ui/src/store/modules/tokens.ts index bd19965b45..cca19480de 100644 --- a/src/security-server/admin-service/ui/src/store/modules/tokens.ts +++ b/src/security-server/admin-service/ui/src/store/modules/tokens.ts @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -import { Key, Token, TokenCertificate } from '@/openapi-types'; +import { Key, Token, TokenCertificate, TokenPinUpdate } from '@/openapi-types'; import * as api from '@/util/api'; import { deepClone } from '@/util/helpers'; import { encodePathParameter } from '@/util/api'; @@ -56,6 +56,9 @@ export const useTokens = defineStore('tokens', { selectedToken: undefined as Token | undefined, }; }, + persist: { + paths: ['tokens', 'selectedToken'], + }, getters: { filteredTokens: (state) => (search: string) => { // Filter term is applied to token name key name and certificate owner id @@ -188,5 +191,27 @@ export const useTokens = defineStore('tokens', { throw error; }); }, + updatePin(tokenId: string, oldPin: string, newPin: string) { + const tokenPinUpdate: TokenPinUpdate = { + old_pin: oldPin, + new_pin: newPin, + }; + return api + .put(`/tokens/${encodePathParameter(tokenId)}/pin`, tokenPinUpdate) + .catch((error) => { + throw error; + }); + }, + updateToken(token: Token) { + return api + .patch(`/tokens/${encodePathParameter(token.id)}`, token) + .then((res) => { + const tokenIndex = this.tokens.findIndex((t) => t.id === token.id); + this.tokens[tokenIndex] = res.data; + }) + .catch((error) => { + throw error; + }); + }, }, }); diff --git a/src/security-server/admin-service/ui/src/store/modules/user.ts b/src/security-server/admin-service/ui/src/store/modules/user.ts index e217aa6f8c..e1e14efdf8 100644 --- a/src/security-server/admin-service/ui/src/store/modules/user.ts +++ b/src/security-server/admin-service/ui/src/store/modules/user.ts @@ -53,7 +53,9 @@ export const useUser = defineStore('user', { bannedRoutes: [] as RouteRecordName[], // Array for routes the user doesn't have permission to access. }; }, - persist: true, // This store is saved into browser local storage (pinia-plugin-persistedstate) + persist: { + storage: localStorage, + }, getters: { hasPermission: (state) => (perm: string) => { return state.permissions.includes(perm); @@ -227,6 +229,8 @@ export const useUser = defineStore('user', { const system = useSystem(); system.clearSystemStore(); + sessionStorage.clear(); + // Call backend for logout return axiosAuth .post('/logout') diff --git a/src/security-server/admin-service/ui/src/views/LocalGroup/LocalGroup.vue b/src/security-server/admin-service/ui/src/views/LocalGroup/LocalGroup.vue index 063e573635..bcad54e122 100644 --- a/src/security-server/admin-service/ui/src/views/LocalGroup/LocalGroup.vue +++ b/src/security-server/admin-service/ui/src/views/LocalGroup/LocalGroup.vue @@ -185,7 +185,6 @@ export default defineComponent({ required: true, }, }, - emits: ['backk'], data() { return { confirmGroup: false, diff --git a/src/security-server/admin-service/ui/src/views/Service/Endpoints/Endpoint/EndpointDetails.vue b/src/security-server/admin-service/ui/src/views/Service/Endpoints/Endpoint/EndpointDetails.vue index 04da278c9a..de95a36efb 100644 --- a/src/security-server/admin-service/ui/src/views/Service/Endpoints/Endpoint/EndpointDetails.vue +++ b/src/security-server/admin-service/ui/src/views/Service/Endpoints/Endpoint/EndpointDetails.vue @@ -81,7 +81,7 @@ class="save-button" :loading="saving" :disabled="!meta.touched || !meta.valid" - @click="saveEndpoint()" + @click="save()" >{{ $t('action.save') }} @@ -92,16 +92,14 @@ title="endpoints.deleteTitle" text="endpoints.deleteEndpointText" @cancel="confirmDelete = false" - @accept="deleteEndpoint(id)" + @accept="remove(id)" />