UNPKG

12.8 kBJavaScriptView Raw
1import { __decorate } from "tslib";
2import { hOP } from "@pnp/core";
3import { body } from "@pnp/queryable";
4import { _SPInstance, _SPCollection, deleteable, spInvokableFactory, SPCollection, } from "../spqueryable.js";
5import { SiteGroups } from "../site-groups/types.js";
6import { defaultPath } from "../decorators.js";
7import { spPost, spPostMerge } from "../operations.js";
8/**
9 * Describes a set of role assignments for the current scope
10 *
11 */
12let _RoleAssignments = class _RoleAssignments extends _SPCollection {
13 /**
14 * Gets the role assignment associated with the specified principal id from the collection.
15 *
16 * @param id The id of the role assignment
17 */
18 getById(id) {
19 return RoleAssignment(this).concat(`(${id})`);
20 }
21 /**
22 * Adds a new role assignment with the specified principal and role definitions to the collection
23 *
24 * @param principalId The id of the user or group to assign permissions to
25 * @param roleDefId The id of the role definition that defines the permissions to assign
26 *
27 */
28 async add(principalId, roleDefId) {
29 await spPost(RoleAssignments(this, `addroleassignment(principalid=${principalId}, roledefid=${roleDefId})`));
30 }
31 /**
32 * Removes the role assignment with the specified principal and role definition from the collection
33 *
34 * @param principalId The id of the user or group in the role assignment
35 * @param roleDefId The id of the role definition in the role assignment
36 *
37 */
38 async remove(principalId, roleDefId) {
39 await spPost(RoleAssignments(this, `removeroleassignment(principalid=${principalId}, roledefid=${roleDefId})`));
40 }
41};
42_RoleAssignments = __decorate([
43 defaultPath("roleassignments")
44], _RoleAssignments);
45export { _RoleAssignments };
46export const RoleAssignments = spInvokableFactory(_RoleAssignments);
47/**
48 * Describes a role assignment
49 *
50 */
51export class _RoleAssignment extends _SPInstance {
52 constructor() {
53 super(...arguments);
54 this.delete = deleteable();
55 }
56 /**
57 * Gets the groups that directly belong to the access control list (ACL) for this securable object
58 *
59 */
60 get groups() {
61 return SiteGroups(this, "groups");
62 }
63 /**
64 * Gets the role definition bindings for this role assignment
65 *
66 */
67 get bindings() {
68 return SPCollection(this, "roledefinitionbindings");
69 }
70}
71export const RoleAssignment = spInvokableFactory(_RoleAssignment);
72/**
73 * Describes a collection of role definitions
74 *
75 */
76let _RoleDefinitions = class _RoleDefinitions extends _SPCollection {
77 /**
78 * Gets the role definition with the specified id from the collection
79 *
80 * @param id The id of the role definition
81 *
82 */
83 getById(id) {
84 return RoleDefinition(this, `getById(${id})`);
85 }
86 /**
87 * Gets the role definition with the specified name
88 *
89 * @param name The name of the role definition
90 *
91 */
92 getByName(name) {
93 return RoleDefinition(this, `getbyname('${name}')`);
94 }
95 /**
96 * Gets the role definition with the specified role type
97 *
98 * @param roleTypeKind The roletypekind of the role definition (None=0, Guest=1, Reader=2, Contributor=3, WebDesigner=4, Administrator=5, Editor=6, System=7)
99 *
100 */
101 getByType(roleTypeKind) {
102 return RoleDefinition(this, `getbytype(${roleTypeKind})`);
103 }
104 /**
105 * Creates a role definition
106 *
107 * @param name The new role definition's name
108 * @param description The new role definition's description
109 * @param order The order in which the role definition appears
110 * @param basePermissions The permissions mask for this role definition, high and low values need to be converted to string
111 *
112 */
113 async add(name, description, order, basePermissions) {
114 const postBody = body({
115 BasePermissions: { "High": basePermissions.High.toString(), "Low": basePermissions.Low.toString() },
116 Description: description,
117 Name: name,
118 Order: order,
119 });
120 // __metadata: { "type": "SP.RoleDefinition" },
121 const data = await spPost(this, postBody);
122 return {
123 data: data,
124 definition: this.getById(data.Id),
125 };
126 }
127};
128_RoleDefinitions = __decorate([
129 defaultPath("roledefinitions")
130], _RoleDefinitions);
131export { _RoleDefinitions };
132export const RoleDefinitions = spInvokableFactory(_RoleDefinitions);
133/**
134 * Describes a role definition
135 *
136 */
137export class _RoleDefinition extends _SPInstance {
138 constructor() {
139 super(...arguments);
140 this.delete = deleteable();
141 }
142 /**
143 * Updates this role definition with the supplied properties
144 *
145 * @param properties A plain object hash of values to update for the role definition
146 */
147 async update(properties) {
148 const s = ["BasePermissions"];
149 if (hOP(properties, s[0]) !== undefined) {
150 const bpObj = properties[s[0]];
151 bpObj.High = bpObj.High.toString();
152 bpObj.Low = bpObj.Low.toString();
153 }
154 const data = await spPostMerge(this, body(properties));
155 let definition = this;
156 if (hOP(properties, "Name")) {
157 const parent = this.getParent(RoleDefinitions);
158 definition = parent.getByName(properties.Name);
159 }
160 return {
161 data,
162 definition,
163 };
164 }
165}
166export const RoleDefinition = spInvokableFactory(_RoleDefinition);
167export var PermissionKind;
168(function (PermissionKind) {
169 /**
170 * Has no permissions on the Site. Not available through the user interface.
171 */
172 PermissionKind[PermissionKind["EmptyMask"] = 0] = "EmptyMask";
173 /**
174 * View items in lists, documents in document libraries, and Web discussion comments.
175 */
176 PermissionKind[PermissionKind["ViewListItems"] = 1] = "ViewListItems";
177 /**
178 * Add items to lists, documents to document libraries, and Web discussion comments.
179 */
180 PermissionKind[PermissionKind["AddListItems"] = 2] = "AddListItems";
181 /**
182 * Edit items in lists, edit documents in document libraries, edit Web discussion comments
183 * in documents, and customize Web Part Pages in document libraries.
184 */
185 PermissionKind[PermissionKind["EditListItems"] = 3] = "EditListItems";
186 /**
187 * Delete items from a list, documents from a document library, and Web discussion
188 * comments in documents.
189 */
190 PermissionKind[PermissionKind["DeleteListItems"] = 4] = "DeleteListItems";
191 /**
192 * Approve a minor version of a list item or document.
193 */
194 PermissionKind[PermissionKind["ApproveItems"] = 5] = "ApproveItems";
195 /**
196 * View the source of documents with server-side file handlers.
197 */
198 PermissionKind[PermissionKind["OpenItems"] = 6] = "OpenItems";
199 /**
200 * View past versions of a list item or document.
201 */
202 PermissionKind[PermissionKind["ViewVersions"] = 7] = "ViewVersions";
203 /**
204 * Delete past versions of a list item or document.
205 */
206 PermissionKind[PermissionKind["DeleteVersions"] = 8] = "DeleteVersions";
207 /**
208 * Discard or check in a document which is checked out to another user.
209 */
210 PermissionKind[PermissionKind["CancelCheckout"] = 9] = "CancelCheckout";
211 /**
212 * Create, change, and delete personal views of lists.
213 */
214 PermissionKind[PermissionKind["ManagePersonalViews"] = 10] = "ManagePersonalViews";
215 /**
216 * Create and delete lists, add or remove columns in a list, and add or remove public views of a list.
217 */
218 PermissionKind[PermissionKind["ManageLists"] = 12] = "ManageLists";
219 /**
220 * View forms, views, and application pages, and enumerate lists.
221 */
222 PermissionKind[PermissionKind["ViewFormPages"] = 13] = "ViewFormPages";
223 /**
224 * Make content of a list or document library retrieveable for anonymous users through SharePoint search.
225 * The list permissions in the site do not change.
226 */
227 PermissionKind[PermissionKind["AnonymousSearchAccessList"] = 14] = "AnonymousSearchAccessList";
228 /**
229 * Allow users to open a Site, list, or folder to access items inside that container.
230 */
231 PermissionKind[PermissionKind["Open"] = 17] = "Open";
232 /**
233 * View pages in a Site.
234 */
235 PermissionKind[PermissionKind["ViewPages"] = 18] = "ViewPages";
236 /**
237 * Add, change, or delete HTML pages or Web Part Pages, and edit the Site using
238 * a Windows SharePoint Services compatible editor.
239 */
240 PermissionKind[PermissionKind["AddAndCustomizePages"] = 19] = "AddAndCustomizePages";
241 /**
242 * Apply a theme or borders to the entire Site.
243 */
244 PermissionKind[PermissionKind["ApplyThemeAndBorder"] = 20] = "ApplyThemeAndBorder";
245 /**
246 * Apply a style sheet (.css file) to the Site.
247 */
248 PermissionKind[PermissionKind["ApplyStyleSheets"] = 21] = "ApplyStyleSheets";
249 /**
250 * View reports on Site usage.
251 */
252 PermissionKind[PermissionKind["ViewUsageData"] = 22] = "ViewUsageData";
253 /**
254 * Create a Site using Self-Service Site Creation.
255 */
256 PermissionKind[PermissionKind["CreateSSCSite"] = 23] = "CreateSSCSite";
257 /**
258 * Create subsites such as team sites, Meeting Workspace sites, and Document Workspace sites.
259 */
260 PermissionKind[PermissionKind["ManageSubwebs"] = 24] = "ManageSubwebs";
261 /**
262 * Create a group of users that can be used anywhere within the site collection.
263 */
264 PermissionKind[PermissionKind["CreateGroups"] = 25] = "CreateGroups";
265 /**
266 * Create and change permission levels on the Site and assign permissions to users
267 * and groups.
268 */
269 PermissionKind[PermissionKind["ManagePermissions"] = 26] = "ManagePermissions";
270 /**
271 * Enumerate files and folders in a Site using Microsoft Office SharePoint Designer
272 * and WebDAV interfaces.
273 */
274 PermissionKind[PermissionKind["BrowseDirectories"] = 27] = "BrowseDirectories";
275 /**
276 * View information about users of the Site.
277 */
278 PermissionKind[PermissionKind["BrowseUserInfo"] = 28] = "BrowseUserInfo";
279 /**
280 * Add or remove personal Web Parts on a Web Part Page.
281 */
282 PermissionKind[PermissionKind["AddDelPrivateWebParts"] = 29] = "AddDelPrivateWebParts";
283 /**
284 * Update Web Parts to display personalized information.
285 */
286 PermissionKind[PermissionKind["UpdatePersonalWebParts"] = 30] = "UpdatePersonalWebParts";
287 /**
288 * Grant the ability to perform all administration tasks for the Site as well as
289 * manage content, activate, deactivate, or edit properties of Site scoped Features
290 * through the object model or through the user interface (UI). When granted on the
291 * root Site of a Site Collection, activate, deactivate, or edit properties of
292 * site collection scoped Features through the object model. To browse to the Site
293 * Collection Features page and activate or deactivate Site Collection scoped Features
294 * through the UI, you must be a Site Collection administrator.
295 */
296 PermissionKind[PermissionKind["ManageWeb"] = 31] = "ManageWeb";
297 /**
298 * Content of lists and document libraries in the Web site will be retrieveable for anonymous users through
299 * SharePoint search if the list or document library has AnonymousSearchAccessList set.
300 */
301 PermissionKind[PermissionKind["AnonymousSearchAccessWebLists"] = 32] = "AnonymousSearchAccessWebLists";
302 /**
303 * Use features that launch client applications. Otherwise, users must work on documents
304 * locally and upload changes.
305 */
306 PermissionKind[PermissionKind["UseClientIntegration"] = 37] = "UseClientIntegration";
307 /**
308 * Use SOAP, WebDAV, or Microsoft Office SharePoint Designer interfaces to access the Site.
309 */
310 PermissionKind[PermissionKind["UseRemoteAPIs"] = 38] = "UseRemoteAPIs";
311 /**
312 * Manage alerts for all users of the Site.
313 */
314 PermissionKind[PermissionKind["ManageAlerts"] = 39] = "ManageAlerts";
315 /**
316 * Create e-mail alerts.
317 */
318 PermissionKind[PermissionKind["CreateAlerts"] = 40] = "CreateAlerts";
319 /**
320 * Allows a user to change his or her user information, such as adding a picture.
321 */
322 PermissionKind[PermissionKind["EditMyUserInfo"] = 41] = "EditMyUserInfo";
323 /**
324 * Enumerate permissions on Site, list, folder, document, or list item.
325 */
326 PermissionKind[PermissionKind["EnumeratePermissions"] = 63] = "EnumeratePermissions";
327 /**
328 * Has all permissions on the Site. Not available through the user interface.
329 */
330 PermissionKind[PermissionKind["FullMask"] = 65] = "FullMask";
331})(PermissionKind || (PermissionKind = {}));
332//# sourceMappingURL=types.js.map
\No newline at end of file