hasPermission role utility (#5554)
This commit is contained in:
parent
8cd127a223
commit
801c954673
1 changed files with 14 additions and 0 deletions
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;
|
||||
}
|
||||
Loading…
Reference in a new issue