基于用户组限制共享点列表中的项目 [英] restrict items in a sharepoint list based on users group

查看:52
本文介绍了基于用户组限制共享点列表中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好, 我们有一个sharePoint列表,其中包含敏感数据,并希望根据用户组来限制用户可以查看的内容.

Hi,  we have a sharePoint list that has sensitive data and want to restrict what users can view based on their user group.

我们有20多个小组.我最初想到的是具有目标受众的Webpart,但是基于小组的数目,我认为必须有更好的方法?

We have over 20 groups.  I initially thought of webparts with target audience, but based on number of groups was thinking there must be a better approach?

推荐答案

我们可以通过JavaScript来实现.我们可以添加一个脚本编辑器"将Web部件插入页面以插入我们的JS代码.

We can achieve this via JavaScript. We can add a "Script Editor" Web part into page to insert our JS code.

这是一个演示供您参考.

Here is a demo for your reference.

    <script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js"></script>
    <script type="text/javascript">

        //get all users of group
        function getUsersOfGroup(groupName) {
            var users;


.ajax({ 类型:"GET", //这里您需要将网址修改为实际的网站网址 网址:"/sites/LeeLiuDevSite/_api/web/sitegroups/getbyname('+ quot; groupName +"')/users', 标头:{ "Accept":"application/json; odata = verbose", }, dataType:"json", 异步:假, 成功:功能(数据){ 用户= data.d.results; } }); 回头客; }
.ajax({ type: "GET", //here you need to modify the url to be your actual site url url: "/sites/LeeLiuDevSite/_api/web/sitegroups/getbyname('" + groupName + "')/users", headers: { "Accept": "application/json; odata=verbose", }, dataType: "json", async:false, success: function (data) { users = data.d.results; } }); return users; }


(function(){ var users = getUsersOfGroup("Test"); //获取当前用户ID var currentUserId = _spPageContextInfo.userId; var hasPermission = true; for(var x = 0; x< users.length; x ++){ var id = users [0] .Id; 如果(currentUserId == users [0] .Id){ hasPermission = false; } } 如果(!hasPermission){ //没有权限,限制 //....... } }); </script>
(function () { var users = getUsersOfGroup("Test"); //get current user id var currentUserId = _spPageContextInfo.userId; var hasPermission = true; for (var x = 0; x < users.length; x++) { var id = users[0].Id; if (currentUserId == users[0].Id) { hasPermission = false; } } if (!hasPermission) { //don't has permission, restrict //....... } }); </script>

Chrome中的调试屏幕截图.

Screenshot of debug in Chrome.

最诚挚的问候,

刘李


这篇关于基于用户组限制共享点列表中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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