@esri/arcgis-rest-portal
Version:
ArcGIS Online and Enterprise content and user helpers for @esri/arcgis-rest-request
42 lines • 1.95 kB
JavaScript
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */
import { getPortalUrl } from "../util/get-portal-url.js";
import { getGroup } from "../groups/get.js";
export function getSharingUrl(requestOptions, username) {
const providedUsername = username || requestOptions.authentication.username; // as any workaround for backward compatibility for discovering username from provided auth method
const owner = requestOptions.owner || providedUsername;
return `${getPortalUrl(requestOptions)}/content/users/${encodeURIComponent(owner)}/items/${requestOptions.id}/share`;
}
export function isItemOwner(requestOptions, username) {
const providedUsername = username || requestOptions.authentication.username; // as any workaround for backward compatibility for discovering username from provided auth method
const owner = requestOptions.owner || providedUsername;
return owner === providedUsername;
}
/**
* Check it the user is a full org_admin
* @param requestOptions
* @returns Promise resolving in a boolean indicating if the user is an ArcGIS Organization administrator
*/
export function isOrgAdmin(requestOptions) {
return requestOptions.authentication.getUser().then((user) => {
return user && user.role === "org_admin" && !user.roleId;
});
}
/**
* Get the User Membership for a particular group. Use this if all you have is the groupId.
* If you have the group object, check the `userMembership.memberType` property instead of calling this method.
*
* @param requestOptions
* @returns A Promise that resolves with "owner" | "admin" | "member" | "none"
*/
export function getUserMembership(requestOptions) {
// fetch the group...
return getGroup(requestOptions.groupId, requestOptions)
.then((group) => {
return group.userMembership.memberType;
})
.catch(() => {
return "none";
});
}
//# sourceMappingURL=helpers.js.map