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

fix(hub-sites): prevent surveys and their feature services from being… #669

Merged
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
52,014 changes: 19,048 additions & 32,966 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export * from "./util";
export * from "./utils";
export * from "./i18n";
export * from "./request";
export * from "./surveys";

import OperationStack from "./OperationStack";
import OperationError from "./OperationError";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { IRequestOptions } from "@esri/arcgis-rest-request";
import { getRelatedItems } from "@esri/arcgis-rest-portal";
import { IModel } from "@esri/hub-common";
import { IModel } from "../types";

/**
* Gets the primary input Feature Service for the given
Expand All @@ -21,7 +21,7 @@ export const getInputFeatureServiceModel = (
id: formId,
relationshipType: "Survey2Service",
direction: "forward",
...requestOptions
...requestOptions,
}).then(({ relatedItems: [featureService] }) => {
let model;
if (featureService) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { IRequestOptions } from "@esri/arcgis-rest-request";
import { getRelatedItems } from "@esri/arcgis-rest-portal";
import { IModel } from "@esri/hub-common";
import { IModel } from "../types";

/**
* Fetches a Survey's source Feature Service from a given
Expand All @@ -20,7 +20,7 @@ export const getSourceFeatureServiceModelFromFieldworker = (
id: fieldworkerId,
relationshipType: "Service2Data",
direction: "forward",
...requestOptions
...requestOptions,
}).then(({ relatedItems: [featureService] }) => {
let model;
if (featureService) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { IRequestOptions } from "@esri/arcgis-rest-request";
import { getRelatedItems } from "@esri/arcgis-rest-portal";
import { IModel } from "@esri/hub-common";
import { IModel } from "../types";

/**
* Fetches a Survey's Stakeholder View for a given
Expand All @@ -20,7 +20,7 @@ export const getStakeholderModel = (
id: formId,
relationshipType: "Survey2Data",
direction: "forward",
...requestOptions
...requestOptions,
}).then(({ relatedItems: [stakeholderView] }) => {
let model;
if (stakeholderView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
* Apache-2.0 */

import { IRequestOptions } from "@esri/arcgis-rest-request";
import { getItem } from "@esri/arcgis-rest-portal";
import { IModel, IGetSurveyModelsResponse } from "@esri/hub-common";
import { getItem, IItem } from "@esri/arcgis-rest-portal";
import { IModel, IGetSurveyModelsResponse } from "../types";
import { getInputFeatureServiceModel } from "./get-input-feature-service-model";
import { getSourceFeatureServiceModelFromFieldworker } from "./get-source-feature-service-model-from-fieldworker";
import { getStakeholderModel } from "./get-stakeholder-model";
import { isFieldworkerView } from "../utils/is-fieldworker-view";
import { isFieldworkerView } from "./is-fieldworker-view";

/**
* Builds a dictionary of Survey items for the given Form model
Expand All @@ -16,18 +16,23 @@ import { isFieldworkerView } from "../utils/is-fieldworker-view";
* @returns {Promise<IGetSurveyModelsResponse>}
*/
export const getSurveyModels = (
formId: string,
formItemOrId: string | IItem,
requestOptions: IRequestOptions
): Promise<IGetSurveyModelsResponse> => {
let fieldworker: IModel;
let stakeholder: IModel;

return getItem(formId, requestOptions).then(item => {
const getForm = () =>
typeof formItemOrId === "string"
? getItem(formItemOrId, requestOptions)
: Promise.resolve(formItemOrId);

return getForm().then((form) => {
const promises: Array<Promise<IModel>> = [
// the primary input will be the fieldworker (if it exists), otherwise
// the source feature service.
getInputFeatureServiceModel(formId, requestOptions),
getStakeholderModel(formId, requestOptions)
getInputFeatureServiceModel(form.id, requestOptions),
getStakeholderModel(form.id, requestOptions),
];

return Promise.all(promises)
Expand All @@ -49,12 +54,12 @@ export const getSurveyModels = (
return featureServiceOrFieldworkerModelResult;
}
})
.then(featureService => {
.then((featureService) => {
return {
form: { item },
form: { item: form },
featureService,
fieldworker,
stakeholder
stakeholder,
};
});
});
Expand Down
5 changes: 5 additions & 0 deletions packages/common/src/surveys/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from "./get-input-feature-service-model";
export * from "./get-source-feature-service-model-from-fieldworker";
export * from "./get-stakeholder-model";
export * from "./get-survey-models";
export * from "./is-fieldworker-view";
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function isFieldworkerView(featureServiceItem: IItem): boolean {
const hasExpectedTypeKeywords = [
"Survey123",
"Feature Service",
"View Service"
"View Service",
].every(hasTypekeyword);
isFieldworker =
hasExpectedTypeKeywords && !hasTypekeyword("StakeholderView");
Expand Down
38 changes: 38 additions & 0 deletions packages/common/test/mocks/groups/update-group.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"id": "08e7a44370674f1189555b3f49e56ad9",
"title": "My Update Group",
"isInvitationOnly": false,
"owner": "surveyownerqa",
"description": "My Update Group description",
"snippet": "My Update Group snippet",
"tags": [
"Hub Group",
"Hub Initiative Group",
"Hub Site Group",
"Hub Core Team Group",
"Hub Team Group"
],
"phone": null,
"sortField": "modified",
"sortOrder": "desc",
"isViewOnly": false,
"thumbnail": null,
"created": 1572898481000,
"modified": 1592418955000,
"access": "public",
"capabilities": [
"updateitemcontrol"
],
"isFav": false,
"isReadOnly": false,
"protected": true,
"autoJoin": false,
"notificationsEnabled": false,
"provider": null,
"providerGroupName": null,
"leavingDisallowed": false,
"hiddenMembers": false,
"displaySettings": {
"itemTypes": ""
}
}
35 changes: 35 additions & 0 deletions packages/common/test/mocks/groups/view-group.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"id": "437eb8e240fd42c2afa5b8005d35bd16",
"title": "My View Group",
"isInvitationOnly": false,
"owner": "surveyownerqa",
"description": "My View Group description",
"snippet": "My View Group snippet",
"tags": [
"Hub Group",
"Hub Content Group",
"Hub Site Group",
"Hub Initiative Group"
],
"phone": null,
"sortField": "modified",
"sortOrder": "desc",
"isViewOnly": false,
"thumbnail": null,
"created": 1572898481000,
"modified": 1592422470000,
"access": "org",
"capabilities": [],
"isFav": false,
"isReadOnly": false,
"protected": true,
"autoJoin": false,
"notificationsEnabled": false,
"provider": null,
"providerGroupName": null,
"leavingDisallowed": false,
"hiddenMembers": false,
"displaySettings": {
"itemTypes": ""
}
}
67 changes: 67 additions & 0 deletions packages/common/test/mocks/items/feature-service-item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"id": "9a2fea7edecc47eb9818b4f5a220ee71",
"owner": "surveyownerqa",
"created": 1591979702000,
"isOrgItem": true,
"modified": 1591979848000,
"guid": null,
"name": "survey123_a5db32e043f14f6a9edfec7075288df6",
"title": "My Survey Schema (System File)",
"type": "Feature Service",
"typeKeywords": [
"a5db32e043f14f6a9edfec7075288df6",
"ArcGIS Server",
"Data",
"Feature Access",
"Feature Service",
"OwnerView",
"Service",
"Singlelayer",
"Source",
"Survey123",
"Survey123 Hub",
"SurveyService",
"Hosted Service"
],
"description": null,
"tags": [],
"snippet": null,
"thumbnail": null,
"documentation": null,
"extent": [
[
-180,
-90
],
[
180,
90
]
],
"categories": [],
"accessInformation": null,
"licenseInfo": null,
"culture": "",
"properties": null,
"url": "https://servicesqa.arcgis.com/Xj56SBi2udA78cC9/arcgis/rest/services/survey123_a5db32e043f14f6a9edfec7075288df6/FeatureServer",
"proxyFilter": null,
"access": "org",
"size": 10526,
"appCategories": [],
"industries": [],
"languages": [],
"largeThumbnail": null,
"banner": null,
"screenshots": [],
"listed": false,
"ownerFolder": "9f56495a60244cb6988ccf4ee23e3aab",
"protected": false,
"commentsEnabled": true,
"numComments": 0,
"numRatings": 0,
"avgRating": 0,
"numViews": 0,
"itemControl": "admin",
"scoreCompleteness": 16,
"groupDesignations": null
}
66 changes: 66 additions & 0 deletions packages/common/test/mocks/items/fieldworker-item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"id": "03b5d608ae204177bb69acaf06fb2f98",
"owner": "surveyownerqa",
"created": 1591979735000,
"isOrgItem": true,
"modified": 1591979848000,
"guid": null,
"name": "survey123_a5db32e043f14f6a9edfec7075288df6_fieldworker",
"title": "My Survey Inputs (System File)",
"type": "Feature Service",
"typeKeywords": [
"a5db32e043f14f6a9edfec7075288df6",
"ArcGIS Server",
"Data",
"Feature Access",
"Feature Service",
"FieldworkerView",
"Service",
"Singlelayer",
"Survey123",
"Survey123 Hub",
"Hosted Service",
"View Service"
],
"description": null,
"tags": [],
"snippet": null,
"thumbnail": null,
"documentation": null,
"extent": [
[
-180,
-90
],
[
180,
90
]
],
"categories": [],
"accessInformation": null,
"licenseInfo": null,
"culture": "",
"properties": null,
"url": "https://servicesqa.arcgis.com/Xj56SBi2udA78cC9/arcgis/rest/services/survey123_a5db32e043f14f6a9edfec7075288df6_fieldworker/FeatureServer",
"proxyFilter": null,
"access": "org",
"size": 0,
"appCategories": [],
"industries": [],
"languages": [],
"largeThumbnail": null,
"banner": null,
"screenshots": [],
"listed": false,
"ownerFolder": "9f56495a60244cb6988ccf4ee23e3aab",
"protected": false,
"commentsEnabled": true,
"numComments": 0,
"numRatings": 0,
"avgRating": 0,
"numViews": 0,
"itemControl": "admin",
"scoreCompleteness": 16,
"groupDesignations": null
}
Loading