-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(hub-sites): prevent surveys and their feature services from being…
… shared to site teams during si affects: @esri/hub-sites, @esri/hub-surveys ISSUES CLOSED: [2325](https://devtopia.esri.com/dc/hub/issues/2325)
- Loading branch information
1 parent
820900c
commit 658ed28
Showing
8 changed files
with
19,149 additions
and
32,937 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { IModel, IHubRequestOptions } from "@esri/hub-common"; | ||
import { getSurveyModels } from "@esri/hub-surveys"; | ||
|
||
function _getIneligibleModelIds( | ||
siteModel: IModel, | ||
models: IModel[], | ||
hubRequestOptions: IHubRequestOptions | ||
) { | ||
const fetchSurveyModels = (model: IModel) => | ||
getSurveyModels(model.item, hubRequestOptions).then( | ||
({ form, featureService, fieldworker, stakeholder }) => | ||
[form, featureService, fieldworker, stakeholder].filter(Boolean) | ||
); | ||
|
||
const inEligibleModelCollectionPromises = models.reduce( | ||
(acc, model) => | ||
model.item.type === "Form" ? [...acc, fetchSurveyModels(model)] : acc, | ||
[Promise.resolve([siteModel])] | ||
); | ||
|
||
return Promise.all(inEligibleModelCollectionPromises).then( | ||
(ineligibleModelCollections) => | ||
ineligibleModelCollections.reduce( | ||
(acc, ineligibleModelCollection) => [ | ||
...acc, | ||
...ineligibleModelCollection, | ||
], | ||
[] | ||
) | ||
); | ||
} | ||
|
||
export function _getSharingEligibleModels( | ||
siteModel: IModel, | ||
models: IModel[], | ||
hubRequestOptions: IHubRequestOptions | ||
) { | ||
return _getIneligibleModelIds(siteModel, models, hubRequestOptions).then( | ||
(ineligibleModels) => | ||
models.reduce( | ||
(acc, model) => | ||
ineligibleModels.find(({ item: { id } }) => model.item.id === id) | ||
? acc | ||
: [...acc, model], | ||
[] | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
|
||
import { IModel, IHubRequestOptions } from "@esri/hub-common"; | ||
import * as hubSurveys from "@esri/hub-surveys"; | ||
import { _getSharingEligibleModels } from "../src/_get-sharing-eligible-models"; | ||
import { getSurveyModels } from "@esri/hub-surveys"; | ||
|
||
describe("_getSharingEligibleModels", function () { | ||
let models: IModel[]; | ||
let siteModel: IModel; | ||
let hubRequestOptions: IHubRequestOptions; | ||
|
||
beforeEach(() => { | ||
siteModel = { item: { id: "site-id" } } as IModel; | ||
|
||
models = [ | ||
siteModel, | ||
{ item: { id: "123", type: "Web Map" } }, | ||
{ item: { id: "456", type: "Form" } }, | ||
{ item: { id: "789", type: "Feature Service" } }, | ||
{ item: { id: "101", type: "Feature Service" } }, | ||
{ item: { id: "121", type: "Feature Service" } }, | ||
] as IModel[]; | ||
|
||
hubRequestOptions = { authentication: {} } as IHubRequestOptions; | ||
}); | ||
|
||
it("resolves an array of sharing eligible models", async function () { | ||
const getSurveyModelsSpy = spyOn( | ||
hubSurveys, | ||
"getSurveyModels" | ||
).and.returnValue( | ||
Promise.resolve({ | ||
form: models[2], | ||
featureService: models[3], | ||
fieldworker: models[4], | ||
stakeholder: models[5], | ||
}) | ||
); | ||
const results = await _getSharingEligibleModels( | ||
siteModel, | ||
models, | ||
hubRequestOptions | ||
); | ||
expect(getSurveyModelsSpy.calls.count()).toBe(1); | ||
expect(getSurveyModelsSpy).toHaveBeenCalledWith( | ||
models[2].item, | ||
hubRequestOptions | ||
); | ||
expect(results.length).toBe(1); | ||
expect(results[0]).toEqual(models[1]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.