Exemplo n.º 1
0
        public void Update(Role role)
        {
            Require.NotNull(role, "role");

            foreach (RepeaterItem item in FunctionRepeater.Items)
            {
                if (item.IsDataItem())
                {
                    string pluginName = ViewState["PluginName" + item.ItemIndex].ToString();
                    string groupName = ViewState["GroupName" + item.ItemIndex].ToString();

                    PermissionGroup group = null;

                    if (!String.IsNullOrEmpty(pluginName))
                    {
                        var plugin = PluginManager.FindEnabledPlugin(pluginName);
                        if (plugin != null)
                        {
                            group = plugin.PermissionGroups.Find(groupName);
                        }
                    }
                    else
                    {
                        group = CmsConfiguration.Instance.Security.PermissionGroups.Find(groupName);
                    }

                    if (group == null) continue;

                    var chbList = (CheckBoxList)item.FindControl("Operations");

                    var selectedOperations = new List<Permission>();
                    var unselectedOperations = new List<Permission>();

                    foreach (ListItem each in chbList.Items)
                    {
                        if (each.Selected)
                        {
                            selectedOperations.Add(group.Permissions.Find(each.Value));
                        }
                        else
                        {
                            unselectedOperations.Add(group.Permissions.Find(each.Value));
                        }
                    }

                    foreach (var each in selectedOperations)
                    {
                        role.AddPermission(each);
                    }

                    foreach (var each in unselectedOperations)
                    {
                        role.RemovePermission(each);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void Bind(Role role)
        {
            _role = role;

            IEnumerable<PermissionGroup> functions = CmsConfiguration.Instance.Security.PermissionGroups;
            var plugins = PluginManager.EnabledPlugins;

            foreach (var plugin in plugins)
            {
                functions = functions.Union(plugin.PermissionGroups);
            }

            FunctionRepeater.DataSource = functions;
            FunctionRepeater.DataBind();
        }
Exemplo n.º 3
0
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid) return;

            if (RoleId > 0)
            {
                var role = NhSession.Get<Role>(RoleId);
                UpdateObject(role);
            }
            else
            {
                var role = new Role();
                UpdateObject(role);
                NhSession.Save(role);
            }

            NhSession.Commit();

            Response.Redirect("RoleList.aspx");
        }
Exemplo n.º 4
0
 public RoleGrantedPermission(Role role)
 {
     Role = role;
 }
Exemplo n.º 5
0
 public void UpdateObject(Role entity)
 {
     entity.Name = Name.Text.Trim();
     Privileges.Update(entity);
 }
Exemplo n.º 6
0
 public void InitView(Role entity)
 {
     Name.Text = entity.Name;
     Privileges.Bind(entity);
 }