import PortalUser from "@arcgis/core/portal/PortalUser.js";const PortalUser = await $arcgis.import("@arcgis/core/portal/PortalUser.js");- Inheritance:
- PortalUser→
Accessor
- Since
- ArcGIS Maps SDK for JavaScript 4.0
Represents a registered user of the Portal. Personal details of the user, such as email and groups, are returned only to the user or the administrator of the user's organization. View the ArcGIS Portal API REST documentation for the user for more details.
Constructors
Constructor
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| properties | | |
Properties
| Property | Type | Class |
|---|---|---|
| | ||
| | ||
| | ||
declaredClass readonly inherited | ||
| | ||
| | ||
| | ||
| | ||
| | ||
| | ||
| | ||
| | ||
string[] | | |
| | ||
| | ||
| | ||
| | ||
thumbnailUrl readonly | | |
| | ||
userContentUrl readonly | | |
| |
privileges
- Type
- string[]
The user's privileges based on their user type or role in their organization.
roleId
The ID of the user's role. Only set if the user is assigned a custom role.
When present, the role will indicate the "base" role of the custom role based on the privileges
the custom role contains. For example, if the custom role contains some publisher privileges, the
role will be set to org_publisher.
sourceJSON
- Type
- any
- Since
- ArcGIS Maps SDK for JavaScript 4.13
The JSON used to create the property values when the PortalUser is created.
Although most commonly used properties are exposed on the PortalUser class directly,
this provides access to all information returned for the portal user. This property is
useful if working in an application built using an older version of the API which
requires access to a portal's user properties from a more recent version.
- See also
Methods
| Method | Signature | Class |
|---|---|---|
fromJSON inherited static | fromJSON(json: any): any | |
addItem(params: AddItemParameters): Promise<PortalItem> | | |
deleteItem(item: PortalItem, permanentDelete?: boolean): Promise<void> | | |
deleteItems(items: PortalItem[], permanentDelete?: boolean): Promise<DeleteItemsResult[]> | | |
fetchFolders(): Promise<PortalFolder[]> | | |
fetchGroups(): Promise<PortalGroup[]> | | |
fetchItems(params?: FetchItemsParameters): Promise<FetchItemsResult> | | |
fetchTags(): Promise<Array<{
tag: string;
count: number;
}>> | | |
getThumbnailUrl(width?: number): string | null | undefined | | |
queryFavorites(queryParams?: PortalQueryParamsProperties): Promise<PortalQueryResult<PortalItem>> | | |
restoreItem(item: PortalItem, folder?: PortalFolder | string): Promise<void> | | |
toJSON inherited | toJSON(): any |
fromJSON
- Signature
-
fromJSON (json: any): any
Creates a new instance of this class and initializes it with values from a JSON object
generated from an ArcGIS product. The object passed into the input json
parameter often comes from a response to a query operation in the REST API or a
toJSON()
method from another ArcGIS product. See the Using fromJSON()
topic in the Guide for details and examples of when and how to use this function.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| json | A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects. | |
- Returns
- any
Returns a new instance of this class.
addItem
- Signature
-
addItem (params: AddItemParameters): Promise<PortalItem>
Adds an item to the user's portal content.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| params | See the object specifications table below for the parameters that may be passed as properties in this object. | |
- Returns
- Promise<PortalItem>
When resolved, returns the PortalItem to be added to the user's content.
deleteItem
- Signature
-
deleteItem (item: PortalItem, permanentDelete?: boolean): Promise<void>
Deletes an item from the user's portal content.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| item | The portal item to remove. | | |
| permanentDelete | Since 4.30. When the recycle bin is enabled and the item to be deleted is an item type supported by the recycle bin, this parameter determines if the item should be permanently deleted. If | |
Example
// Delete an item from the user's content.// This will recycle an item if the recycle bin is enabled and item is supported, or// permanently delete it if the recycle bin is disabled or not supported.const portalItem = new PortalItem({ id: "affa021c51944b5694132b2d61fe1057"});portal.user.deleteItem(portalItem).then(() => { console.log("Item deleted from user's content.");})// If the item could not be deleted, an error will be returned..catch((error) => { console.error("Error deleting item: ", error);}); deleteItems
- Signature
-
deleteItems (items: PortalItem[], permanentDelete?: boolean): Promise<DeleteItemsResult[]>
- Since
- ArcGIS Maps SDK for JavaScript 4.8
Deletes items from the user's portal content.
- See also
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| items | The portal items to remove. | | |
| permanentDelete | = false - Since 4.30. When the recycle bin is enabled and the items to be deleted are item types supported by the recycle bin, this parameter determines if the items should be permanently deleted. If | |
- Returns
- Promise<DeleteItemsResult[]>
Resolves to an array of DeleteItemsResult.
Example
// Delete items from the user's content.// This will permanently delete items even if recycle bin is enabled.let itemArray = [portalItem1, portalItem2, portalItem3];portal.user.deleteItems(itemArray, true).then((deleteItemsResults) => { deleteItemsResults.forEach((deleteItemsResult) => { if (deleteItemsResult.success) { console.log(`${deleteItemsResult.item.title} deleted from user's content.`); } else { console.error(`Error deleting ${deleteItemsResult.item.title}: `, result.error); } });}); fetchFolders
- Signature
-
fetchFolders (): Promise<PortalFolder[]>
Fetches all of the user's folders used to organize portal content.
- Returns
- Promise<PortalFolder[]>
Resolves to an array of PortalFolder objects representing each of the user's folders in the portal.
Example
// Once portal is loaded, user signed inportal.load().then(() => { portalUser.fetchFolders().then((folders) => { folders.forEach((folder) => { console.log("User folder", folder.title); }); });}); fetchGroups
- Signature
-
fetchGroups (): Promise<PortalGroup[]>
Fetches all the groups that the portal user has permission to access.
- Returns
- Promise<PortalGroup[]>
Resolves to an array of PortalGroup objects representing each group that the user can access.
Example
// Once portal is loaded, user signed inportal.load().then(() => { // fetch all the groups user can access portal.user.fetchGroups().then((groups) => { groups.forEach((group) => { console.log(`${group.title} group`); }); });}); fetchItems
- Signature
-
fetchItems (params?: FetchItemsParameters): Promise<FetchItemsResult>
Retrieves all the items in either the user's root folder or the specified folder.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| params | See the object specifications table below for the parameters that may be passed as properties in this object. | |
- Returns
- Promise<FetchItemsResult>
Resolves to a FetchItemsResult.
Examples
// Retrieves items from the user's root folder.portal.user.fetchItems().then((fetchItemsResult) => { console.log("Next start index: ", fetchItemsResult.nextStart); fetchItemsResult.items.forEach((item) => { console.log("Portal item title:", item.title); });});// Retrieves items from the recycle bin which will include items from the user's root and subfolders.portal.user.fetchItems( { inRecyclebin: true, includeSubfolderItems: true }).then((fetchItemsResult) => { console.log("next start index: ", fetchItemsResult.nextStart); fetchItemsResult.items.forEach((item) => { console.log("Portal item title:", item.title); });}); queryFavorites
- Signature
-
queryFavorites (queryParams?: PortalQueryParamsProperties): Promise<PortalQueryResult<PortalItem>>
Executes a query against the user's favorite group to return an array of PortalItem objects that match the input query.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| queryParams | The input query parameters defined in PortalQueryParams. This object may be autocast. | |
- Returns
- Promise<PortalQueryResult<PortalItem>>
When resolved, resolves to an instance of PortalQueryResult which contains a
resultsarray of PortalItem objects representing all the items that match the input query.
restoreItem
- Signature
-
restoreItem (item: PortalItem, folder?: PortalFolder | string): Promise<void>
- Since
- ArcGIS Maps SDK for JavaScript 4.30
Restores an item from the user's recycle bin to their content. This method only applies if the recycle bin is enabled on the organization.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| item | The portal item to restore. | | |
| folder | The folder to restore the item to. If not specified, the item will be restored to the root folder. If an invalid folder is specified, an error will be returned and the item will not be restored. | |
Examples
// Restore a recycled item to the root folder.const portalItem = new PortalItem({ id: "affa021c51944b5694132b2d61fe1057"});portal.user.restoreItem(portalItem).then(() => { console.log("Item restored to root folder.")});// Restore a recycled item to a specified folder.const portalItem = new PortalItem({ id: "affa021c51944b5694132b2d61fe1057"});// This can be a PortalFolder object or a folder ID string.const portalFolder = "6bbff8b7f2b54c628603135b72f9cb55";portal.user.restoreItem(portalItem, portalFolder).then(() => { console.log("Item restored to folder with ID: '6bbff8b7f2b54c628603135b72f9cb55'.")}); toJSON
- Signature
-
toJSON (): any
Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.
- Returns
- any
The ArcGIS portal JSON representation of an instance of this class.