Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
    protected void CategoryList_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        string roleName = DecodeFromQS("role");

        Category    category     = e.Item.DataItem as Category;
        HiddenField cat          = e.Item.FindControl("categoryId") as HiddenField;
        Label       categoryName = e.Item.FindControl("categoryName") as Label;

        if (cat != null && category != null)
        {
            cat.Value = category.Id.ToString();
        }

        if (categoryName != null && category != null)
        {
            categoryName.Text = category.ParentId > 0 ? category.Parent.Name + " - " + category.Name : category.Name;
        }

        CheckBox read    = e.Item.FindControl("readRoleCatPermission") as CheckBox;
        CheckBox edit    = e.Item.FindControl("editRoleCatPermission") as CheckBox;
        CheckBox publish = e.Item.FindControl("publishRoleCatPermission") as CheckBox;

        if (read != null && edit != null && publish != null)
        {
            SetupTogglePermissionsScript(read, edit, publish, read, "read");
            SetupTogglePermissionsScript(read, edit, publish, edit, "edit");
            SetupTogglePermissionsScript(read, edit, publish, publish, "publish");

            RoleCategoryPermissionsCollection rpc = RolePermissionManager.GetRoleCategoryPermissions();

            RoleCategoryPermissions rp = rpc.Find(
                delegate(RoleCategoryPermissions rcper)
            {
                return(rcper.RoleName.ToLower() == roleName.ToLower() &&
                       rcper.CategoryId == category.Id);
            });

            if (rp != null)
            {
                read.Checked    = rp.HasRead;
                edit.Checked    = rp.HasEdit;
                publish.Checked = rp.HasPublish;
            }
        }
    }
Exemplo n.º 3
0
        public static void ClearPermissionsForRole(string role)
        {
            GetRolePermissions();
            GetRoleCategoryPermissions();

            foreach (RoleCategoryPermissions rcp in roleCategoryPermissions)
            {
                if (rcp.RoleName.ToLower() == role.ToLower())
                {
                    RoleCategoryPermissions.Destroy(rcp.Id);
                }
            }

            foreach (RolePermissions rp in rolePermissions)
            {
                if (rp.RoleName.ToLower() == role.ToLower())
                {
                    RolePermissions.Destroy(rp.Id);
                }
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }