Skip to content

Commit

Permalink
fix(annotation users): pass auth when getting anno user; handle faile…
Browse files Browse the repository at this point in the history
…d requests

when getting user info pass along authentication from current request
also ignore failed requests to get user info

AFFECTS PACKAGES:
@esri/hub-annotations

ISSUES CLOSED: #40
  • Loading branch information
tomwayson committed Jun 7, 2019
1 parent e8c3950 commit d8485d2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
13 changes: 8 additions & 5 deletions packages/annotations/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
IStatisticDefinition
} from "@esri/arcgis-rest-feature-layer";

import { getUser, IGetUserOptions } from "@esri/arcgis-rest-portal";
import { getUser } from "@esri/arcgis-rest-portal";
import { UserSession } from "@esri/arcgis-rest-auth";
import { IGeometry, IFeature } from "@esri/arcgis-rest-types";
import { IAnnoFeature } from "./add";
Expand Down Expand Up @@ -98,17 +98,20 @@ export function searchAnnotations(

const getUserInfo = users
.filter(name => name !== "") // filter out anonymous comments
.map(name =>
getUser({
.map(name => {
return getUser({
username: name,
authentication: requestOptions.authentication as UserSession
})
);
}).catch(() => null);
});

return Promise.all(getUserInfo).then(userInfo => {
const included: IResourceObject[] = [];

userInfo.forEach(attributes => {
if (!attributes) {
return;
}
included.push({ id: attributes.username, type: `users`, attributes });
});

Expand Down
28 changes: 28 additions & 0 deletions packages/annotations/test/mocks/anno_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ export const annoQueryResponse = {
updated_at: 1349395200002,
dataset_id: "xds466"
}
},
{
attributes: {
OBJECTID: 5,
author: "nolongerexists",
source: null as string,
status: "pending",
target: "something",
data: "somehow this user no longer exists",
created_at: 1349395200002,
updated_at: 1349395200002,
dataset_id: "xds466"
}
}
]
};
Expand Down Expand Up @@ -231,6 +244,21 @@ const data = [
updated_at: 1349395200002,
dataset_id: "xds466"
}
},
{
id: 5,
type: "annotations",
attributes: {
OBJECTID: 5,
author: "nolongerexists",
source: null as string,
status: "pending",
target: "something",
data: "somehow this user no longer exists",
created_at: 1349395200002,
updated_at: 1349395200002,
dataset_id: "xds466"
}
}
] as IResourceObject[];

Expand Down
10 changes: 8 additions & 2 deletions packages/annotations/test/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ describe("searchAnnotations", () => {
}),
new Promise(resolve => {
resolve(userResponseJones);
}),
new Promise((resolve, reject) => {
reject({ error: "not sure this matters" });
})
);

Expand All @@ -70,7 +73,7 @@ describe("searchAnnotations", () => {
})
.then(response => {
expect(queryParamsSpy.calls.count()).toEqual(1);
expect(userParamsSpy.calls.count()).toEqual(2);
expect(userParamsSpy.calls.count()).toEqual(3);
const queryOpts = queryParamsSpy.calls.argsFor(
0
)[0] as IQueryFeaturesOptions;
Expand Down Expand Up @@ -146,6 +149,9 @@ describe("searchAnnotations", () => {
}),
new Promise(resolve => {
resolve(userResponseJones);
}),
new Promise((resolve, reject) => {
reject({ error: "not sure this matters" });
})
);

Expand All @@ -155,7 +161,7 @@ describe("searchAnnotations", () => {
})
.then(response => {
expect(queryParamsSpy.calls.count()).toEqual(1);
expect(userParamsSpy.calls.count()).toEqual(2);
expect(userParamsSpy.calls.count()).toEqual(3);
const queryOpts = queryParamsSpy.calls.argsFor(
0
)[0] as IQueryFeaturesOptions;
Expand Down

0 comments on commit d8485d2

Please sign in to comment.