diff --git a/404.html b/404.html index 6bb03883d..d22690759 100644 --- a/404.html +++ b/404.html @@ -5,7 +5,7 @@
More advanced case, allow to edit apartments only if user is owner of the apartment (defined as user_id), otherwise return error "You are not assigned to this apartment and can't edit it":
-import type { AdminUser, ActionCheckSource } from 'adminforth/types/AdminForthConfig.js';
async function canModifyAppart({ adminUser, source, meta }: { adminUser: AdminUser, meta: any, source: ActionCheckSource }): boolean {
if (source === ActionCheckSource.DisplayButtons) {
// if check is done for displaying button - we show button to everyone
return true;
}
if (adminUser.isRoot) {
return "Root user can't create appartment, relogin as DB user";
}
const { oldRecord, newRecord } = meta;
if (oldRecord.user_id !== adminUser.dbUser.id) {
return "You are not assigned to this apartment and can't edit it";
}
if (newRecord.user_id !== oldRecord.user_id) {
return "You can't change the owner of the apartment";
}
return true;
}
{
...
resourceId: 'apparts',
...
options: {
allowedActions: {
edit: canModifyAppart,
}
...
}
}
import type { AdminUser, ActionCheckSource } from 'adminforth/types/AdminForthConfig.js';
async function canModifyAppart({ adminUser, source, meta }: { adminUser: AdminUser, meta: any, source: ActionCheckSource }): boolean {
if (source === ActionCheckSource.DisplayButtons) {
// if check is done for displaying button - we show button to everyone
return true;
}
if (adminUser.isRoot) {
return false; //root user is not in db so can't be assigned
}
const { oldRecord, newRecord } = meta;
if (oldRecord.user_id !== adminUser.dbUser.id) {
return "You are not assigned to this apartment and can't edit it";
}
if (newRecord.user_id !== oldRecord.user_id) {
return "You can't change the owner of the apartment";
}
return true;
}
{
...
resourceId: 'apparts',
...
options: {
allowedActions: {
edit: canModifyAppart,
}
...
}
}