Example #1
0
        public static void AddUpdateRole(string roleName, bool hasRead, bool hasEdit, bool hasPublish)
        {
            RolePermissions permissions = new RolePermissions();

            permissions.RoleName   = roleName;
            permissions.HasRead    = hasRead;
            permissions.HasEdit    = hasEdit;
            permissions.HasPublish = hasPublish;
            permissions.Save();

            RolePermissionManager.MarkDirty();

            // Add role to other membership databases
            controller.AddRole(roleName);
        }
Example #2
0
        public static void AddUpdateRole(string roleName, int categoryID, bool hasRead, bool hasEdit, bool hasPublish)
        {
            RoleCategoryPermissions rcp = new RoleCategoryPermissions();

            rcp.RoleName   = roleName;
            rcp.HasRead    = hasRead;
            rcp.HasEdit    = hasEdit;
            rcp.HasPublish = hasPublish;
            rcp.CategoryId = categoryID;
            rcp.Save();

            RolePermissionManager.MarkDirty();

            // Add role to other membership databases
            controller.AddRole(roleName);
        }
Example #3
0
        public static void DeleteRole(string roleName)
        {
            // Remove users from role
            List <IGraffitiUser> roleUsers = GraffitiUsers.GetUsers(roleName);

            if (roleUsers != null && roleUsers.Count > 0)
            {
                foreach (IGraffitiUser user in roleUsers)
                {
                    GraffitiUsers.RemoveUserFromRole(user.Name, roleName);
                }
            }

            RolePermissionsCollection         rp  = RolePermissionManager.GetRolePermissions();
            RoleCategoryPermissionsCollection rpc = RolePermissionManager.GetRoleCategoryPermissions();

            foreach (RolePermissions rperm in rp)
            {
                if (String.Compare(rperm.RoleName, roleName, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    RolePermissions.Destroy(RolePermissions.Columns.RoleName, rperm.RoleName);
                    break;
                }
            }

            foreach (RoleCategoryPermissions rcatperm in rpc)
            {
                if (String.Compare(rcatperm.RoleName, roleName, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    RoleCategoryPermissions.Destroy(RolePermissions.Columns.RoleName, rcatperm.RoleName);
                    break;
                }
            }

            RolePermissionManager.MarkDirty();

            // Remove role from other membership databases
            controller.DeleteRole(roleName);
        }