import { IGroup , IUser , GroupMembership } from "@esri/arcgis-rest-types" ; import { IUserRequestOptions } from "@esri/arcgis-rest-auth" ; import { getPortalUrl } from "../util/get-portal-url" ; import { getGroup } from "../groups/get" ; export interface ISharingOptions extends IUserRequestOptions { /**
     * Unique identifier for the item.
     */ id : string ; /**
     * Item owner, if different from the authenticated user.
     */ owner ? : string ; } export interface ISharingResponse { notSharedWith ? : string [ ] ; notUnsharedFrom ? : string [ ] ; itemId : string ; } export function getSharingUrl ( requestOptions ) { const username = requestOptions . authentication . username ; const owner = requestOptions . owner || username ; return `${ getPortalUrl ( requestOptions ) }/content/users/${ encodeURIComponent ( owner ) }/items/${ requestOptions . id }/share` ; } export function isItemOwner ( requestOptions ) { const username = requestOptions . authentication . username ; const owner = requestOptions . owner || username ; return owner === username ; } param requestOptions returns export function isOrgAdmin ( requestOptions ) { const session = requestOptions . authentication ; return session . getUser ( requestOptions ) . then ( ( user ) => { return user && user . role === "org_admin" && ! user . roleId ; } ) ; } param requestOptions returns export function getUserMembership ( requestOptions ) { return getGroup ( requestOptions . groupId , requestOptions ) . then ( ( group ) => { return group . userMembership . memberType ; } ) . catch ( ( ) => { return "none" as GroupMembership ; } ) ; } export interface IGroupSharingOptions extends ISharingOptions { /**
     * Group identifier
     */ groupId : string ; confirmItemControl ? : boolean ; }