23 lines
693 B
JavaScript
23 lines
693 B
JavaScript
/** All known permission codes. */
|
|
export const PERMISSION_CODES = [
|
|
'S', 'R', 'M', 'W', 'C', 'K', 'D', 'N', 'V',
|
|
];
|
|
/** Test whether a permission string grants a specific code. */
|
|
export function hasPermission(perms, code) {
|
|
if (!perms) {
|
|
return false;
|
|
}
|
|
return perms.indexOf(code) !== -1;
|
|
}
|
|
/**
|
|
* Test whether a permission string grants a code, falling back to a default
|
|
* when the string is missing. Used by the UI to assume "full access" when the
|
|
* server doesn't return `oc:permissions` at all.
|
|
*/
|
|
export function hasPermissionOrDefault(perms, code, fallback) {
|
|
if (perms === null) {
|
|
return fallback;
|
|
}
|
|
return perms.indexOf(code) !== -1;
|
|
}
|