使用Web服务API确定SharePoint网站/工作区用户的角色 [英] Determining User's role in a SharePoint site/workspace using the webservices API

查看:104
本文介绍了使用Web服务API确定SharePoint网站/工作区用户的角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何找出在使用Web服务API网站的用户的角色(S)?我所去的是用户名和域名。

How do I figure out the role(s) of a user in a site using the webservices API? All I have to go on is the username and domain.

我发现PermissionsService.Permissions.GetPermissionCollection(URL,网络)将返回允许用户和组的集合与他们的权限,口罩,但我仍然需要弄清楚如果用户是在任何组然后转换权限面具到的角色集合。

I've found that the PermissionsService.Permissions.GetPermissionCollection(url,"Web") will return a collection of permitted users and groups with their permissions masks but I still need to figure out if the user is in any of the groups and then convert the permissions masks into a roles collection.

我觉得有一个更好的方式来做到这一点,我只是失踪了。

I feel like there's a better way to do this and I'm just missing it.

推荐答案

我已经解决了类似的东西 - 我的方法检查,如果用户分配一个特定的角色。这里的算法首先:

I've solved something similar - my method checks if user is assigned a specific role. Here's the algorithm first:


  1. 检查用户在一个网站直接分配角色

  2. 如果是 - 冷静,如果不是 - 让所有的团体用户中的一员,让那些该角色分配给它们的所有组

  3. 比较两个。如果有一个匹配 - 凉爽,如果不是 - 用户没有分配在该位点的水平的作用。

而code:

public bool IsAssignedAPermission(string premissionName, string userLoginName)
    {
        XmlNode nodes;
        bool isAssignedAPermission;

        isAssignedAPermission = false;

        //Check if user is directly assigned a Full Control role
        try
        {
            nodes = userGroupService.GetRoleCollectionFromUser(userLoginName);
            using (XmlNodeReader reader = new XmlNodeReader(nodes))
            {
                DataSet ds = new DataSet();
                ds.ReadXml(reader);
                DataTable dt = ds.Tables[1];
                foreach (DataRow row in dt.Rows)
                {
                    string permission = row[1].ToString();
                    if (permission == premissionName)
                    {
                        isAssignedAPermission = true;
                        break;
                    }
                }
            }
        }
        catch
        {
            List<string> groupMemberships;
            List<string> fullControlGroups;

            //Check if user is a member of a Full Control group
            //This is done in three steps:

            //1. Get the list of groups the user is member of
            groupMemberships = new List<string>();
            nodes = userGroupService.GetGroupCollectionFromUser(userLoginName);
            using (XmlNodeReader reader = new XmlNodeReader(nodes))
            {
                DataSet ds = new DataSet();
                ds.ReadXml(reader);
                DataTable dt = ds.Tables[1];
                foreach (DataRow row in dt.Rows)
                {
                    string groupName = row[1].ToString();
                    groupMemberships.Add(groupName);
                }
            }

            //2. Get the list of groups that have Full Control permissions
            fullControlGroups = new List<string>();
            nodes = userGroupService.GetGroupCollectionFromRole(premissionName);
            using (XmlNodeReader reader = new XmlNodeReader(nodes))
            {
                DataSet ds = new DataSet();
                ds.ReadXml(reader);
                DataTable dt = ds.Tables[1];
                foreach (DataRow row in dt.Rows)
                {
                    string groupName = row[1].ToString();
                    fullControlGroups.Add(groupName);
                }
            }

            //3. Check if user belongs to any of the Full Control groups
            foreach (string membership in groupMemberships)
            {
                if (fullControlGroups.Contains(membership))
                {
                    isAssignedAPermission = true;
                    break;
                }
            }
        }

        return isAssignedAPermission;
    }

方法参数userLoginName应该是在一个domain \\ username形式,例如SHAREPOINT \\鲍里斯。我希望我帮助。干杯

Method parameter userLoginName should be in a form domain\username, e.g. SHAREPOINT\Boris. I hope I helped. Cheers

这篇关于使用Web服务API确定SharePoint网站/工作区用户的角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆