Reworked authorization of conditions to use a single export by combing getRule and applyConditions into
createIsAuthorized Signed-off-by: Harry Hogg <hhogg@spotify.com> Co-authored-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
committed by
Vincenzo Scamporlino
parent
2b8ad06250
commit
2b124bc24a
@@ -126,7 +126,7 @@ export type MetadataResponse = {
|
||||
rules: MetadataResponseSerializedRule[];
|
||||
};
|
||||
|
||||
export const applyConditions = <TResourceType extends string, TResource>(
|
||||
const applyConditions = <TResourceType extends string, TResource>(
|
||||
criteria: PermissionCriteria<PermissionCondition<TResourceType>>,
|
||||
resource: TResource | undefined,
|
||||
getRule: (name: string) => PermissionRule<TResource, unknown, TResourceType>,
|
||||
@@ -160,6 +160,27 @@ export const applyConditions = <TResourceType extends string, TResource>(
|
||||
return rule.apply(resource, criteria.params ?? {});
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
* Takes some permission conditions and returns a definitive authorization result
|
||||
* on the resource to which they apply.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const createIsAuthorized = <
|
||||
TResourceType extends string,
|
||||
TResource,
|
||||
TQuery,
|
||||
>(
|
||||
rules: PermissionRule<TResource, TQuery, string>[],
|
||||
) => {
|
||||
const getRule = createGetRule(rules);
|
||||
return (
|
||||
criteria: PermissionCriteria<PermissionCondition<TResourceType>>,
|
||||
resource: TResource | undefined,
|
||||
) => applyConditions(criteria, resource, getRule);
|
||||
};
|
||||
|
||||
/**
|
||||
* Options for creating a permission integration router specific
|
||||
* for a particular resource type.
|
||||
|
||||
@@ -19,9 +19,4 @@ export * from './createConditionExports';
|
||||
export * from './createConditionTransformer';
|
||||
export * from './createPermissionIntegrationRouter';
|
||||
export * from './createPermissionRule';
|
||||
export {
|
||||
createGetRule,
|
||||
isAndCriteria,
|
||||
isOrCriteria,
|
||||
isNotCriteria,
|
||||
} from './util';
|
||||
export { isAndCriteria, isOrCriteria, isNotCriteria } from './util';
|
||||
|
||||
Reference in New Issue
Block a user