我的应用程序中有一些选项卡,如报告、任务等......此外,用户具有不同的权限,如reports.add、tasks.delete。我需要创建函数来检查允许用户做什么。
// for example array with all current user permissions
// this permissions mean user is allowed to do everything with tasks
// add and edit reports, but not allowed to to delete it
const permissions = ['reports.add', 'reports.edit', 'tasks'];
const isAllowed = (condition) => {
return permissions.some((permission) => {
// here is problem, I can't create algorithm
});
};
// When user clicks delete report button
// I expect to use this function like this
if (isAllowed('reports.delete')) {
deleteReport()
}
蛊毒传说
慕慕森
相关分类