import { IUser } from "@esri/arcgis-rest-auth" ; import { hasAllPrivileges } from "./has-all-privileges" ; import { GROUP_ACCESS_PRIVS } from "./group-access-privs" ; import { AGOAccess } from "../types" ; import { IPortal } from "@esri/arcgis-rest-portal" ; import { getProp } from "@esri/hub-common" ; param requestedAccess param user param portal export function getAllowedGroupAccess ( requestedAccess , user , portal ? ) { const portalWideCanSharePublic = getProp ( portal , "canSharePublic" ) || false ; const canCreatePublic = portalWideCanSharePublic && hasAllPrivileges ( user , GROUP_ACCESS_PRIVS . public ) ; const canCreateOrg = hasAllPrivileges ( user , GROUP_ACCESS_PRIVS . org ) ; let result = requestedAccess ; if ( requestedAccess === "public" && ! canCreatePublic ) { result = "org" ; if ( ! canCreateOrg ) { result = "private" ; } } else { if ( requestedAccess === "org" && ! canCreateOrg ) { result = "private" ; } } return result ; }