Refactor Administration entrypoint
We moved the administration item to the company switcher in the header
This commit is contained in:
48
app/Http/Controllers/Admin/AdminDashboardController.php
Normal file
48
app/Http/Controllers/Admin/AdminDashboardController.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class AdminDashboardController extends Controller
|
||||
{
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$version = preg_replace('~[\r\n]+~', '', File::get(base_path('version.md')));
|
||||
|
||||
$dbDriver = config('database.default');
|
||||
$dbVersion = $this->getDatabaseVersion($dbDriver);
|
||||
|
||||
return response()->json([
|
||||
'app_version' => $version,
|
||||
'php_version' => phpversion(),
|
||||
'database' => [
|
||||
'driver' => $dbDriver,
|
||||
'version' => $dbVersion,
|
||||
],
|
||||
'counts' => [
|
||||
'companies' => Company::count(),
|
||||
'users' => User::count(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
private function getDatabaseVersion(string $driver): ?string
|
||||
{
|
||||
try {
|
||||
return match ($driver) {
|
||||
'mysql' => DB::selectOne('SELECT VERSION() as version')?->version,
|
||||
'pgsql' => DB::selectOne('SHOW server_version')?->server_version,
|
||||
'sqlite' => DB::selectOne('SELECT sqlite_version() as version')?->version,
|
||||
default => null,
|
||||
};
|
||||
} catch (\Throwable) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,16 +49,28 @@ class BootstrapController extends Controller
|
||||
'save_pdf_to_disk',
|
||||
]);
|
||||
|
||||
// Super admin mode — return admin-only menu with all companies listed
|
||||
if ($current_user->isSuperAdmin() && $request->has('admin_mode')) {
|
||||
return response()->json([
|
||||
'current_user' => new UserResource($current_user),
|
||||
'current_user_settings' => $current_user_settings,
|
||||
'current_user_abilities' => [],
|
||||
'companies' => CompanyResource::collection($companies),
|
||||
'current_company' => null,
|
||||
'current_company_settings' => [],
|
||||
'current_company_currency' => Currency::first(),
|
||||
'config' => config('invoiceshelf'),
|
||||
'global_settings' => $global_settings,
|
||||
'main_menu' => $this->generateMenu('admin_menu', $current_user),
|
||||
'setting_menu' => [],
|
||||
'modules' => [],
|
||||
'admin_mode' => true,
|
||||
'pending_invitations' => CompanyInvitationResource::collection($pendingInvitations),
|
||||
]);
|
||||
}
|
||||
|
||||
// User has no companies — return minimal bootstrap
|
||||
if ($companies->isEmpty()) {
|
||||
$main_menu = $current_user->isSuperAdmin()
|
||||
? $this->generateMenu('main_menu', $current_user)
|
||||
: [];
|
||||
|
||||
$setting_menu = $current_user->isSuperAdmin()
|
||||
? $this->generateMenu('setting_menu', $current_user)
|
||||
: [];
|
||||
|
||||
return response()->json([
|
||||
'current_user' => new UserResource($current_user),
|
||||
'current_user_settings' => $current_user_settings,
|
||||
@@ -69,8 +81,8 @@ class BootstrapController extends Controller
|
||||
'current_company_currency' => Currency::first(),
|
||||
'config' => config('invoiceshelf'),
|
||||
'global_settings' => $global_settings,
|
||||
'main_menu' => $main_menu,
|
||||
'setting_menu' => $setting_menu,
|
||||
'main_menu' => [],
|
||||
'setting_menu' => [],
|
||||
'modules' => [],
|
||||
'pending_invitations' => CompanyInvitationResource::collection($pendingInvitations),
|
||||
]);
|
||||
|
||||
@@ -21,11 +21,15 @@ class CompanyMiddleware
|
||||
$firstCompany = $user->companies()->first();
|
||||
|
||||
// User has no companies — allow request through without company header
|
||||
// (BootstrapController handles this gracefully)
|
||||
if (! $firstCompany) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
// Super admin without company header — allow pass-through (admin mode)
|
||||
if ($user->isSuperAdmin() && ! $request->header('company')) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if (! $request->header('company') || ! $user->hasCompany($request->header('company'))) {
|
||||
$request->headers->set('company', $firstCompany->id);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class SettingsPolicy
|
||||
|
||||
public function manageBackups(User $user)
|
||||
{
|
||||
if ($user->isOwner()) {
|
||||
if ($user->isSuperAdmin()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class SettingsPolicy
|
||||
|
||||
public function manageFileDisk(User $user)
|
||||
{
|
||||
if ($user->isOwner()) {
|
||||
if ($user->isSuperAdmin()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class SettingsPolicy
|
||||
|
||||
public function manageEmailConfig(User $user)
|
||||
{
|
||||
if ($user->isOwner()) {
|
||||
if ($user->isSuperAdmin()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class SettingsPolicy
|
||||
|
||||
public function managePDFConfig(User $user)
|
||||
{
|
||||
if ($user->isOwner()) {
|
||||
if ($user->isSuperAdmin()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class SettingsPolicy
|
||||
|
||||
public function manageSettings(User $user)
|
||||
{
|
||||
if ($user->isOwner()) {
|
||||
if ($user->isSuperAdmin()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,13 @@ class AppServiceProvider extends ServiceProvider
|
||||
}
|
||||
});
|
||||
|
||||
// admin menu (super admin mode)
|
||||
\Menu::make('admin_menu', function ($menu) {
|
||||
foreach (config('invoiceshelf.admin_menu') as $data) {
|
||||
$this->generateMenu($menu, $data);
|
||||
}
|
||||
});
|
||||
|
||||
// setting menu
|
||||
\Menu::make('setting_menu', function ($menu) {
|
||||
foreach (config('invoiceshelf.setting_menu') as $data) {
|
||||
|
||||
@@ -381,10 +381,26 @@ return [
|
||||
'ability' => '',
|
||||
'model' => '',
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
* List of admin mode menu (super admin only)
|
||||
*/
|
||||
'admin_menu' => [
|
||||
[
|
||||
'title' => 'navigation.dashboard',
|
||||
'group' => 1,
|
||||
'link' => '/admin/administration/dashboard',
|
||||
'icon' => 'ServerIcon',
|
||||
'name' => 'AdminDashboard',
|
||||
'owner_only' => false,
|
||||
'super_admin_only' => true,
|
||||
'ability' => '',
|
||||
'model' => '',
|
||||
],
|
||||
[
|
||||
'title' => 'navigation.companies',
|
||||
'group' => 4,
|
||||
'group_label' => 'navigation.administration',
|
||||
'group' => 1,
|
||||
'link' => '/admin/administration/companies',
|
||||
'icon' => 'BuildingOfficeIcon',
|
||||
'name' => 'AdminCompanies',
|
||||
@@ -395,7 +411,7 @@ return [
|
||||
],
|
||||
[
|
||||
'title' => 'navigation.all_users',
|
||||
'group' => 4,
|
||||
'group' => 1,
|
||||
'link' => '/admin/administration/users',
|
||||
'icon' => 'UsersIcon',
|
||||
'name' => 'AdminUsers',
|
||||
@@ -406,7 +422,7 @@ return [
|
||||
],
|
||||
[
|
||||
'title' => 'navigation.settings',
|
||||
'group' => 4,
|
||||
'group' => 1,
|
||||
'link' => '/admin/administration/settings/mail-configuration',
|
||||
'icon' => 'CogIcon',
|
||||
'name' => 'AdminSettings',
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
"decline": "Decline",
|
||||
"welcome": "Welcome",
|
||||
"no_company_description": "You are not a member of any company yet. Accept an invitation below or contact your administrator.",
|
||||
"app_version": "Application Version",
|
||||
"database": "Database",
|
||||
"update": "Update",
|
||||
"deselect": "Deselect",
|
||||
"download": "Download",
|
||||
|
||||
8
resources/scripts/admin/admin-router.js
vendored
8
resources/scripts/admin/admin-router.js
vendored
@@ -114,6 +114,8 @@ const InvoicePublicPage = () =>
|
||||
import('@/scripts/components/InvoicePublicPage.vue')
|
||||
|
||||
// Administration (Super Admin)
|
||||
const AdminDashboard = () =>
|
||||
import('@/scripts/admin/views/administration/AdminDashboard.vue')
|
||||
const AdminCompaniesIndex = () =>
|
||||
import('@/scripts/admin/views/administration/companies/Index.vue')
|
||||
const AdminCompaniesEdit = () =>
|
||||
@@ -515,6 +517,12 @@ export default [
|
||||
},
|
||||
|
||||
// Administration (Super Admin)
|
||||
{
|
||||
path: 'administration/dashboard',
|
||||
name: 'admin.dashboard',
|
||||
meta: { isSuperAdmin: true },
|
||||
component: AdminDashboard,
|
||||
},
|
||||
{
|
||||
path: 'administration/companies',
|
||||
name: 'admin.companies.index',
|
||||
|
||||
@@ -55,12 +55,16 @@ const isAppLoaded = computed(() => {
|
||||
})
|
||||
|
||||
const hasCompany = computed(() => {
|
||||
return !!companyStore.selectedCompany || !!userStore.currentUser?.is_super_admin
|
||||
return !!companyStore.selectedCompany || companyStore.isAdminMode
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
globalStore.bootstrap().then((res) => {
|
||||
if (!res.data.current_company && !res.data.current_user.is_super_admin) {
|
||||
if (companyStore.isAdminMode) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!res.data.current_company) {
|
||||
if (route.name !== 'no.company') {
|
||||
router.push({ name: 'no.company' })
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
"
|
||||
>
|
||||
<router-link
|
||||
to="/admin/dashboard"
|
||||
:to="companyStore.isAdminMode ? '/admin/administration/dashboard' : '/admin/dashboard'"
|
||||
class="
|
||||
float-none
|
||||
text-lg
|
||||
@@ -61,7 +61,7 @@
|
||||
|
||||
<ul class="flex float-right h-8 m-0 list-none md:h-9">
|
||||
<li
|
||||
v-if="hasCreateAbilities()"
|
||||
v-if="hasCreateAbilities() && !companyStore.isAdminMode"
|
||||
class="relative hidden float-left m-0 md:block"
|
||||
>
|
||||
<BaseDropdown width-class="w-48">
|
||||
@@ -124,7 +124,7 @@
|
||||
</BaseDropdown>
|
||||
</li>
|
||||
|
||||
<li class="ml-2">
|
||||
<li v-if="!companyStore.isAdminMode" class="ml-2">
|
||||
<GlobalSearchBar
|
||||
v-if="
|
||||
userStore.currentUser.is_owner ||
|
||||
@@ -179,6 +179,7 @@ import { computed } from 'vue'
|
||||
import { useUserStore } from '@/scripts/admin/stores/user'
|
||||
import { useGlobalStore } from '@/scripts/admin/stores/global'
|
||||
|
||||
import { useCompanyStore } from '@/scripts/admin/stores/company'
|
||||
import CompanySwitcher from '@/scripts/components/CompanySwitcher.vue'
|
||||
import GlobalSearchBar from '@/scripts/components/GlobalSearchBar.vue'
|
||||
import MainLogo from '@/scripts/components/icons/MainLogo.vue'
|
||||
@@ -188,6 +189,7 @@ import abilities from '@/scripts/admin/stub/abilities'
|
||||
const authStore = useAuthStore()
|
||||
const userStore = useUserStore()
|
||||
const globalStore = useGlobalStore()
|
||||
const companyStore = useCompanyStore()
|
||||
const router = useRouter()
|
||||
|
||||
const previewAvatar = computed(() => {
|
||||
|
||||
14
resources/scripts/admin/stores/company.js
vendored
14
resources/scripts/admin/stores/company.js
vendored
@@ -14,18 +14,32 @@ export const useCompanyStore = (useWindow = false) => {
|
||||
selectedCompany: null,
|
||||
selectedCompanySettings: {},
|
||||
selectedCompanyCurrency: null,
|
||||
isAdminMode: window.Ls?.get('isAdminMode') === 'true',
|
||||
}),
|
||||
|
||||
actions: {
|
||||
setSelectedCompany(data) {
|
||||
if (data) {
|
||||
window.Ls.set('selectedCompany', data.id)
|
||||
window.Ls.remove('isAdminMode')
|
||||
this.isAdminMode = false
|
||||
} else {
|
||||
window.Ls.remove('selectedCompany')
|
||||
}
|
||||
this.selectedCompany = data
|
||||
},
|
||||
|
||||
setAdminMode(enabled) {
|
||||
this.isAdminMode = enabled
|
||||
if (enabled) {
|
||||
window.Ls.set('isAdminMode', 'true')
|
||||
window.Ls.remove('selectedCompany')
|
||||
this.selectedCompany = null
|
||||
} else {
|
||||
window.Ls.remove('isAdminMode')
|
||||
}
|
||||
},
|
||||
|
||||
fetchBasicMailConfig() {
|
||||
return new Promise((resolve, reject) => {
|
||||
http
|
||||
|
||||
8
resources/scripts/admin/stores/global.js
vendored
8
resources/scripts/admin/stores/global.js
vendored
@@ -47,10 +47,14 @@ export const useGlobalStore = (useWindow = false) => {
|
||||
actions: {
|
||||
bootstrap() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const companyStore = useCompanyStore()
|
||||
const url = companyStore.isAdminMode
|
||||
? '/api/v1/bootstrap?admin_mode=1'
|
||||
: '/api/v1/bootstrap'
|
||||
|
||||
http
|
||||
.get('/api/v1/bootstrap')
|
||||
.get(url)
|
||||
.then(async (response) => {
|
||||
const companyStore = useCompanyStore()
|
||||
const userStore = useUserStore()
|
||||
const moduleStore = useModuleStore()
|
||||
|
||||
|
||||
104
resources/scripts/admin/views/administration/AdminDashboard.vue
Normal file
104
resources/scripts/admin/views/administration/AdminDashboard.vue
Normal file
@@ -0,0 +1,104 @@
|
||||
<template>
|
||||
<BasePage>
|
||||
<BasePageHeader :title="$t('navigation.dashboard')">
|
||||
<BaseBreadcrumb>
|
||||
<BaseBreadcrumbItem
|
||||
:title="$t('navigation.administration')"
|
||||
to="/admin/administration/dashboard"
|
||||
active
|
||||
/>
|
||||
</BaseBreadcrumb>
|
||||
</BasePageHeader>
|
||||
|
||||
<div v-if="isLoading" class="flex justify-center py-16">
|
||||
<BaseGlobalLoader />
|
||||
</div>
|
||||
|
||||
<div v-else class="grid grid-cols-1 gap-6 mt-6 md:grid-cols-2 lg:grid-cols-3">
|
||||
<!-- App Version -->
|
||||
<BaseCard>
|
||||
<template #header>
|
||||
<div class="flex items-center">
|
||||
<BaseIcon name="ServerIcon" class="w-5 h-5 mr-2 text-gray-400" />
|
||||
<span class="font-medium text-gray-700">{{ $t('general.app_version') }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<p class="text-2xl font-semibold text-gray-900">
|
||||
{{ data.app_version }}
|
||||
</p>
|
||||
</BaseCard>
|
||||
|
||||
<!-- PHP Version -->
|
||||
<BaseCard>
|
||||
<template #header>
|
||||
<div class="flex items-center">
|
||||
<BaseIcon name="CodeBracketIcon" class="w-5 h-5 mr-2 text-gray-400" />
|
||||
<span class="font-medium text-gray-700">PHP</span>
|
||||
</div>
|
||||
</template>
|
||||
<p class="text-2xl font-semibold text-gray-900">
|
||||
{{ data.php_version }}
|
||||
</p>
|
||||
</BaseCard>
|
||||
|
||||
<!-- Database -->
|
||||
<BaseCard>
|
||||
<template #header>
|
||||
<div class="flex items-center">
|
||||
<BaseIcon name="CircleStackIcon" class="w-5 h-5 mr-2 text-gray-400" />
|
||||
<span class="font-medium text-gray-700">{{ $t('general.database') }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<p class="text-2xl font-semibold text-gray-900">
|
||||
{{ data.database?.driver?.toUpperCase() }}
|
||||
</p>
|
||||
<p class="text-sm text-gray-500 mt-1">
|
||||
{{ data.database?.version }}
|
||||
</p>
|
||||
</BaseCard>
|
||||
|
||||
<!-- Companies -->
|
||||
<BaseCard>
|
||||
<template #header>
|
||||
<div class="flex items-center">
|
||||
<BaseIcon name="BuildingOfficeIcon" class="w-5 h-5 mr-2 text-gray-400" />
|
||||
<span class="font-medium text-gray-700">{{ $t('navigation.companies') }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<p class="text-2xl font-semibold text-gray-900">
|
||||
{{ data.counts?.companies }}
|
||||
</p>
|
||||
</BaseCard>
|
||||
|
||||
<!-- Users -->
|
||||
<BaseCard>
|
||||
<template #header>
|
||||
<div class="flex items-center">
|
||||
<BaseIcon name="UsersIcon" class="w-5 h-5 mr-2 text-gray-400" />
|
||||
<span class="font-medium text-gray-700">{{ $t('navigation.all_users') }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<p class="text-2xl font-semibold text-gray-900">
|
||||
{{ data.counts?.users }}
|
||||
</p>
|
||||
</BaseCard>
|
||||
</div>
|
||||
</BasePage>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import http from '@/scripts/http'
|
||||
|
||||
const isLoading = ref(true)
|
||||
const data = ref({})
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const response = await http.get('/api/v1/super-admin/dashboard')
|
||||
data.value = response.data
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
})
|
||||
</script>
|
||||
@@ -19,7 +19,13 @@
|
||||
@click="isShow = !isShow"
|
||||
>
|
||||
<span
|
||||
v-if="companyStore.selectedCompany"
|
||||
v-if="companyStore.isAdminMode"
|
||||
class="w-16 text-sm font-medium truncate sm:w-auto"
|
||||
>
|
||||
{{ $t('navigation.administration') }}
|
||||
</span>
|
||||
<span
|
||||
v-else-if="companyStore.selectedCompany"
|
||||
class="w-16 text-sm font-medium truncate sm:w-auto"
|
||||
>
|
||||
{{ companyStore.selectedCompany.name }}
|
||||
@@ -49,6 +55,29 @@
|
||||
pb-4
|
||||
"
|
||||
>
|
||||
<!-- Administration Mode -->
|
||||
<div v-if="userStore.currentUser?.is_super_admin">
|
||||
<div
|
||||
class="p-2 px-3 rounded-md cursor-pointer hover:bg-gray-100 hover:text-primary-500"
|
||||
:class="{
|
||||
'bg-gray-100 text-primary-500': companyStore.isAdminMode,
|
||||
}"
|
||||
@click="enterAdminMode"
|
||||
>
|
||||
<div class="flex items-center">
|
||||
<span
|
||||
class="flex items-center justify-center mr-3 overflow-hidden text-base font-semibold bg-primary-100 rounded-md w-9 h-9 shrink-0 text-primary-500"
|
||||
>
|
||||
<BaseIcon name="ShieldCheckIcon" class="w-5 h-5" />
|
||||
</span>
|
||||
<div class="flex flex-col">
|
||||
<span class="text-sm font-medium">{{ $t('navigation.administration') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="border-t border-gray-100 my-1"></div>
|
||||
</div>
|
||||
|
||||
<label
|
||||
class="
|
||||
px-3
|
||||
@@ -259,7 +288,16 @@ function addNewCompany() {
|
||||
})
|
||||
}
|
||||
|
||||
async function enterAdminMode() {
|
||||
companyStore.setAdminMode(true)
|
||||
isShow.value = false
|
||||
router.push('/admin/administration/dashboard')
|
||||
await globalStore.setIsAppLoaded(false)
|
||||
await globalStore.bootstrap()
|
||||
}
|
||||
|
||||
async function changeCompany(company) {
|
||||
companyStore.setAdminMode(false)
|
||||
await companyStore.setSelectedCompany(company)
|
||||
router.push('/admin/dashboard')
|
||||
await globalStore.setIsAppLoaded(false)
|
||||
|
||||
2
resources/scripts/http/index.js
vendored
2
resources/scripts/http/index.js
vendored
@@ -20,7 +20,7 @@ instance.interceptors.request.use(function (config) {
|
||||
config.headers.Authorization = authToken
|
||||
}
|
||||
|
||||
if (companyId) {
|
||||
if (companyId && Ls.get('isAdminMode') !== 'true') {
|
||||
config.headers.company = companyId
|
||||
}
|
||||
|
||||
|
||||
2
resources/scripts/router/index.js
vendored
2
resources/scripts/router/index.js
vendored
@@ -26,7 +26,7 @@ router.beforeEach((to) => {
|
||||
const { isAppLoaded } = globalStore
|
||||
|
||||
if (isAppLoaded && to.meta.requiresAuth && to.name !== 'no.company') {
|
||||
if (!companyStore.selectedCompany && !(to.meta.isSuperAdmin && userStore.currentUser?.is_super_admin)) {
|
||||
if (!companyStore.selectedCompany && !companyStore.isAdminMode && !(to.meta.isSuperAdmin && userStore.currentUser?.is_super_admin)) {
|
||||
return { name: 'no.company' }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\Admin\AdminDashboardController;
|
||||
use App\Http\Controllers\Admin\BackupsController;
|
||||
use App\Http\Controllers\Admin\CompaniesController;
|
||||
use App\Http\Controllers\Admin\CountriesController;
|
||||
@@ -158,6 +159,7 @@ Route::prefix('/v1')->group(function () {
|
||||
// ----------------------------------
|
||||
|
||||
Route::middleware(['auth:sanctum', 'super-admin'])->prefix('super-admin')->group(function () {
|
||||
Route::get('dashboard', [AdminDashboardController::class, 'index']);
|
||||
Route::get('companies', [CompaniesController::class, 'index']);
|
||||
Route::get('companies/{company}', [CompaniesController::class, 'show']);
|
||||
Route::put('companies/{company}', [CompaniesController::class, 'update']);
|
||||
|
||||
Reference in New Issue
Block a user