Skip to content

Commit

Permalink
feat: add feature and entity flagging into checkPermission (#1187)
Browse files Browse the repository at this point in the history
* feat: add feature and entity flagging into checkPermission

* fix: remove unused alpha prop - was replaces bu availability in prev breaking change

* refactor: return to _entity in check functions which dont use the param
  • Loading branch information
dbouwman authored Aug 25, 2023
1 parent 7ed63d9 commit b040283
Show file tree
Hide file tree
Showing 15 changed files with 474 additions and 240 deletions.
4 changes: 2 additions & 2 deletions packages/common/src/ArcGISContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export interface IArcGISContext {
/**
* Hash of feature flags
*/
featureFlags?: IFeatureFlags;
featureFlags: IFeatureFlags;
}

/**
Expand Down Expand Up @@ -279,7 +279,7 @@ export class ArcGISContext implements IArcGISContext {

private _serviceStatus: HubServiceStatus;

private _featureFlags: IFeatureFlags;
private _featureFlags: IFeatureFlags = {};

/**
* Create a new instance of `ArcGISContext`.
Expand Down
3 changes: 1 addition & 2 deletions packages/common/src/ArcGISContextManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class ArcGISContextManager {

private _serviceStatus: HubServiceStatus;

private _featureFlags: IFeatureFlags;
private _featureFlags: IFeatureFlags = {};

/**
* Private constructor. Use `ArcGISContextManager.create(...)` to
Expand Down Expand Up @@ -373,7 +373,6 @@ export class ArcGISContextManager {
contextOpts.currentUser = this._currentUser;
}

// TODO: Decide if featureFlags should be passed forward
return contextOpts;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { IArcGISContext } from "../../ArcGISContext";
import { IPermissionPolicy } from "../types/IPermissionPolicy";
import { IPolicyCheck } from "../types/IPolicyCheck";

/**
* Type signature for Permission Check Functions
*/
export type PermissionCheckFunction = (
policy: IPermissionPolicy,
context: IArcGISContext,
entity?: Record<string, any>
) => IPolicyCheck[];
40 changes: 0 additions & 40 deletions packages/common/src/permissions/_internal/checkAlphaGating.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getPolicyResponseCode } from "./getPolicyResponseCode";
export function checkAuthentication(
policy: IPermissionPolicy,
context: IArcGISContext,
entity?: Record<string, any>
_entity?: Record<string, any>
): IPolicyCheck[] {
const checks = [] as IPolicyCheck[];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { IArcGISContext } from "../../ArcGISContext";
import { getWithDefault } from "../../objects/get-with-default";
import { IFeatureFlags, IPermissionPolicy } from "../types/IPermissionPolicy";
import { IPermissionPolicy } from "../types/IPermissionPolicy";
import { IPolicyCheck } from "../types/IPolicyCheck";
import { PolicyResponse } from "../types/PolicyResponse";
import { getPolicyResponseCode } from "./getPolicyResponseCode";

// NOTE: Entity Feature Flagging is handled in checkPermission directly
// as it needs to interact with the feature flagging, and depending on
// the outcome, possibly omit some of the checks
export function checkEntityFeature(
policy: IPermissionPolicy,
_entitycontext: IArcGISContext,
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/permissions/_internal/checkLicense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getPolicyResponseCode } from "./getPolicyResponseCode";
export function checkLicense(
policy: IPermissionPolicy,
context: IArcGISContext,
entity?: Record<string, any>
_entity?: Record<string, any>
): IPolicyCheck[] {
const checks = [] as IPolicyCheck[];
// Only return a check if the policy is defined
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/permissions/_internal/checkPrivileges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { getPolicyResponseCode } from "./getPolicyResponseCode";
* Validate privilege policy
* @param policy
* @param context
* @param entity
* @param _entity
* @returns
*/
export function checkPrivileges(
policy: IPermissionPolicy,
context: IArcGISContext,
entity?: Record<string, any>
_entity?: Record<string, any>
): IPolicyCheck[] {
let checks = [] as IPolicyCheck[];
// Only return a check if the policy is defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const policyResponseCodes: IPolicyLookup[] = [
{ response: "not-in-environment", code: "PC134" },
{ response: "feature-disabled", code: "PC135" },
{ response: "feature-enabled", code: "PC136" },
{ response: "no-policy-exists", code: "PC137" },
{ response: "disabled-by-entity-flag", code: "PC137" },
{ response: "disabled-by-feature-flag", code: "PC137" },
];

/**
Expand Down
Loading

0 comments on commit b040283

Please sign in to comment.