fix: 🛂 update policies on model actions
This commit is contained in:
parent
8a772bfd9e
commit
6ef87cfb48
7 changed files with 24 additions and 15 deletions
|
|
@ -64,12 +64,12 @@ export default function ModelActions({
|
|||
const routeAction = route(`back.${modelRoute}.${action.value}`, model.id);
|
||||
|
||||
// All post actions mapping.
|
||||
const actionMap: Record<ViewsType[number]["value"], {
|
||||
const actionMap: Record<ViewsType[number]["label"], {
|
||||
method: typeof destroy | typeof patch;
|
||||
success: { title: string; description: string };
|
||||
error: { title: string; description: string };
|
||||
}> = {
|
||||
[Views.ARCHIVATION.value]: {
|
||||
[Views.ARCHIVATION.label]: {
|
||||
method: destroy,
|
||||
success: {
|
||||
title: "Archivation réussie !",
|
||||
|
|
@ -80,7 +80,7 @@ export default function ModelActions({
|
|||
description: "Un problème est survenu lors de l'archivation de cette entrée.",
|
||||
},
|
||||
},
|
||||
[Views.RESTORATION.value]: {
|
||||
[Views.RESTORATION.label]: {
|
||||
method: patch,
|
||||
success: {
|
||||
title: "Restoration réussie !",
|
||||
|
|
@ -91,7 +91,7 @@ export default function ModelActions({
|
|||
description: "Un problème est survenu lors de la restoration de cette entrée.",
|
||||
},
|
||||
},
|
||||
[Views.DELETION.value]: {
|
||||
[Views.DELETION.label || Views.FORCEDELETION.label]: {
|
||||
method: destroy,
|
||||
success: {
|
||||
title: "Suppression réussie !",
|
||||
|
|
@ -103,9 +103,9 @@ export default function ModelActions({
|
|||
},
|
||||
},
|
||||
};
|
||||
const config = actionMap[action.value];
|
||||
const config = actionMap[action.label];
|
||||
if (!config) {
|
||||
throw new Error(`Unknown action: ${action.value}`);
|
||||
throw new Error(`Unknown action: ${action.label}`);
|
||||
}
|
||||
|
||||
config.method(routeAction, {
|
||||
|
|
@ -126,6 +126,7 @@ export default function ModelActions({
|
|||
action.value === Views.ARCHIVATION.value
|
||||
|| action.value === Views.RESTORATION.value
|
||||
|| action.value === Views.DELETION.value
|
||||
|| action.value === Views.FORCEDELETION.value
|
||||
? inDialog && index != 0 ? (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
|
|
@ -144,8 +145,8 @@ export default function ModelActions({
|
|||
* @returns Element
|
||||
*/
|
||||
const PostAction = ({ action }: { action: ViewsType[number] }) => {
|
||||
const isRestoreAction = action.value === Views.RESTORATION.value;
|
||||
const isArchiveAction = action.value === Views.ARCHIVATION.value;
|
||||
const isRestoreAction = action.label === Views.RESTORATION.label;
|
||||
const isArchiveAction = action.label === Views.ARCHIVATION.label;
|
||||
const btnVariantType = isRestoreAction ? "ghost" : "destructive";
|
||||
const btnConfirm = useTrans(isRestoreAction ? "back.yes_restore" : "back.yes_delete");
|
||||
const btnDesc = useTrans(isRestoreAction ? "back.restore_data" : isArchiveAction ? "back.trash_data" : "back.lost_data");
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ export default function Dashboard({
|
|||
const isArchiveRoute = route().current("back.dynamic-pages.trash");
|
||||
const actionModels = isArchiveRoute ? [
|
||||
Views.RESTORATION,
|
||||
Views.DELETION,
|
||||
Views.FORCEDELETION,
|
||||
] : [
|
||||
Views.VISUALIZATION,
|
||||
Views.EDITION,
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ export default function Show({ data }: { data: SingleResource }) {
|
|||
auth: AuthProp;
|
||||
appEnv: AppEnv;
|
||||
};
|
||||
const { viewAny } = auth.policies.users;
|
||||
const { viewAny } = auth.policies.dynamicPages;
|
||||
const dynamicPageModel = data.data as DynamicPageModel;
|
||||
const enumDynamicPageStatus = usePage().props.enumDynamicPageStatus as LaravelEnum;
|
||||
const actionModels = [
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ export default function Dashboard({
|
|||
const isArchiveRoute = route().current("back.page-configs.trash");
|
||||
const actionModels = isArchiveRoute ? [
|
||||
Views.RESTORATION,
|
||||
Views.DELETION,
|
||||
Views.FORCEDELETION,
|
||||
] : [
|
||||
Views.VISUALIZATION,
|
||||
Views.EDITION,
|
||||
|
|
|
|||
|
|
@ -27,7 +27,11 @@ export default function Show({ data }: { data: SingleResource }) {
|
|||
};
|
||||
const { viewAny } = auth.policies.users;
|
||||
const userModel = data.data as UserModel;
|
||||
const actionModels = [Views.EDITION, Views.DUPLICATION, Views.DELETION];
|
||||
const actionModels = [
|
||||
Views.EDITION,
|
||||
Views.DUPLICATION,
|
||||
Views.DELETION,
|
||||
];
|
||||
const columns = [
|
||||
{
|
||||
accessorKey: "first_name",
|
||||
|
|
|
|||
|
|
@ -62,6 +62,12 @@ export const Views = {
|
|||
icon: ArchiveRestore,
|
||||
},
|
||||
DELETION: {
|
||||
label: "suppression",
|
||||
value: "destroy",
|
||||
policy: "delete",
|
||||
icon: Trash2,
|
||||
},
|
||||
FORCEDELETION: {
|
||||
label: "suppression",
|
||||
value: "forceDestroy",
|
||||
policy: "forceDelete",
|
||||
|
|
|
|||
|
|
@ -28,9 +28,7 @@ Route::prefix('admin')
|
|||
})->name('dashboard.index');
|
||||
|
||||
// * USERS.
|
||||
Route::delete('/users/{user}/force', [UserController::class, 'forceDestroy'])
|
||||
->name('users.forceDestroy');
|
||||
Route::resource('users', UserController::class)->except("destroy");
|
||||
Route::resource('users', UserController::class);
|
||||
Route::get('/users/{user}/duplicate', [UserController::class, 'duplicate'])->name('users.duplicate');
|
||||
|
||||
// * DYNAMIC PAGES.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue