forked from Ivasoft/mattermost-mobile
hasPermission role utility (#5554)
This commit is contained in:
14
app/utils/role/index.ts
Normal file
14
app/utils/role/index.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import type RoleModel from '@typings/database/models/servers/role';
|
||||
|
||||
export function hasPermission(roles: RoleModel[] | Role[], permission: string, defaultValue: boolean) {
|
||||
const permissions = new Set<string>();
|
||||
for (const role of roles) {
|
||||
role.permissions.forEach(permissions.add, permissions);
|
||||
}
|
||||
|
||||
const exists = permissions.has(permission);
|
||||
return defaultValue === true || exists;
|
||||
}
|
||||
Reference in New Issue
Block a user