UNPKG

@pnp/sp

Version:

pnp - provides a fluent api for working with SharePoint REST

92 lines 2.59 kB
import { __decorate } from "tslib"; import { _SPCollection, spInvokableFactory, _SPInstance, deleteable, spPost, spPostMerge, } from "../spqueryable.js"; import { SiteGroups } from "../site-groups/types.js"; import { body } from "@pnp/queryable"; import { defaultPath } from "../decorators.js"; let _SiteUsers = class _SiteUsers extends _SPCollection { /** * Gets a user from the collection by id * * @param id The id of the user to retrieve */ getById(id) { return SiteUser(this, `getById(${id})`); } /** * Gets a user from the collection by email * * @param email The email address of the user to retrieve */ getByEmail(email) { return SiteUser(this, `getByEmail('${email}')`); } /** * Gets a user from the collection by login name * * @param loginName The login name of the user to retrieve * e.g. SharePoint Online: 'i:0#.f|membership|user@domain' */ getByLoginName(loginName) { return SiteUser(this).concat(`('!@v::${loginName}')`); } /** * Removes a user from the collection by id * * @param id The id of the user to remove */ removeById(id) { return spPost(SiteUsers(this, `removeById(${id})`)); } /** * Removes a user from the collection by login name * * @param loginName The login name of the user to remove */ removeByLoginName(loginName) { const o = SiteUsers(this, "removeByLoginName(@v)"); o.query.set("@v", `'${loginName}'`); return spPost(o); } /** * Adds a user to a site collection * * @param loginName The login name of the user to add to a site collection * */ async add(loginName) { await spPost(this, body({ LoginName: loginName })); return this.getByLoginName(loginName); } }; _SiteUsers = __decorate([ defaultPath("siteusers") ], _SiteUsers); export { _SiteUsers }; export const SiteUsers = spInvokableFactory(_SiteUsers); /** * Describes a single user * */ export class _SiteUser extends _SPInstance { constructor() { super(...arguments); this.delete = deleteable(); } /** * Gets the groups for this user * */ get groups() { return SiteGroups(this, "groups"); } /** * Updates this user * * @param props Group properties to update */ async update(props) { return spPostMerge(this, body(props)); } } export const SiteUser = spInvokableFactory(_SiteUser); //# sourceMappingURL=types.js.map