Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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)
        {
            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);
        }
Ejemplo n.º 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)
        {
            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);
        }
Ejemplo n.º 5
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);
        }