first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { combineScopes } from './combine-scopes.ee';
|
||||
import type { Scope, ScopeLevels, ScopeOptions, MaskLevels } from '../types.ee';
|
||||
|
||||
/**
|
||||
* Checks if scopes exist in user's permissions.
|
||||
* @param scope - Scope(s) to check
|
||||
* @param userScopes - User's permission levels
|
||||
* @param masks - Optional scope filters
|
||||
* @param options - Checking mode (default: oneOf)
|
||||
*/
|
||||
export const hasScope = (
|
||||
scope: Scope | Scope[],
|
||||
userScopes: ScopeLevels,
|
||||
masks?: MaskLevels,
|
||||
options: ScopeOptions = { mode: 'oneOf' },
|
||||
): boolean => {
|
||||
if (!Array.isArray(scope)) scope = [scope];
|
||||
const userScopeSet = combineScopes(userScopes, masks);
|
||||
return options.mode === 'allOf'
|
||||
? !!scope.length && scope.every((s) => userScopeSet.has(s))
|
||||
: scope.some((s) => userScopeSet.has(s));
|
||||
};
|
||||
Reference in New Issue
Block a user