/// <summary> /// Handles the Click event of the lbAddUser control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void lbAddUser_Click(object sender, EventArgs e) { List <AuthRule> existingAuths = Authorization.AuthRules(iSecured.TypeId, iSecured.Id, CurrentAction); int maxOrder = existingAuths.Count > 0 ? existingAuths.Last().Order : -1; bool actionUpdated = false; if (ppUser.PersonId.HasValue) { var rockContext = new RockContext(); int?personAliasId = ppUser.PersonAliasId; if (personAliasId.HasValue) { bool alreadyExists = false; foreach (AuthRule auth in existingAuths) { if (auth.PersonAliasId.HasValue && auth.PersonAliasId.Equals(personAliasId.Value)) { alreadyExists = true; break; } } if (!alreadyExists) { var authService = new Rock.Model.AuthService(rockContext); Rock.Model.Auth auth = new Rock.Model.Auth(); auth.EntityTypeId = iSecured.TypeId; auth.EntityId = iSecured.Id; auth.Action = CurrentAction; auth.AllowOrDeny = "A"; auth.SpecialRole = Rock.Model.SpecialRole.None; auth.PersonAliasId = personAliasId; auth.Order = ++maxOrder; authService.Add(auth); rockContext.SaveChanges(); actionUpdated = true; } } } if (actionUpdated) { Authorization.ReloadAction(iSecured.TypeId, iSecured.Id, CurrentAction); } pnlAddUser.Visible = false; phList.Visible = true; BindGrid(); }
/// <summary> /// Handles the Click event of the lbAddUser control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void lbAddUser_Click( object sender, EventArgs e ) { List<AuthRule> existingAuths = Authorization.AuthRules( iSecured.TypeId, iSecured.Id, CurrentAction ); int maxOrder = existingAuths.Count > 0 ? existingAuths.Last().Order : -1; bool actionUpdated = false; if ( ppUser.PersonId.HasValue ) { var rockContext = new RockContext(); int? personAliasId = ppUser.PersonAliasId; if ( personAliasId.HasValue ) { bool alreadyExists = false; foreach ( AuthRule auth in existingAuths ) { if ( auth.PersonAliasId.HasValue && auth.PersonAliasId.Equals( personAliasId.Value ) ) { alreadyExists = true; break; } } if ( !alreadyExists ) { var authService = new Rock.Model.AuthService( rockContext ); Rock.Model.Auth auth = new Rock.Model.Auth(); auth.EntityTypeId = iSecured.TypeId; auth.EntityId = iSecured.Id; auth.Action = CurrentAction; auth.AllowOrDeny = "A"; auth.SpecialRole = Rock.Model.SpecialRole.None; auth.PersonAliasId = personAliasId; auth.Order = ++maxOrder; authService.Add( auth ); rockContext.SaveChanges(); actionUpdated = true; } } } if ( actionUpdated ) { Authorization.ReloadAction( iSecured.TypeId, iSecured.Id, CurrentAction ); } pnlAddUser.Visible = false; phList.Visible = true; BindGrid(); }
/// <summary> /// Handles the Click event of the lbAddRole control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> 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 = 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, li.Text ) ) { if ( rule.SpecialRole == specialRole && rule.GroupId == groupId ) { alreadyExists = true; break; } } if ( !alreadyExists ) { var rockContext = new RockContext(); var authService = new Rock.Model.AuthService( rockContext ); 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 ); rockContext.SaveChanges(); actionUpdated = true; } if ( actionUpdated ) { Authorization.ReloadAction( iSecured.TypeId, iSecured.Id, li.Text ); } } } pnlAddRole.Visible = false; phList.Visible = true; BindGrid(); }
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(); }