1
0
mirror of https://gitlab.com/bramw/baserow.git synced 2024-11-21 23:37:55 +00:00
bramw_baserow/enterprise/web-frontend/modules/baserow_enterprise/utils/roles.js

25 lines
805 B
JavaScript

/**
* Filters the role array by scope_type and subject_type.
*
* @param {Array} roles The role array to filter
* @param {object} filter An object that can contains a `scopeType` or a `subjectType`
* property which is used to filter the role list.
* @returns a filtered list of roles
*/
export const filterRoles = (roles, { scopeType, subjectType }) => {
return roles.filter(
({
allowed_scope_types: allowedScopeTypes,
allowed_subject_types: allowedSubjectTypes,
isVisible,
}) =>
isVisible &&
(scopeType === undefined ||
!Array.isArray(allowedScopeTypes) ||
allowedScopeTypes.includes(scopeType)) &&
(subjectType === undefined ||
!Array.isArray(allowedSubjectTypes) ||
allowedSubjectTypes.includes(subjectType))
)
}