feat: implement multi-tenancy and super admin impersonation with security banner
This commit is contained in:
@@ -16,7 +16,7 @@ const props = defineProps({
|
||||
|
||||
const user = computed(() => usePage().props.auth.user);
|
||||
const canManage = computed(() => {
|
||||
return user.value.roles.some(r => r.name === props.task.service.name || r.name === 'Admin');
|
||||
return user.value.roles.some(r => r.name === props.task.service.name || r.name === 'Admin' || r.name === 'SuperAdmin');
|
||||
});
|
||||
|
||||
const progress = computed(() => {
|
||||
|
||||
@@ -13,6 +13,21 @@ const showingNavigationDropdown = ref(false);
|
||||
<template>
|
||||
<div>
|
||||
<div class="min-h-screen bg-gray-100 dark:bg-gray-900">
|
||||
<!-- Impersonation Banner -->
|
||||
<div v-if="$page.props.tenant.is_impersonating" class="bg-amber-500 text-white py-2 px-4 shadow-md">
|
||||
<div class="max-w-7xl mx-auto flex justify-between items-center text-sm font-bold">
|
||||
<div class="flex items-center space-x-2">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
<span>MODE SIMULATION ACTIF : Vous modifiez actuellement le locataire "{{ $page.props.tenant.current ? $page.props.tenant.current.name : 'VUE GLOBALE' }}"</span>
|
||||
</div>
|
||||
<Link :href="route('superadmin.reset')" method="post" as="button" class="bg-white text-amber-600 px-3 py-1 rounded-md hover:bg-amber-50 transition-colors">
|
||||
Arrêter la simulation
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<nav
|
||||
class="border-b border-gray-100 bg-white dark:border-gray-700 dark:bg-gray-800"
|
||||
>
|
||||
@@ -20,13 +35,16 @@ const showingNavigationDropdown = ref(false);
|
||||
<div class="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
|
||||
<div class="flex h-16 justify-between">
|
||||
<div class="flex">
|
||||
<!-- Logo -->
|
||||
<div class="flex shrink-0 items-center">
|
||||
<!-- Logo and Structure Name -->
|
||||
<div class="flex shrink-0 items-center space-x-3">
|
||||
<Link :href="route('dashboard')">
|
||||
<ApplicationLogo
|
||||
class="block h-9 w-auto"
|
||||
/>
|
||||
</Link>
|
||||
<span class="text-lg font-bold text-gray-800 dark:text-gray-200">
|
||||
{{ $page.props.tenant.current ? $page.props.tenant.current.name : ($page.props.auth.user.structure ? $page.props.auth.user.structure.name : '') }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- Navigation Links -->
|
||||
@@ -40,40 +58,48 @@ const showingNavigationDropdown = ref(false);
|
||||
Tableau de Bord
|
||||
</NavLink>
|
||||
<NavLink
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin')"
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin' || r.name === 'SuperAdmin')"
|
||||
:href="route('users.index')"
|
||||
:active="route().current('users.*')"
|
||||
>
|
||||
Utilisateurs
|
||||
</NavLink>
|
||||
<NavLink
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin')"
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin' || r.name === 'SuperAdmin')"
|
||||
:href="route('roles.index')"
|
||||
:active="route().current('roles.*')"
|
||||
>
|
||||
Rôles
|
||||
</NavLink>
|
||||
<NavLink
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin')"
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin' || r.name === 'SuperAdmin')"
|
||||
:href="route('permissions.index')"
|
||||
:active="route().current('permissions.*')"
|
||||
>
|
||||
Permissions
|
||||
</NavLink>
|
||||
<NavLink
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin')"
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin' || r.name === 'SuperAdmin')"
|
||||
:href="route('services.index')"
|
||||
:active="route().current('services.*')"
|
||||
>
|
||||
Services
|
||||
</NavLink>
|
||||
<NavLink
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin')"
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin' || r.name === 'SuperAdmin')"
|
||||
:href="route('templates.index')"
|
||||
:active="route().current('templates.*')"
|
||||
>
|
||||
Modèles
|
||||
</NavLink>
|
||||
<NavLink
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'SuperAdmin')"
|
||||
:href="route('superadmin.index')"
|
||||
:active="route().current('superadmin.*')"
|
||||
class="text-indigo-600 dark:text-indigo-400 font-bold"
|
||||
>
|
||||
🛠️ SaaS Admin
|
||||
</NavLink>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -182,40 +208,48 @@ const showingNavigationDropdown = ref(false);
|
||||
Tableau de Bord
|
||||
</ResponsiveNavLink>
|
||||
<ResponsiveNavLink
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin')"
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin' || r.name === 'SuperAdmin')"
|
||||
:href="route('users.index')"
|
||||
:active="route().current('users.*')"
|
||||
>
|
||||
Utilisateurs
|
||||
</ResponsiveNavLink>
|
||||
<ResponsiveNavLink
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin')"
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin' || r.name === 'SuperAdmin')"
|
||||
:href="route('roles.index')"
|
||||
:active="route().current('roles.*')"
|
||||
>
|
||||
Rôles
|
||||
</ResponsiveNavLink>
|
||||
<ResponsiveNavLink
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin')"
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin' || r.name === 'SuperAdmin')"
|
||||
:href="route('permissions.index')"
|
||||
:active="route().current('permissions.*')"
|
||||
>
|
||||
Permissions
|
||||
</ResponsiveNavLink>
|
||||
<ResponsiveNavLink
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin')"
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin' || r.name === 'SuperAdmin')"
|
||||
:href="route('services.index')"
|
||||
:active="route().current('services.*')"
|
||||
>
|
||||
Services
|
||||
</ResponsiveNavLink>
|
||||
<ResponsiveNavLink
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin')"
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'Admin' || r.name === 'SuperAdmin')"
|
||||
:href="route('templates.index')"
|
||||
:active="route().current('templates.*')"
|
||||
>
|
||||
Modèles
|
||||
</ResponsiveNavLink>
|
||||
<ResponsiveNavLink
|
||||
v-if="$page.props.auth.user.roles.some(r => r.name === 'SuperAdmin')"
|
||||
:href="route('superadmin.index')"
|
||||
:active="route().current('superadmin.*')"
|
||||
class="text-indigo-600 dark:text-indigo-400 font-bold"
|
||||
>
|
||||
🛠️ SaaS Admin
|
||||
</ResponsiveNavLink>
|
||||
</div>
|
||||
|
||||
<!-- Responsive Settings Options -->
|
||||
@@ -261,6 +295,18 @@ const showingNavigationDropdown = ref(false);
|
||||
|
||||
<!-- Page Content -->
|
||||
<main>
|
||||
<!-- Flash Messages -->
|
||||
<div v-if="$page.props.flash.success" class="max-w-7xl mx-auto mt-4 px-4 sm:px-6 lg:px-8">
|
||||
<div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative" role="alert">
|
||||
<span class="block sm:inline">{{ $page.props.flash.success }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="$page.props.flash.error" class="max-w-7xl mx-auto mt-4 px-4 sm:px-6 lg:px-8">
|
||||
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative" role="alert">
|
||||
<span class="block sm:inline">{{ $page.props.flash.error }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<slot />
|
||||
</main>
|
||||
</div>
|
||||
|
||||
@@ -7,6 +7,7 @@ import TextInput from '@/Components/TextInput.vue';
|
||||
import { Head, Link, useForm } from '@inertiajs/vue3';
|
||||
|
||||
const form = useForm({
|
||||
structure_name: '',
|
||||
name: '',
|
||||
email: '',
|
||||
password: '',
|
||||
@@ -26,7 +27,23 @@ const submit = () => {
|
||||
|
||||
<form @submit.prevent="submit">
|
||||
<div>
|
||||
<InputLabel for="name" value="Nom" />
|
||||
<InputLabel for="structure_name" value="Nom de votre Organisation (SaaS)" />
|
||||
|
||||
<TextInput
|
||||
id="structure_name"
|
||||
type="text"
|
||||
class="mt-1 block w-full"
|
||||
v-model="form.structure_name"
|
||||
required
|
||||
autofocus
|
||||
autocomplete="organization"
|
||||
/>
|
||||
|
||||
<InputError class="mt-2" :message="form.errors.structure_name" />
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<InputLabel for="name" value="Votre Nom complet" />
|
||||
|
||||
<TextInput
|
||||
id="name"
|
||||
@@ -34,7 +51,6 @@ const submit = () => {
|
||||
class="mt-1 block w-full"
|
||||
v-model="form.name"
|
||||
required
|
||||
autofocus
|
||||
autocomplete="name"
|
||||
/>
|
||||
|
||||
|
||||
86
resources/js/Pages/SuperAdmin/Create.vue
Normal file
86
resources/js/Pages/SuperAdmin/Create.vue
Normal file
@@ -0,0 +1,86 @@
|
||||
<script setup>
|
||||
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue';
|
||||
import InputError from '@/Components/InputError.vue';
|
||||
import InputLabel from '@/Components/InputLabel.vue';
|
||||
import PrimaryButton from '@/Components/PrimaryButton.vue';
|
||||
import TextInput from '@/Components/TextInput.vue';
|
||||
import { Head, useForm } from '@inertiajs/vue3';
|
||||
|
||||
const form = useForm({
|
||||
name: '',
|
||||
slug: '',
|
||||
domain: '',
|
||||
is_active: true,
|
||||
});
|
||||
|
||||
const submit = () => {
|
||||
form.post(route('superadmin.store'));
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Head title="Créer une Structure" />
|
||||
|
||||
<AuthenticatedLayout>
|
||||
<template #header>
|
||||
<h2 class="text-xl font-semibold leading-tight text-gray-800 dark:text-gray-200">
|
||||
Créer une nouvelle Structure (Tenant)
|
||||
</h2>
|
||||
</template>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="mx-auto max-w-7xl sm:px-6 lg:px-8">
|
||||
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6">
|
||||
<form @submit.prevent="submit" class="max-w-xl space-y-6">
|
||||
<div>
|
||||
<InputLabel for="name" value="Nom de l'organisation" />
|
||||
<TextInput
|
||||
id="name"
|
||||
type="text"
|
||||
class="mt-1 block w-full"
|
||||
v-model="form.name"
|
||||
required
|
||||
autofocus
|
||||
/>
|
||||
<InputError class="mt-2" :message="form.errors.name" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<InputLabel for="slug" value="Slug (Identifiant URL)" />
|
||||
<TextInput
|
||||
id="slug"
|
||||
type="text"
|
||||
class="mt-1 block w-full"
|
||||
v-model="form.slug"
|
||||
required
|
||||
/>
|
||||
<InputError class="mt-2" :message="form.errors.slug" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<InputLabel for="domain" value="Domaine personnalisé (Optionnel)" />
|
||||
<TextInput
|
||||
id="domain"
|
||||
type="text"
|
||||
class="mt-1 block w-full"
|
||||
v-model="form.domain"
|
||||
/>
|
||||
<InputError class="mt-2" :message="form.errors.domain" />
|
||||
</div>
|
||||
|
||||
<div class="flex items-center space-x-2">
|
||||
<input type="checkbox" id="is_active" v-model="form.is_active" class="rounded border-gray-300 text-indigo-600 shadow-sm focus:ring-indigo-500">
|
||||
<InputLabel for="is_active" value="Structure active" />
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-4">
|
||||
<PrimaryButton :disabled="form.processing">Créer</PrimaryButton>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AuthenticatedLayout>
|
||||
</template>
|
||||
89
resources/js/Pages/SuperAdmin/Edit.vue
Normal file
89
resources/js/Pages/SuperAdmin/Edit.vue
Normal file
@@ -0,0 +1,89 @@
|
||||
<script setup>
|
||||
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue';
|
||||
import InputError from '@/Components/InputError.vue';
|
||||
import InputLabel from '@/Components/InputLabel.vue';
|
||||
import PrimaryButton from '@/Components/PrimaryButton.vue';
|
||||
import TextInput from '@/Components/TextInput.vue';
|
||||
import { Head, useForm } from '@inertiajs/vue3';
|
||||
|
||||
const props = defineProps({
|
||||
structure: Object
|
||||
});
|
||||
|
||||
const form = useForm({
|
||||
name: props.structure.name,
|
||||
slug: props.structure.slug,
|
||||
domain: props.structure.domain,
|
||||
is_active: props.structure.is_active === 1 || props.structure.is_active === true,
|
||||
});
|
||||
|
||||
const submit = () => {
|
||||
form.put(route('superadmin.update', props.structure.id));
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Head title="Modifier la Structure" />
|
||||
|
||||
<AuthenticatedLayout>
|
||||
<template #header>
|
||||
<h2 class="text-xl font-semibold leading-tight text-gray-800 dark:text-gray-200">
|
||||
Modifier : {{ structure.name }}
|
||||
</h2>
|
||||
</template>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="mx-auto max-w-7xl sm:px-6 lg:px-8">
|
||||
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6">
|
||||
<form @submit.prevent="submit" class="max-w-xl space-y-6">
|
||||
<div>
|
||||
<InputLabel for="name" value="Nom de l'organisation" />
|
||||
<TextInput
|
||||
id="name"
|
||||
type="text"
|
||||
class="mt-1 block w-full"
|
||||
v-model="form.name"
|
||||
required
|
||||
/>
|
||||
<InputError class="mt-2" :message="form.errors.name" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<InputLabel for="slug" value="Slug (Identifiant URL)" />
|
||||
<TextInput
|
||||
id="slug"
|
||||
type="text"
|
||||
class="mt-1 block w-full"
|
||||
v-model="form.slug"
|
||||
required
|
||||
/>
|
||||
<InputError class="mt-2" :message="form.errors.slug" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<InputLabel for="domain" value="Domaine personnalisé (Optionnel)" />
|
||||
<TextInput
|
||||
id="domain"
|
||||
type="text"
|
||||
class="mt-1 block w-full"
|
||||
v-model="form.domain"
|
||||
/>
|
||||
<InputError class="mt-2" :message="form.errors.domain" />
|
||||
</div>
|
||||
|
||||
<div class="flex items-center space-x-2">
|
||||
<input type="checkbox" id="is_active" v-model="form.is_active" class="rounded border-gray-300 text-indigo-600 shadow-sm focus:ring-indigo-500">
|
||||
<InputLabel for="is_active" value="Structure active" />
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-4">
|
||||
<PrimaryButton :disabled="form.processing">Mettre à jour</PrimaryButton>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AuthenticatedLayout>
|
||||
</template>
|
||||
103
resources/js/Pages/SuperAdmin/Index.vue
Normal file
103
resources/js/Pages/SuperAdmin/Index.vue
Normal file
@@ -0,0 +1,103 @@
|
||||
<script setup>
|
||||
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue';
|
||||
import { Head, Link, router } from '@inertiajs/vue3';
|
||||
import { ref } from 'vue';
|
||||
|
||||
const props = defineProps({
|
||||
structures: Array,
|
||||
current_structure_id: Number
|
||||
});
|
||||
|
||||
const switchTo = (id) => {
|
||||
router.post(route('superadmin.switch', id));
|
||||
};
|
||||
|
||||
const resetSession = () => {
|
||||
router.post(route('superadmin.reset'));
|
||||
};
|
||||
|
||||
const deleteStructure = (id) => {
|
||||
if (confirm('Êtes-vous sûr de vouloir supprimer cette structure (Tenant) et toutes ses données associées ?')) {
|
||||
router.delete(route('superadmin.destroy', id));
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Head title="Super Administration SaaS" />
|
||||
|
||||
<AuthenticatedLayout>
|
||||
<template #header>
|
||||
<div class="flex justify-between items-center">
|
||||
<h2 class="text-xl font-semibold leading-tight text-gray-800 dark:text-gray-200">
|
||||
Super Administration SaaS
|
||||
</h2>
|
||||
<div class="flex space-x-4">
|
||||
<Link :href="route('superadmin.create')" class="px-4 py-2 bg-indigo-600 text-white rounded-md text-sm hover:bg-indigo-700">
|
||||
+ Créer une Structure
|
||||
</Link>
|
||||
<button v-if="current_structure_id" @click="resetSession" class="px-4 py-2 bg-red-600 text-white rounded-md text-sm hover:bg-red-700">
|
||||
Arrêter la simulation (Vue Globale)
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="mx-auto max-w-7xl sm:px-6 lg:px-8">
|
||||
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6 text-gray-900 dark:text-gray-100">
|
||||
<h3 class="text-lg font-medium mb-4">Gestion des Structures (Tenants)</h3>
|
||||
|
||||
<div class="overflow-x-auto">
|
||||
<table class="w-full text-left border-collapse">
|
||||
<thead>
|
||||
<tr class="border-b dark:border-gray-700 bg-gray-50 dark:bg-gray-700/50">
|
||||
<th class="px-6 py-3 text-xs font-bold uppercase text-gray-500">Nom</th>
|
||||
<th class="px-6 py-3 text-xs font-bold uppercase text-gray-500">Slug (URL)</th>
|
||||
<th class="px-6 py-3 text-xs font-bold uppercase text-gray-500">Utilisateurs</th>
|
||||
<th class="px-6 py-3 text-xs font-bold uppercase text-gray-500">Statut</th>
|
||||
<th class="px-6 py-3 text-xs font-bold uppercase text-gray-500">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="structure in structures" :key="structure.id" class="border-b dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-700/30">
|
||||
<td class="px-6 py-4 font-medium">{{ structure.name }}</td>
|
||||
<td class="px-6 py-4 text-sm text-gray-500">{{ structure.slug }}</td>
|
||||
<td class="px-6 py-4">{{ structure.users_count }}</td>
|
||||
<td class="px-6 py-4">
|
||||
<span v-if="structure.is_active" class="px-2 py-1 text-xs font-semibold text-green-800 bg-green-100 rounded-full">Actif</span>
|
||||
<span v-else class="px-2 py-1 text-xs font-semibold text-red-800 bg-red-100 rounded-full">Inactif</span>
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<div class="flex items-center space-x-3">
|
||||
<button
|
||||
v-if="current_structure_id !== structure.id"
|
||||
@click="switchTo(structure.id)"
|
||||
title="Simuler (Impersonate)"
|
||||
class="text-blue-600 hover:text-blue-900 text-sm font-medium">
|
||||
Gérer ce SaaS
|
||||
</button>
|
||||
<span v-else class="text-green-600 text-sm font-bold w-[100px]">✓ En cours</span>
|
||||
|
||||
<span class="text-gray-300">|</span>
|
||||
|
||||
<Link :href="route('superadmin.edit', structure.id)" class="text-indigo-600 hover:text-indigo-900">
|
||||
Modifier
|
||||
</Link>
|
||||
|
||||
<button @click="deleteStructure(structure.id)" class="text-red-600 hover:text-red-900">
|
||||
Supprimer
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AuthenticatedLayout>
|
||||
</template>
|
||||
Reference in New Issue
Block a user