Files
pgadmin4/web/pgadmin/browser/static/js/withCheckPermission.js
T

29 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2025, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
import pgAdmin from 'sources/pgadmin';
import current_user from 'pgadmin.user_management.current_user';
import gettext from 'sources/gettext';
export default function withCheckPermission(options, callback) {
// Check if the user has permission to access the menu item
return ()=>{
options = options ?? {};
// if the permission are not provided then no restrictions.
if(!options.permission || (options.permission && current_user.permissions?.includes(options.permission))) {
callback();
} else {
pgAdmin.Browser.notifier.alert(
gettext('Permission Denied'),
gettext('You dont have the necessary permissions to access this feature. Please contact your administrator for assistance')
);
}
};
}