Skip to content

Commit

Permalink
feat: remove capabilities, add featureFlags to Context (#1184)
Browse files Browse the repository at this point in the history
* fix: remove subsystems in favor of services

BREAKING CHANGE: HubSubsystem, HubSystemStatus, isSubsystem removed

* fix: remove capabilities

BREAKING CHANGE: Remove all capability related functions, props, fix tests

* feat: context holds feature flags

* refactor: ensure .features persisted for S/I/P only

* refactor: update version test to account for settings.features being included

* fix: remove IEntityFeature type

BREAKING CHANGE: IEntityFeature type replaced with IFeatureFlag
  • Loading branch information
dbouwman authored Aug 23, 2023
1 parent 19ea058 commit 394c60c
Show file tree
Hide file tree
Showing 59 changed files with 417 additions and 1,599 deletions.
13 changes: 0 additions & 13 deletions packages/common/e2e/permissions.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,5 @@ describe("Check Permissions", () => {
const results = checkPermission("hub:site:edit", context, entity);
expect(results.access).toBe(true);
});
it("default capabilities applied on load", async () => {
const entity: HubEntity = await fetchHubEntity(
"initiative",
TEST_INITIATIVE_ID,
context
);

const instance = HubInitiative.fromJson(
entity as IHubInitiative,
context
);
const chk = instance.checkCapability("details");
});
});
});
51 changes: 24 additions & 27 deletions packages/common/src/ArcGISContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
} from "@esri/arcgis-rest-auth";
import { IPortal } from "@esri/arcgis-rest-portal";
import { IRequestOptions } from "@esri/arcgis-rest-request";
import { HubServiceStatus, HubSystemStatus } from "./core";
import { HubServiceStatus } from "./core";
import { getProp, getWithDefault } from "./objects";
import { HubEnvironment, HubLicense } from "./permissions/types";
import { HubEnvironment, HubLicense, IFeatureFlags } from "./permissions/types";
import { IHubRequestOptions } from "./types";
import { getEnvironmentFromPortalUrl } from "./utils/getEnvironmentFromPortalUrl";

Expand Down Expand Up @@ -160,10 +160,6 @@ export interface IArcGISContext {
* Additional app-specific context
*/
properties: Record<string, any>;
/**
* DEPRECATED: System status
*/
systemStatus: HubSystemStatus;

/**
* Hub Service Status
Expand All @@ -185,6 +181,11 @@ export interface IArcGISContext {
* What environment is this running in?
*/
environment: HubEnvironment;

/**
* Hash of feature flags
*/
featureFlags?: IFeatureFlags;
}

/**
Expand Down Expand Up @@ -231,16 +232,16 @@ export interface IArcGISContextOptions {
* Optional hash of additional context
*/
properties?: Record<string, any>;
/**
* DEPRECATED: Option to pass in system status vs fetching it
* TODO: Remove with Capabilities
*/
systemStatus?: HubSystemStatus;

/**
* Option to pass in service status vs fetching it
*/
serviceStatus?: HubServiceStatus;

/**
* Hash of feature flags
*/
featureFlags?: IFeatureFlags;
}

/**
Expand Down Expand Up @@ -276,11 +277,10 @@ export class ArcGISContext implements IArcGISContext {

private _properties: Record<string, any>;

// TODO: Remove with Capabilities
private _systemStatus: HubSystemStatus;

private _serviceStatus: HubServiceStatus;

private _featureFlags: IFeatureFlags;

/**
* Create a new instance of `ArcGISContext`.
*
Expand All @@ -290,7 +290,6 @@ export class ArcGISContext implements IArcGISContext {
this.id = opts.id;
this._portalUrl = opts.portalUrl;
this._hubUrl = opts.hubUrl;
this._systemStatus = opts.systemStatus;
this._serviceStatus = opts.serviceStatus;
if (opts.authentication) {
this._authentication = opts.authentication;
Expand All @@ -306,6 +305,8 @@ export class ArcGISContext implements IArcGISContext {
if (opts.properties) {
this._properties = opts.properties;
}

this._featureFlags = opts.featureFlags || {};
}

/**
Expand All @@ -322,6 +323,14 @@ export class ArcGISContext implements IArcGISContext {
return !!this._authentication;
}

/**
* Return hash of feature flags passed into constructor.
* Default is empty object.
*/
public get featureFlags(): IFeatureFlags {
return this._featureFlags;
}

/**
* Is the users org in the alpha orgs list?
* Alpha orgs are passed in via properties.alphaOrgs
Expand Down Expand Up @@ -461,18 +470,6 @@ export class ArcGISContext implements IArcGISContext {
}
}

/**
* Returns the current hub system status information
* TODO: Remove with Capabilities
*/
get systemStatus(): HubSystemStatus {
// tslint:disable-next-line: no-console
console.warn(
`DEPRECATED: context.systemStatus is deprecated use context.serviceStatus instead`
);
return this._systemStatus;
}

/**
* Returns the current hub service status information
*/
Expand Down
93 changes: 18 additions & 75 deletions packages/common/src/ArcGISContextManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import {
import { getHubApiFromPortalUrl } from "./urls/getHubApiFromPortalUrl";
import { getPortalBaseFromOrgUrl } from "./urls/getPortalBaseFromOrgUrl";
import { Level, Logger } from "./utils/logger";
import { HubService, HubServiceStatus, HubSystemStatus } from "./core";
import { HubServiceStatus } from "./core";
import { cloneObject } from "./util";
import { base64ToUnicode, unicodeToBase64 } from "./utils/encoding";
import { IFeatureFlags } from "./permissions";

/**
* Options that can be passed into `ArcGISContextManager.create`
Expand Down Expand Up @@ -64,15 +65,14 @@ export interface IArcGISContextManagerOptions {
logLevel?: Level;

/**
* DEPRECATED: Option to pass in system status vs fetching it
* TODO: Remove with Capabilities
* Option to pass in service status vs fetching it
*/
systemStatus?: HubSystemStatus;
serviceStatus?: HubServiceStatus;

/**
* Option to pass in service status vs fetching it
* Optional hash of feature flags
*/
serviceStatus?: HubServiceStatus;
featureFlags?: IFeatureFlags;
}

/**
Expand Down Expand Up @@ -113,10 +113,10 @@ export class ArcGISContextManager {

private _logLevel: Level = Level.error;

private _systemStatus: HubSystemStatus;

private _serviceStatus: HubServiceStatus;

private _featureFlags: IFeatureFlags;

/**
* Private constructor. Use `ArcGISContextManager.create(...)` to
* instantiate an instance
Expand Down Expand Up @@ -157,14 +157,13 @@ export class ArcGISContextManager {
this._currentUser = cloneObject(opts.currentUser);
}

// TODO: Remove with Capabilities
if (opts.systemStatus) {
this._systemStatus = opts.systemStatus;
}

if (opts.serviceStatus) {
this._serviceStatus = opts.serviceStatus;
}

if (opts.featureFlags) {
this._featureFlags = cloneObject(opts.featureFlags);
}
}

/**
Expand Down Expand Up @@ -228,10 +227,9 @@ export class ArcGISContextManager {
// of portalUrl
opts.portalUrl = state.portalUrl;
}
// system status is safe to carry forward even if session is expired
// TODO: Remove with Capabilities
opts.systemStatus = state.systemStatus;
// service status and feature flags are safe to carry forward even if session is expired
opts.serviceStatus = state.serviceStatus;
opts.featureFlags = state.featureFlags;

return ArcGISContextManager.create(opts);
}
Expand Down Expand Up @@ -296,9 +294,8 @@ export class ArcGISContextManager {
session?: string;
} = {
portalUrl: this._portalUrl,
// TODO: Remove with Capabilities
systemStatus: this._systemStatus,
serviceStatus: this._serviceStatus,
featureFlags: this._featureFlags,
};

if (this._authentication) {
Expand Down Expand Up @@ -345,11 +342,6 @@ export class ArcGISContextManager {
throw ex;
}
}
// get system status
// TODO: Remove with Capabilities
if (!this._systemStatus) {
this._systemStatus = await getSystemStatus(this._portalUrl);
}
// get service status
if (!this._serviceStatus) {
this._serviceStatus = await getServiceStatus(this._portalUrl);
Expand All @@ -368,9 +360,8 @@ export class ArcGISContextManager {
portalUrl: this._portalUrl,
hubUrl: this._hubUrl,
properties: this._properties,
// TODO: Remove with Capabilities
systemStatus: this._systemStatus,
serviceStatus: this._serviceStatus,
featureFlags: this._featureFlags,
};
if (this._authentication) {
contextOpts.authentication = this._authentication;
Expand All @@ -381,60 +372,12 @@ export class ArcGISContextManager {
if (this._currentUser) {
contextOpts.currentUser = this._currentUser;
}
return contextOpts;
}
}

/**
* Temporary fake implementation based on isPortal
* which we have during the initialization
* @param hubApiUrl
*/
function getSystemStatus(portalUrl: string): Promise<HubSystemStatus> {
let status = HUB_STATUS;
const isPortal = portalUrl.indexOf("arcgis.com") === -1;
// When we move to fetching the system status from the API
// we can use
// const hubApiUrl = getHubApiFromPortalUrl(portalUrl);
if (isPortal) {
status = ENTERPRISE_SITES_STATUS;
// TODO: Decide if featureFlags should be passed forward
return contextOpts;
}

return Promise.resolve(status);
}

const ENTERPRISE_SITES_STATUS: HubSystemStatus = {
content: "online",
discussions: "not-available",
events: "not-available",
initiatives: "not-available",
items: "online",
metrics: "not-available",
notifications: "not-available",
pages: "online",
projects: "not-available",
search: "online",
sites: "online",
groups: "online",
platform: "online",
};

const HUB_STATUS: HubSystemStatus = {
content: "online",
discussions: "online",
events: "online",
initiatives: "online",
items: "online",
metrics: "online",
notifications: "online",
pages: "online",
projects: "online",
search: "online",
sites: "online",
groups: "online",
platform: "online",
};

function getServiceStatus(portalUrl: string): Promise<HubServiceStatus> {
let status = HUB_SERVICE_STATUS;
const isPortal = portalUrl.indexOf("arcgis.com") === -1;
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion packages/common/src/capabilities/_internal/index.ts

This file was deleted.

Loading

0 comments on commit 394c60c

Please sign in to comment.