Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add feature and entity flagging into checkPermission #1187

Merged
merged 3 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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