/// <summary> /// Sets the role actions. /// </summary> private void SetRoleActions() { cblRoleActionList.Items.Clear(); foreach (var action in iSecured.SupportedActions) { if (action.Key == CurrentAction) { lActionDescription.Text = action.Value; ListItem roleItem = new ListItem(action.Key); roleItem.Selected = true; cblRoleActionList.Items.Add(roleItem); } else { bool alreadyAdded = false; Rock.Model.SpecialRole specialRole = Rock.Model.SpecialRole.None; int?groupId = ddlRoles.SelectedValue.AsIntegerOrNull(); switch (groupId) { case -1: specialRole = Rock.Model.SpecialRole.AllUsers; break; case -2: specialRole = Rock.Model.SpecialRole.AllAuthenticatedUsers; break; case -3: specialRole = Rock.Model.SpecialRole.AllUnAuthenticatedUsers; break; default: specialRole = Rock.Model.SpecialRole.None; break; } if (groupId < 0) { groupId = null; } foreach (AuthRule rule in Authorization.AuthRules(iSecured.TypeId, iSecured.Id, action.Key)) { if (rule.SpecialRole == specialRole && rule.GroupId == groupId) { alreadyAdded = true; break; } } if (!alreadyAdded) { cblRoleActionList.Items.Add(new ListItem(action.Key)); } } } }
protected void lbAddRole_Click(object sender, EventArgs e) { List <AuthRule> existingAuths = Authorization.AuthRules(iSecured.TypeId, iSecured.Id, CurrentAction); int maxOrder = existingAuths.Count > 0 ? existingAuths.Last().Order : -1; foreach (ListItem li in cblRoleActionList.Items) { if (li.Selected) { bool actionUpdated = false; bool alreadyExists = false; Rock.Model.SpecialRole specialRole = Rock.Model.SpecialRole.None; int?groupId = Int32.Parse(ddlRoles.SelectedValue); switch (groupId) { case -1: specialRole = Rock.Model.SpecialRole.AllUsers; break; case -2: specialRole = Rock.Model.SpecialRole.AllAuthenticatedUsers; break; case -3: specialRole = Rock.Model.SpecialRole.AllUnAuthenticatedUsers; break; default: specialRole = Rock.Model.SpecialRole.None; break; } if (groupId < 0) { groupId = null; } foreach (AuthRule rule in Authorization.AuthRules(iSecured.TypeId, iSecured.Id, li.Text)) { if (rule.SpecialRole == specialRole && rule.GroupId == groupId) { alreadyExists = true; break; } } if (!alreadyExists) { Rock.Model.Auth auth = new Rock.Model.Auth(); auth.EntityTypeId = iSecured.TypeId; auth.EntityId = iSecured.Id; auth.Action = li.Text; auth.AllowOrDeny = "A"; auth.SpecialRole = specialRole; auth.GroupId = groupId; auth.Order = ++maxOrder; authService.Add(auth, CurrentPersonId); authService.Save(auth, CurrentPersonId); actionUpdated = true; } if (actionUpdated) { Authorization.ReloadAction(iSecured.TypeId, iSecured.Id, li.Text); } } } pnlAddRole.Visible = false; phList.Visible = true; BindGrid(); }