/// <summary>
        /// Add a permission level (e.g.Contribute, Reader,...) to a group
        /// </summary>
        /// <param name="web">Web to operate against</param>
        /// <param name="groupName">Name of the group</param>
        /// <param name="permissionLevel">Permission level to add</param>
        /// <param name="removeExistingPermissionLevels">Set to true to remove all other permission levels for that group</param>
        public static void AddPermissionLevelToGroup(this Web web, string groupName, RoleType permissionLevel, bool removeExistingPermissionLevels = false)
        {
            if (string.IsNullOrEmpty(groupName))
                throw new ArgumentNullException("groupName");

            var group = web.SiteGroups.GetByName(groupName);
            web.Context.Load(group);
            web.Context.ExecuteQuery();
            web.AddPermissionLevelImplementation(group, permissionLevel, removeExistingPermissionLevels);
        }
        /// <summary>
        /// Add a permission level (e.g.Contribute, Reader,...) to a user
        /// </summary>
        /// <param name="web">Web to operate against</param>
        /// <param name="userLoginName">Loginname of the user</param>
        /// <param name="permissionLevel">Permission level to add</param>
        /// <param name="removeExistingPermissionLevels">Set to true to remove all other permission levels for that user</param>
        public static void AddPermissionLevelToUser(this Web web, string userLoginName, RoleType permissionLevel, bool removeExistingPermissionLevels = false)
        {
            if (string.IsNullOrEmpty(userLoginName))
                throw new ArgumentNullException("userLoginName");

            User user = web.EnsureUser(userLoginName);
            web.Context.Load(user);
            web.Context.ExecuteQuery();
            web.AddPermissionLevelImplementation(user, permissionLevel, removeExistingPermissionLevels);
        }
        /// <summary>
        /// Add a role definition (e.g.Contribute, Read, Approve) to a group
        /// </summary>
        /// <param name="securableObject">Web/List/Item to operate against</param>
        /// <param name="principal">Principal to add permission to</param>
        /// <param name="roleDefinitionName">Name of the role definition to add, Full Control|Design|Contribute|Read|Approve|Manage Hierarchy|Restricted Read. Use the correct name of the language of the root site you are using</param>
        /// <param name="removeExistingPermissionLevels">Set to true to remove all other permission levels for that group</param>
        public static void AddPermissionLevelToPrincipal(this SecurableObject securableObject, Principal principal, string roleDefinitionName, bool removeExistingPermissionLevels = false)
        {
            if (principal == null)
                throw new ArgumentNullException("principal");

            if (string.IsNullOrEmpty(roleDefinitionName))
                throw new ArgumentNullException("roleDefinitionName");

            Web web = securableObject.GetAssociatedWeb();

            securableObject.Context.Load(principal);
            securableObject.Context.ExecuteQueryRetry();
            RoleDefinition roleDefinition = web.RoleDefinitions.GetByName(roleDefinitionName);
            securableObject.AddPermissionLevelImplementation(principal, roleDefinition, removeExistingPermissionLevels);
        }
Beispiel #4
0
 /// <summary>
 /// Add a permission level (e.g.Contribute, Reader,...) to a user
 /// </summary>
 /// <param name="web">Web to operate against</param>
 /// <param name="userLoginName">Loginname of the user</param>
 /// <param name="permissionLevel">Permission level to add</param>
 /// <param name="removeExistingPermissionLevels">Set to true to remove all other permission levels for that user</param>
 public static void AddPermissionLevelToUser(this Web web, string userLoginName, RoleType permissionLevel, bool removeExistingPermissionLevels = false)
 {
     User user = web.EnsureUser(userLoginName);
     web.Context.Load(user);
     web.Context.ExecuteQuery();
     web.AddPermissionLevelImplementation(user, permissionLevel, removeExistingPermissionLevels);
 }
Beispiel #5
0
 /// <summary>
 /// Add a permission level (e.g.Contribute, Reader,...) to a group
 /// </summary>
 /// <param name="web">Web to operate against</param>
 /// <param name="groupName">Name of the group</param>
 /// <param name="permissionLevel">Permission level to add</param>
 /// <param name="removeExistingPermissionLevels">Set to true to remove all other permission levels for that group</param>
 public static void AddPermissionLevelToGroup(this Web web, string groupName, RoleType permissionLevel, bool removeExistingPermissionLevels = false)
 {
     var group = web.SiteGroups.GetByName(groupName);
     web.Context.Load(group);
     web.Context.ExecuteQuery();
     web.AddPermissionLevelImplementation(group, permissionLevel, removeExistingPermissionLevels);
 }
Beispiel #6
0
        /// <summary>
        /// Add a role definition (e.g.Contribute, Read, Approve) to a user
        /// </summary>
        /// <param name="web">Web to operate against</param>
        /// <param name="userLoginName">Loginname of the user</param>
        /// <param name="roleDefinitionName">Name of the role definition to add, Full Control|Design|Contribute|Read|Approve|Manage Hierarchy|Restricted Read. Use the correct name of the language of the root site you are using</param>
        /// <param name="removeExistingPermissionLevels">Set to true to remove all other permission levels for that user</param>
        public static void AddPermissionLevelToUser(this Web web, string userLoginName, string roleDefinitionName, bool removeExistingPermissionLevels = false)
        {
            if (string.IsNullOrEmpty(userLoginName))
                throw new ArgumentNullException("userLoginName");

            if (string.IsNullOrEmpty(userLoginName))
                throw new ArgumentNullException("roleDefinitionName");

            User user = web.EnsureUser(userLoginName);
            web.Context.Load(user);
            web.Context.ExecuteQueryRetry();
            RoleDefinition roleDefinition = web.RoleDefinitions.GetByName(roleDefinitionName);
            web.AddPermissionLevelImplementation(user, roleDefinition, removeExistingPermissionLevels);
        }