Vincent GUFFON 4 years ago
parent
commit
27cc1c141a

+ 39 - 0
components/Layout/AlertBar/SuperAdmin.vue

@@ -0,0 +1,39 @@
+<!--
+Super Admin bar : Barre qui s'affiche lorsque l'utilisateur est un super admin en mode switch
+-->
+
+<template>
+  <UiSystemBar color="ot_danger" v-if="show">
+    <template #bar.text>
+      <v-icon small>fas fa-exclamation-triangle</v-icon>
+      <span>{{$t('super_admin_switch_account')}}</span>
+      <a :href="url" class="ot_black--text text-decoration-none"><strong>{{$t('click_here')}}</strong></a>
+    </template>
+  </UiSystemBar>
+</template>
+
+<script lang="ts">
+import { defineComponent, useStore, useContext} from '@nuxtjs/composition-api'
+import {AnyStore} from "~/types/interfaces";
+import {State} from "@vuex-orm/core";
+
+export default defineComponent({
+  setup () {
+    const {$config} = useContext()
+    const baseLegacyUrl:string = $config.baseURL_adminLegacy
+    const store:AnyStore = useStore<State>()
+    const originalAccess = store.state.profile.access.originalAccess
+
+    const url = `${baseLegacyUrl}/switch_user/${originalAccess.organization.id}/${originalAccess.id}/exit`
+
+    return {
+      show: originalAccess.isSuperAdminAccess,
+      url
+    }
+  }
+})
+</script>
+
+<style scoped>
+
+</style>

+ 1 - 0
components/Layout/Alertbar.vue

@@ -9,6 +9,7 @@ Contient les différentes barre d'alertes qui s'affichent selon certains cas...
     <LayoutAlertBarSwitchUser></LayoutAlertBarSwitchUser>
     <LayoutAlertBarCotisation v-if="isCmf && $can('manage', 'cotisation')"></LayoutAlertBarCotisation>
     <LayoutAlertBarSwitchYear></LayoutAlertBarSwitchYear>
+    <LayoutAlertBarSuperAdmin></LayoutAlertBarSuperAdmin>
   </main>
 </template>
 

+ 2 - 0
lang/layout/fr-FR.js

@@ -1,5 +1,7 @@
 export default (context, locale) => {
   return ({
+    click_here: 'cliquez ici',
+    super_admin_switch_account: 'Vous utilisez une connexion SWITCH. Afin de retourner sur votre compte veuillez',
     insurance_cmf_subscription: 'Souscrire un contrat assurance CMF',
     renew_insurance_cmf: 'Accéder au renouvellement de votre assurance CMF',
     upload_cotisation_invoice: 'Télécharger la facture de votre appel de cotisation',

+ 6 - 4
services/rights/roleUtils.ts

@@ -115,10 +115,12 @@ class RoleUtils {
       if ((match = regex.exec(role)) !== null) {
         const subject = match[2]
         const action = match[3]
-        abilities.push({
-          action: actionMap[action],
-          subject: subject.toLowerCase()
-        })
+        if(subject && action){
+          abilities.push({
+            action: actionMap[action],
+            subject: subject.toLowerCase()
+          })
+        }
       }
     })
 

+ 15 - 4
store/profile/access.ts

@@ -1,6 +1,6 @@
 import * as _ from 'lodash'
 import { $roleUtils } from '~/services/rights/roleUtils'
-import {AbilitiesType, accessState, baseAccessState, baseOrganizationState, Historical} from '~/types/interfaces'
+import {AbilitiesType, accessState, baseAccessState, baseOrganizationState, Historical, OrignalAccessState} from '~/types/interfaces'
 import { GENDER } from '~/types/enums'
 import { MyProfile } from '~/models/Access/MyProfile'
 import { repositoryHelper } from '~/services/store/repository'
@@ -18,6 +18,7 @@ export const state = () => ({
   roles: [],
   abilities: [],
   isAdminAccess: false,
+  isSuperAdminAccess: false,
   isAdmin: false,
   isAdministratifManager: false,
   isPedagogicManager: false,
@@ -75,6 +76,9 @@ export const mutations = {
   setIsAdminAccess (state: accessState, isAdminAccess: boolean) {
     state.isAdminAccess = isAdminAccess
   },
+  setIsSuperAdminAccess (state: accessState, isSuperAdminAccess: boolean) {
+    state.isSuperAdminAccess = isSuperAdminAccess
+  },
   setIsAdmin (state: accessState, isRole: boolean) {
     state.isAdmin = isRole
   },
@@ -126,7 +130,7 @@ export const mutations = {
   addFamilyAccess (state: accessState, access: baseAccessState) {
     state.familyAccesses.push(access)
   },
-  setOriginalAccess (state: accessState, access: baseAccessState) {
+  setOriginalAccess (state: accessState, access: OrignalAccessState) {
     state.originalAccess = access
   }
 }
@@ -193,12 +197,19 @@ export const actions = {
   },
   setOriginalAccess (context: any, access: any) {
     if (access) {
-      const originalAccess:baseAccessState = {
+      const organization: baseOrganizationState = {
+        id: access.organization.id,
+        name: access.organization.name
+      }
+
+      const originalAccess:OrignalAccessState = {
         id: access.id,
         name: access.name,
         givenName: access.givenName,
         gender: access.gender,
-        avatarId: access.avatarId
+        isSuperAdminAccess: access.isSuperAdminAccess,
+        avatarId: access.avatarId,
+        organization: organization
       }
       context.commit('setOriginalAccess', originalAccess)
     }

+ 13 - 7
types/interfaces.d.ts

@@ -63,6 +63,14 @@ interface pageState {
   alerts: Array<alert>,
 }
 
+interface Historical {
+  future?: boolean,
+  past?: boolean,
+  present?: boolean,
+  dateStart?: string,
+  dateEnd?: string
+}
+
 interface baseAccessState {
   id: number,
   name: string,
@@ -71,12 +79,9 @@ interface baseAccessState {
   avatarId: number
 }
 
-interface Historical {
-  future?: boolean,
-  past?: boolean,
-  present?: boolean,
-  dateStart?: string,
-  dateEnd?: string
+interface OrignalAccessState extends baseAccessState {
+  isSuperAdminAccess: boolean,
+  organization: baseOrganizationState
 }
 
 interface accessState extends baseAccessState {
@@ -87,6 +92,7 @@ interface accessState extends baseAccessState {
   roles: Array<string>,
   abilities: Array<AbilitiesType>,
   isAdminAccess: boolean,
+  isSuperAdminAccess: boolean,
   isAdmin: boolean,
   isAdministratifManager: boolean,
   isPedagogicManager: boolean,
@@ -104,7 +110,7 @@ interface accessState extends baseAccessState {
   hasFamilyMenu: boolean,
   multiAccesses: Array<baseOrganizationState>,
   familyAccesses: Array<baseAccessState>,
-  originalAccess: baseAccessState
+  originalAccess: OrignalAccessState
 }
 
 interface AccessStore extends Store<{profile:{access: accessState}}> {}

+ 1 - 1
use/layout/Menus/myFamilyMenu.ts

@@ -39,7 +39,7 @@ class MyFamilyMenu extends BaseMenu implements Menu {
     // Si on est en compte swtich, on doit pouvoir retourner au compte d'origine
     if (this.$store.state.profile.access.originalAccess) {
       const originalAccess = this.$store.state.profile.access.originalAccess
-      const url = `/switch_user/${this.$store.state.profile.organization.id}/${originalAccess.id}/exit`
+      const url = `/switch_user/${originalAccess.organization.id}/${originalAccess.id}/exit`
       children.push(this.constructMenu(`${originalAccess.givenName} ${originalAccess.name}`, undefined, url, true))
     }