Sharepoint学习笔记—ECMAScript对象模型系列-- 9、组与用户操作(二)
接着上面的继续,这里我们描述的关于User与Group的操作如下:
6、 向指定Group中添加指定User
7、 获取指定Group的Owner
8、 把当前登录用户添加到指定Group中
9、 判断当前登录用户是否有EditPermission权限
10、判断当前登录用户是否在某特定的Group中
分别描述如下:
6、 向指定Group中添加指定User
function addUserToSharePointGroup(groupID) {
//var clientContext = new SP.ClientContext(siteUrl);
var clientContext = new SP.ClientContext.get_current();
var collGroup = clientContext.get_web().get_siteGroups();
var oGroup = collGroup.getById(groupID);
var userCreationInfo = new SP.UserCreationInformation();
userCreationInfo.set_email('helpdesk@GLSTAR.COM.AU);
userCreationInfo.set_loginName('GLSTAR\\helpdesk');
userCreationInfo.set_title('helpdesk');
this.oUser = oGroup.get_users().add(userCreationInfo); //add user into group
// var userInfo = '\nUser: ' + oUser.get_title() +
// '\nEmail: ' + oUser.get_email() +
// '\nLogin Name: ' + oUser.get_loginName();
// alert(userInfo);
clientContext.load(oUser);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceededaddUserToSharePointGroup),
Function.createDelegate(this, this.onQueryFailedaddUserToSharePointGroup));
}
function onQuerySucceededaddUserToSharePointGroup() {
alert(this.oUser.get_title() + " added.");
}
function onQueryFailedaddUserToSharePointGroup(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
7、 获取指定Group的Owner
var group;
function getGroupOwnerName(groupID) {
var clientContext = new SP.ClientContext();
var groupCollection = clientContext.get_web().get_siteGroups();
group = groupCollection.getById(groupID);
clientContext.load(group);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceededgetGroupOwnerName),
Function.createDelegate(this, this.onQueryFailedgetGroupOwnerName));
}
function onQuerySucceededgetGroupOwnerName() {
alert("GroupTitle: " + group.get_title() + "\nGroupOwnerTitle : " + group.get_ownerTitle());
}
function onQueryFailedgetGroupOwnerName(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
8、 把当前登录用户添加到指定Group中
var currentUser;
var visitorsGroup;
function addUserToSpecificGroupInCurrWeb(groupID) {
var clientContext = new SP.ClientContext();
var groupCollection = clientContext.get_web().get_siteGroups();
visitorsGroup = groupCollection.getById(groupID);
currentUser = clientContext.get_web().get_currentUser();
var userCollection = visitorsGroup.get_users();
userCollection.addUser(currentUser);
clientContext.load(currentUser);
clientContext.load(visitorsGroup);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceededaddUserToSpecificGroup),
Function.createDelegate(this, this.onQueryFailedaddUserToSpecificGroup));
}
function onQuerySucceededaddUserToSpecificGroup() {
alert(currentUser.get_title() + " added to group " + visitorsGroup.get_title());
}
function onQueryFailedaddUserToSpecificGroup(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
9、 判断当前登录用户是否有EditPermission权限
var theCurrentUser;
var theWeb;
function checkifUserHasEditPermissions() {
// debugger;
var context = new SP.ClientContext.get_current();
theWeb = context.get_web();
theCurrentUser = theWeb.get_currentUser();
context.load(theCurrentUser);
context.load(theWeb, 'EffectiveBasePermissions');
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethodcheckEditPermissions),
Function.createDelegate(this, this.onFailureMethodcheckEditPermissions));
}
function onSuccessMethodcheckEditPermissions() {
//debugger;
if (theWeb.get_effectiveBasePermissions().has(SP.PermissionKind.editListItems)) {
//User Has Edit Permissions
alert(theCurrentUser.get_loginName()+"Has Edit Permission on current website");
}
else {
alert("No Edit Permission");
}
}
function onFailureMethodcheckEditPermissions() {
alert("Failed to check permission");
}
10、判断当前登录用户是否在某特定的Group中
// The below checks if the user exists in the group
function checkIfCurrentUserIsInGroup(groupID) {
var context = SP.ClientContext.get_current();
//I go to parent site if I'm in a subsite!
var siteColl = context.get_site();
var web = siteColl.get_rootWeb();
var groupCollection = web.get_siteGroups();
// Get the Our Group's ID
var _group = groupCollection.getById(groupID); // ID of the Group that we are checking
var users = _group.get_users(); // Get all Users of the group
context.load(_group);
context.load(users);
this._users = users;
this._currentUser = web.get_currentUser(); // Get current user
context.load(this._currentUser);
context.executeQueryAsync(Function.createDelegate(this, this.CheckUserSucceededUserIsInGroup),
Function.createDelegate(this, this.CheckUserfailedUserIsInGroup));
}
//The below Checks if User is the member of the specified group
function CheckUserSucceededUserIsInGroup() {
//debugger;
IsInThisGroupFlag = false;
if (this._users.get_count() > 0) {
var _usersEnum = this._users.getEnumerator();
while (_usersEnum.moveNext()) {
var user = _usersEnum.get_current();
if (user.get_loginName() == this._currentUser.get_loginName()) {
//debugger;
IsInThisGroupFlag = true;
}
if (IsInThisGroupFlag) {
alert(user.get_loginName() + " exist in the checked group " + IsInThisGroupFlag.toString());
}
else {
alert(user.get_loginName() + " not exist in the checked group ");
}
}
}
}
function CheckUserfailedUserIsInGroup() {
alert('failed');
}
转载于:https://www.cnblogs.com/wsdj-ITtech/archive/2012/06/09/2426504.html
Sharepoint学习笔记—ECMAScript对象模型系列-- 9、组与用户操作(二)相关推荐
- Sharepoint学习笔记—ECMAScript对象模型系列-- 7、获取和修改List的Lookup字段
在前面我们提到了如何使用ECMAscript对象模型来操作普通的List Items,但如果我们操作的List包含有Lookup字段,那么我们又该怎么做呢? 首先参考此文搭建我们本文的测试环境 Sha ...
- Sharepoint学习笔记—ECMAScript对象模型系列-- 8、组与用户操作(一)
这里总结一下关于使用ECMAscript对象模型来操作Goup与User的常用情况,因为内容较多,所以拆分为两个部分,这部分主要内容如下: 1.取得当前Sharepoint网站所有的Grou ...
- Sharepoint学习笔记—Site Definition系列-- 2、创建Content Type
Sharepoint本身就是一个丰富的大容器,里面存储的所有信息我们可以称其为"内容(Content)",为了便于管理这些Conent,按照人类的正常逻辑就必然想到的是对此进行&q ...
- Sharepoint学习笔记—Site Definition系列-- 3、创建ListDefinition
创建一个List Definition有多条途径,这里由于我们要基于前面的用户自定义Content Type来创建一个List Defintion,所以我们就需要使用到List Definition ...
- Sharepoint学习笔记—Site Definition系列-- 5、List Definition与List Template之比较
在上一篇我们试图通过List Template来帮助我们相对较快的创建我们List Definition中的Schema.xml文件,你可能会发现,我们并不能照搬List Template中相应的定义 ...
- Sharepoint学习笔记—Site Definition系列-- 1、创建Site Columns
https://www.cnblogs.com/wsdj-ITtech/archive/2012/08/12/2470219.html Site Columns是Sharepoint网站的一个重要底层 ...
- sharepoint ECMAScript对象模型系列
转载:Sharepoint学习笔记-ECMAScript对象模型系列-- 8.组与用户操作(一) http://www.cnblogs.com/wsdj-ITtech/archive/2012/06/ ...
- Sharepoint学习笔记—Ribbon系列-- 2. 在Ribbon中添加新Tab
有了上面的基础,我们来看看如何向Sharepoint网站的Ribbon中添加我们定义的Tab. 直接进入操作步骤 一.创建 SharePoint 项目 要添加新选项卡,应首先创建一个空白 ShareP ...
- Sharepoint学习笔记—架构系列
为便于查阅,这里整理并列出了我的Sharepoint学习笔记中涉及架构方面的有关文章,有些内容可能会在以后更新. Sharepoin学习笔记-架构系列-- Sharepoint的网页(Page), ...
最新文章
- APUE学习笔记-11.5线程终止
- wingide 显示中文 及 配色方案
- DFS、栈、双向队列:CF264A- Escape from Stones
- ThreadLocal到底有没有内存泄漏?
- .net怎么读_想考UKVI不知道怎么报名?亲亲,这边建议你阅读全文并收藏呢
- 《iOS 6核心开发手册(第4版)》——2.11节秘诀:构建星星滑块
- python中的reg_如何在python中从注册表读取字符串格式的Reg_二进制类型值
- 从支付宝SDK的支付流程理解什么是公钥和私钥,什么是加密和数字签名
- 更改VS2010,VS2008,VS2012等指定默认浏览器操作方式
- C/C++调用python,opencv+python
- Linux Unix shell 编程指南学习笔记(第二部分)
- 【勒索病毒数据恢复】Phobos勒索病毒家族之.[back23@vpn.tg].makop
- leapftp,小编悄悄告诉你leapftp是什么
- arm920t内核技术手册
- 计算机语言中double是什么意思,C语言中double是什么意思?_后端开发
- 并行数据转换为串行数据的转换器
- 点,线,面,透视(手绘课)
- 论文阅读:Contextual Translation Embedding for Visual Relationship Detection and SGG(PAMI2020)
- 14、Spark_RDD算子——CombineByKey_ReduceByKey转换
- 【论文阅读】Long-term Temporal Convolutions for Action Recognition
热门文章
- python中fn的用法_Pytorch技巧:DataLoader的collate_fn参数使用详解
- python安装pip_Python的pip安装总是失败怎么办?
- matlab ufunc,ufunc函数
- 注册app短信验证平台_短信验证码平台能免费测试吗?怎么测试?
- 新网 云服务器,新网云服务器的优势包括什么?
- elment-ui 表格进行实时百分比计算
- python在列表末尾删除一个_从链接列表的尾部移除(Python)
- .net core 微服务通讯组件Orleans的使用与配置
- 10种避免大型部署的方法
- mysql中find_in_set()函数的使用