UNPKG

2.69 kBJavaScriptView Raw
1import { __decorate } from "tslib";
2import { _SPCollection, spInvokableFactory, _SPInstance, deleteable, } from "../spqueryable.js";
3import { SiteGroups } from "../site-groups/types.js";
4import { body } from "@pnp/queryable";
5import { defaultPath } from "../decorators.js";
6import { spPost, spPostMerge } from "../operations.js";
7let _SiteUsers = class _SiteUsers extends _SPCollection {
8 /**
9 * Gets a user from the collection by id
10 *
11 * @param id The id of the user to retrieve
12 */
13 getById(id) {
14 return SiteUser(this, `getById(${id})`);
15 }
16 /**
17 * Gets a user from the collection by email
18 *
19 * @param email The email address of the user to retrieve
20 */
21 getByEmail(email) {
22 return SiteUser(this, `getByEmail('${email}')`);
23 }
24 /**
25 * Gets a user from the collection by login name
26 *
27 * @param loginName The login name of the user to retrieve
28 */
29 getByLoginName(loginName) {
30 return SiteUser(this).concat(`('!@v::${encodeURIComponent(loginName)}')`);
31 }
32 /**
33 * Removes a user from the collection by id
34 *
35 * @param id The id of the user to remove
36 */
37 removeById(id) {
38 return spPost(SiteUsers(this, `removeById(${id})`));
39 }
40 /**
41 * Removes a user from the collection by login name
42 *
43 * @param loginName The login name of the user to remove
44 */
45 removeByLoginName(loginName) {
46 const o = SiteUsers(this, "removeByLoginName(@v)");
47 o.query.set("@v", `'${encodeURIComponent(loginName)}'`);
48 return spPost(o);
49 }
50 /**
51 * Adds a user to a site collection
52 *
53 * @param loginName The login name of the user to add to a site collection
54 *
55 */
56 async add(loginName) {
57 await spPost(this, body({ LoginName: loginName }));
58 return this.getByLoginName(loginName);
59 }
60};
61_SiteUsers = __decorate([
62 defaultPath("siteusers")
63], _SiteUsers);
64export { _SiteUsers };
65export const SiteUsers = spInvokableFactory(_SiteUsers);
66/**
67 * Describes a single user
68 *
69 */
70export class _SiteUser extends _SPInstance {
71 constructor() {
72 super(...arguments);
73 this.delete = deleteable();
74 }
75 /**
76 * Gets the groups for this user
77 *
78 */
79 get groups() {
80 return SiteGroups(this, "groups");
81 }
82 /**
83 * Updates this user
84 *
85 * @param props Group properties to update
86 */
87 async update(props) {
88 const data = await spPostMerge(this, body(props));
89 return {
90 data,
91 user: this,
92 };
93 }
94}
95export const SiteUser = spInvokableFactory(_SiteUser);
96//# sourceMappingURL=types.js.map
\No newline at end of file