当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Web.hasPermissions方法代码示例

本文整理汇总了TypeScript中sp-pnp-js.Web.hasPermissions方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Web.hasPermissions方法的具体用法?TypeScript Web.hasPermissions怎么用?TypeScript Web.hasPermissions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sp-pnp-js.Web的用法示例。


在下文中一共展示了Web.hasPermissions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: getCurrentUserPermissionsOnList

    public async getCurrentUserPermissionsOnList(listServerRelativeUrl: string): Promise<DiscussionPermissionLevel[]> {

        const permissionsList = [];

        const web = new Web(_spPageContextInfo.webAbsoluteUrl);
        const permissions = await web.getList(listServerRelativeUrl).getCurrentUserEffectivePermissions();
        const canAddListItems = web.hasPermissions(permissions, PermissionKind.AddListItems);
        const canManageLists = web.hasPermissions(permissions, PermissionKind.ManageLists);

        if (canAddListItems) {
            permissionsList.push(DiscussionPermissionLevel.Add);
        }

        if (canManageLists) {
            permissionsList.push(DiscussionPermissionLevel.ManageLists);
        }

        return permissionsList;
    }
开发者ID:ScoutmanPt,项目名称:PnP,代码行数:19,代码来源:SocialModule.ts

示例2: getCurrentUserPermissionsOnItem

    /**
     * Gets the current user permnissions on a reply
     * @param itemId the item id
     * @param replyAuthorLoginName the reply auhtor name (to check if the current user is the actual author)
     */
    private async getCurrentUserPermissionsOnItem(itemId: number, replyAuthorLoginName: string): Promise<DiscussionPermissionLevel[]> {

        const permissionsList = [];

        const web = new Web(_spPageContextInfo.webAbsoluteUrl);
        const permissions = await web.getList(this.discussionListServerRelativeUrl).items.getById(itemId).getCurrentUserEffectivePermissions();

        const canAddListItems = web.hasPermissions(permissions, PermissionKind.AddListItems);
        const canEditListItems = web.hasPermissions(permissions, PermissionKind.EditListItems);
        const canDeleteListItems = web.hasPermissions(permissions, PermissionKind.DeleteListItems);
        const canManageLists = web.hasPermissions(permissions, PermissionKind.ManageLists);

        if (canManageLists) {
            permissionsList.push(DiscussionPermissionLevel.ManageLists);
            permissionsList.push(DiscussionPermissionLevel.Delete);
            permissionsList.push(DiscussionPermissionLevel.Edit);
        }

        if ((canEditListItems && !canManageLists) || (canDeleteListItems && !canManageLists)) {

            pnp.storage.local.deleteExpired();

            // The "WriteSecurity" property isn't availabe through REST with SharePoint 2013. In this case, we need to get the whole list XML schema to extract this info
            // Not very efficient but we do not have any other option here
            // Not List Item Level Security is different than item permissions so we can't rely on native REST methods (i.e. getCurrentUserEffectivePermissions())
            const writeSecurityStorageKey = String.format("{0}_{1}", _spPageContextInfo.webServerRelativeUrl, "commentsListWriteSecurity");
            let writeSecurity = pnp.storage.local.get(writeSecurityStorageKey);

            if (!writeSecurity) {
                const  list = await web.getList(this.discussionListServerRelativeUrl).select("SchemaXml").get();
                // tslint:disable-next-line:radix
                writeSecurity = parseInt(/WriteSecurity="(\d)"/.exec(list.SchemaXml)[1]);

                pnp.storage.local.put(writeSecurityStorageKey, writeSecurity, pnp.util.dateAdd(new Date(), "minute", 60));
            }

            // 2 = Create items and edit items that were created by the user
            if (writeSecurity === 2) {

                const userLoginNameStorageKey = String.format("{0}_{1}", _spPageContextInfo.webServerRelativeUrl, "currentUserLoginName");
                let currentUserLoginName = pnp.storage.local.get(userLoginNameStorageKey);
                if (!currentUserLoginName) {
                    const currentUser = await web.currentUser.select("LoginName").get();
                    currentUserLoginName = currentUser.LoginName;
                    pnp.storage.local.put(userLoginNameStorageKey, currentUserLoginName, pnp.util.dateAdd(new Date(), "minute", 20));
                }

                // If the current user is the author of the comment
                if (replyAuthorLoginName === currentUserLoginName) {

                    if (canEditListItems) {
                        permissionsList.push(DiscussionPermissionLevel.EditAsAuthor);
                    }

                    if (canDeleteListItems) {
                        permissionsList.push(DiscussionPermissionLevel.DeleteAsAuthor);
                    }
                }
            } else {
                if (canDeleteListItems) {
                    permissionsList.push(DiscussionPermissionLevel.Delete);
                }

                if (canEditListItems) {
                    permissionsList.push(DiscussionPermissionLevel.Edit);
                }
            }
        }

        if (canAddListItems) {
            permissionsList.push(DiscussionPermissionLevel.Add);
        }

        return permissionsList;
    }
开发者ID:ScoutmanPt,项目名称:PnP,代码行数:80,代码来源:SocialModule.ts


注:本文中的sp-pnp-js.Web.hasPermissions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。