UNPKG

@pnp/sp

Version:

pnp - provides a fluent api for working with SharePoint REST

332 lines • 12.8 kB
import { __decorate } from "tslib"; import { hOP } from "@pnp/core"; import { body } from "@pnp/queryable"; import { _SPInstance, _SPCollection, deleteable, spInvokableFactory, SPCollection, } from "../spqueryable.js"; import { SiteGroups } from "../site-groups/types.js"; import { defaultPath } from "../decorators.js"; import { spPost, spPostMerge } from "../operations.js"; /** * Describes a set of role assignments for the current scope * */ let _RoleAssignments = class _RoleAssignments extends _SPCollection { /** * Gets the role assignment associated with the specified principal id from the collection. * * @param id The id of the role assignment */ getById(id) { return RoleAssignment(this).concat(`(${id})`); } /** * Adds a new role assignment with the specified principal and role definitions to the collection * * @param principalId The id of the user or group to assign permissions to * @param roleDefId The id of the role definition that defines the permissions to assign * */ async add(principalId, roleDefId) { await spPost(RoleAssignments(this, `addroleassignment(principalid=${principalId}, roledefid=${roleDefId})`)); } /** * Removes the role assignment with the specified principal and role definition from the collection * * @param principalId The id of the user or group in the role assignment * @param roleDefId The id of the role definition in the role assignment * */ async remove(principalId, roleDefId) { await spPost(RoleAssignments(this, `removeroleassignment(principalid=${principalId}, roledefid=${roleDefId})`)); } }; _RoleAssignments = __decorate([ defaultPath("roleassignments") ], _RoleAssignments); export { _RoleAssignments }; export const RoleAssignments = spInvokableFactory(_RoleAssignments); /** * Describes a role assignment * */ export class _RoleAssignment extends _SPInstance { constructor() { super(...arguments); this.delete = deleteable(); } /** * Gets the groups that directly belong to the access control list (ACL) for this securable object * */ get groups() { return SiteGroups(this, "groups"); } /** * Gets the role definition bindings for this role assignment * */ get bindings() { return SPCollection(this, "roledefinitionbindings"); } } export const RoleAssignment = spInvokableFactory(_RoleAssignment); /** * Describes a collection of role definitions * */ let _RoleDefinitions = class _RoleDefinitions extends _SPCollection { /** * Gets the role definition with the specified id from the collection * * @param id The id of the role definition * */ getById(id) { return RoleDefinition(this, `getById(${id})`); } /** * Gets the role definition with the specified name * * @param name The name of the role definition * */ getByName(name) { return RoleDefinition(this, `getbyname('${name}')`); } /** * Gets the role definition with the specified role type * * @param roleTypeKind The roletypekind of the role definition (None=0, Guest=1, Reader=2, Contributor=3, WebDesigner=4, Administrator=5, Editor=6, System=7) * */ getByType(roleTypeKind) { return RoleDefinition(this, `getbytype(${roleTypeKind})`); } /** * Creates a role definition * * @param name The new role definition's name * @param description The new role definition's description * @param order The order in which the role definition appears * @param basePermissions The permissions mask for this role definition, high and low values need to be converted to string * */ async add(name, description, order, basePermissions) { const postBody = body({ BasePermissions: { "High": basePermissions.High.toString(), "Low": basePermissions.Low.toString() }, Description: description, Name: name, Order: order, }); // __metadata: { "type": "SP.RoleDefinition" }, const data = await spPost(this, postBody); return { data: data, definition: this.getById(data.Id), }; } }; _RoleDefinitions = __decorate([ defaultPath("roledefinitions") ], _RoleDefinitions); export { _RoleDefinitions }; export const RoleDefinitions = spInvokableFactory(_RoleDefinitions); /** * Describes a role definition * */ export class _RoleDefinition extends _SPInstance { constructor() { super(...arguments); this.delete = deleteable(); } /** * Updates this role definition with the supplied properties * * @param properties A plain object hash of values to update for the role definition */ async update(properties) { const s = ["BasePermissions"]; if (hOP(properties, s[0]) !== undefined) { const bpObj = properties[s[0]]; bpObj.High = bpObj.High.toString(); bpObj.Low = bpObj.Low.toString(); } const data = await spPostMerge(this, body(properties)); let definition = this; if (hOP(properties, "Name")) { const parent = this.getParent(RoleDefinitions); definition = parent.getByName(properties.Name); } return { data, definition, }; } } export const RoleDefinition = spInvokableFactory(_RoleDefinition); export var PermissionKind; (function (PermissionKind) { /** * Has no permissions on the Site. Not available through the user interface. */ PermissionKind[PermissionKind["EmptyMask"] = 0] = "EmptyMask"; /** * View items in lists, documents in document libraries, and Web discussion comments. */ PermissionKind[PermissionKind["ViewListItems"] = 1] = "ViewListItems"; /** * Add items to lists, documents to document libraries, and Web discussion comments. */ PermissionKind[PermissionKind["AddListItems"] = 2] = "AddListItems"; /** * Edit items in lists, edit documents in document libraries, edit Web discussion comments * in documents, and customize Web Part Pages in document libraries. */ PermissionKind[PermissionKind["EditListItems"] = 3] = "EditListItems"; /** * Delete items from a list, documents from a document library, and Web discussion * comments in documents. */ PermissionKind[PermissionKind["DeleteListItems"] = 4] = "DeleteListItems"; /** * Approve a minor version of a list item or document. */ PermissionKind[PermissionKind["ApproveItems"] = 5] = "ApproveItems"; /** * View the source of documents with server-side file handlers. */ PermissionKind[PermissionKind["OpenItems"] = 6] = "OpenItems"; /** * View past versions of a list item or document. */ PermissionKind[PermissionKind["ViewVersions"] = 7] = "ViewVersions"; /** * Delete past versions of a list item or document. */ PermissionKind[PermissionKind["DeleteVersions"] = 8] = "DeleteVersions"; /** * Discard or check in a document which is checked out to another user. */ PermissionKind[PermissionKind["CancelCheckout"] = 9] = "CancelCheckout"; /** * Create, change, and delete personal views of lists. */ PermissionKind[PermissionKind["ManagePersonalViews"] = 10] = "ManagePersonalViews"; /** * Create and delete lists, add or remove columns in a list, and add or remove public views of a list. */ PermissionKind[PermissionKind["ManageLists"] = 12] = "ManageLists"; /** * View forms, views, and application pages, and enumerate lists. */ PermissionKind[PermissionKind["ViewFormPages"] = 13] = "ViewFormPages"; /** * Make content of a list or document library retrieveable for anonymous users through SharePoint search. * The list permissions in the site do not change. */ PermissionKind[PermissionKind["AnonymousSearchAccessList"] = 14] = "AnonymousSearchAccessList"; /** * Allow users to open a Site, list, or folder to access items inside that container. */ PermissionKind[PermissionKind["Open"] = 17] = "Open"; /** * View pages in a Site. */ PermissionKind[PermissionKind["ViewPages"] = 18] = "ViewPages"; /** * Add, change, or delete HTML pages or Web Part Pages, and edit the Site using * a Windows SharePoint Services compatible editor. */ PermissionKind[PermissionKind["AddAndCustomizePages"] = 19] = "AddAndCustomizePages"; /** * Apply a theme or borders to the entire Site. */ PermissionKind[PermissionKind["ApplyThemeAndBorder"] = 20] = "ApplyThemeAndBorder"; /** * Apply a style sheet (.css file) to the Site. */ PermissionKind[PermissionKind["ApplyStyleSheets"] = 21] = "ApplyStyleSheets"; /** * View reports on Site usage. */ PermissionKind[PermissionKind["ViewUsageData"] = 22] = "ViewUsageData"; /** * Create a Site using Self-Service Site Creation. */ PermissionKind[PermissionKind["CreateSSCSite"] = 23] = "CreateSSCSite"; /** * Create subsites such as team sites, Meeting Workspace sites, and Document Workspace sites. */ PermissionKind[PermissionKind["ManageSubwebs"] = 24] = "ManageSubwebs"; /** * Create a group of users that can be used anywhere within the site collection. */ PermissionKind[PermissionKind["CreateGroups"] = 25] = "CreateGroups"; /** * Create and change permission levels on the Site and assign permissions to users * and groups. */ PermissionKind[PermissionKind["ManagePermissions"] = 26] = "ManagePermissions"; /** * Enumerate files and folders in a Site using Microsoft Office SharePoint Designer * and WebDAV interfaces. */ PermissionKind[PermissionKind["BrowseDirectories"] = 27] = "BrowseDirectories"; /** * View information about users of the Site. */ PermissionKind[PermissionKind["BrowseUserInfo"] = 28] = "BrowseUserInfo"; /** * Add or remove personal Web Parts on a Web Part Page. */ PermissionKind[PermissionKind["AddDelPrivateWebParts"] = 29] = "AddDelPrivateWebParts"; /** * Update Web Parts to display personalized information. */ PermissionKind[PermissionKind["UpdatePersonalWebParts"] = 30] = "UpdatePersonalWebParts"; /** * Grant the ability to perform all administration tasks for the Site as well as * manage content, activate, deactivate, or edit properties of Site scoped Features * through the object model or through the user interface (UI). When granted on the * root Site of a Site Collection, activate, deactivate, or edit properties of * site collection scoped Features through the object model. To browse to the Site * Collection Features page and activate or deactivate Site Collection scoped Features * through the UI, you must be a Site Collection administrator. */ PermissionKind[PermissionKind["ManageWeb"] = 31] = "ManageWeb"; /** * Content of lists and document libraries in the Web site will be retrieveable for anonymous users through * SharePoint search if the list or document library has AnonymousSearchAccessList set. */ PermissionKind[PermissionKind["AnonymousSearchAccessWebLists"] = 32] = "AnonymousSearchAccessWebLists"; /** * Use features that launch client applications. Otherwise, users must work on documents * locally and upload changes. */ PermissionKind[PermissionKind["UseClientIntegration"] = 37] = "UseClientIntegration"; /** * Use SOAP, WebDAV, or Microsoft Office SharePoint Designer interfaces to access the Site. */ PermissionKind[PermissionKind["UseRemoteAPIs"] = 38] = "UseRemoteAPIs"; /** * Manage alerts for all users of the Site. */ PermissionKind[PermissionKind["ManageAlerts"] = 39] = "ManageAlerts"; /** * Create e-mail alerts. */ PermissionKind[PermissionKind["CreateAlerts"] = 40] = "CreateAlerts"; /** * Allows a user to change his or her user information, such as adding a picture. */ PermissionKind[PermissionKind["EditMyUserInfo"] = 41] = "EditMyUserInfo"; /** * Enumerate permissions on Site, list, folder, document, or list item. */ PermissionKind[PermissionKind["EnumeratePermissions"] = 63] = "EnumeratePermissions"; /** * Has all permissions on the Site. Not available through the user interface. */ PermissionKind[PermissionKind["FullMask"] = 65] = "FullMask"; })(PermissionKind || (PermissionKind = {})); //# sourceMappingURL=types.js.map