示例#1
0
        /// <summary>
        /// Handles the Delete event of the rGrid control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void rGrid_Delete(object sender, RowEventArgs e)
        {
            var rockContext = new RockContext();
            var authService = new Rock.Model.AuthService(rockContext);

            Rock.Model.Auth auth = authService.Get(e.RowKeyId);
            if (auth != null)
            {
                authService.Delete(auth);
                rockContext.SaveChanges();

                Authorization.ReloadAction(iSecured.TypeId, iSecured.Id, CurrentAction);
            }

            BindGrid();
        }
示例#2
0
        /// <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)
        {
            if (ppUser.PersonId.HasValue)
            {
                int?personAliasId = ppUser.PersonAliasId;
                if (personAliasId.HasValue)
                {
                    using (var rockContext = new RockContext())
                    {
                        var authService   = new Rock.Model.AuthService(rockContext);
                        var existingAuths = authService.GetAuths(iSecured.TypeId, iSecured.Id, CurrentAction).ToList();

                        if (!existingAuths.Any(a => a.PersonAliasId.HasValue && a.PersonAliasId.Value == personAliasId.Value))
                        {
                            int order = existingAuths.Count > 0 ? existingAuths.Last().Order + 1 : 0;

                            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         = order;
                            authService.Add(auth);

                            rockContext.SaveChanges();

                            Authorization.ReloadAction(iSecured.TypeId, iSecured.Id, CurrentAction);
                        }
                    }
                }
            }

            pnlAddUser.Visible = false;
            phList.Visible     = true;

            BindGrid();
        }
示例#3
0
        /// <summary>
        /// Handles the SelectedIndexChanged event of the rblAllowDeny 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 rblAllowDeny_SelectedIndexChanged(object sender, EventArgs e)
        {
            RadioButtonList rblAllowDeny = (RadioButtonList)sender;
            GridViewRow     selectedRow  = rblAllowDeny.NamingContainer as GridViewRow;

            if (selectedRow != null)
            {
                int id = (int)rGrid.DataKeys[selectedRow.RowIndex]["Id"];

                var             rockContext = new RockContext();
                var             authService = new Rock.Model.AuthService(rockContext);
                Rock.Model.Auth auth        = authService.Get(id);
                if (auth != null)
                {
                    auth.AllowOrDeny = rblAllowDeny.SelectedValue;
                    rockContext.SaveChanges();

                    Authorization.ReloadAction(iSecured.TypeId, iSecured.Id, CurrentAction);
                }
            }

            BindGrid();
        }
示例#4
0
        /// <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)
        {
            using (var rockContext = new RockContext())
            {
                var authService = new AuthService(rockContext);

                foreach (ListItem li in cblRoleActionList.Items)
                {
                    if (li.Selected)
                    {
                        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;
                        }

                        var existingAuths = authService.GetAuths(iSecured.TypeId, iSecured.Id, li.Text).ToList();
                        if (!existingAuths.Any(a => a.SpecialRole == specialRole && a.GroupId.Equals(groupId)))
                        {
                            int order = existingAuths.Count > 0 ? existingAuths.Last().Order + 1 : 0;

                            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        = order;
                            authService.Add(auth);

                            rockContext.SaveChanges();

                            Authorization.ReloadAction(iSecured.TypeId, iSecured.Id, li.Text);
                        }
                    }
                }
            }

            pnlAddRole.Visible = false;
            phList.Visible     = true;

            BindGrid();
        }
示例#5
0
        /// <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 )
        {
            if ( ppUser.PersonId.HasValue )
            {
                int? personAliasId = ppUser.PersonAliasId;
                if ( personAliasId.HasValue )
                {
                    using ( var rockContext = new RockContext() )
                    {
                        var authService = new Rock.Model.AuthService( rockContext );
                        var existingAuths = authService.GetAuths( iSecured.TypeId, iSecured.Id, CurrentAction ).ToList();

                        if ( !existingAuths.Any( a => a.PersonAliasId.HasValue && a.PersonAliasId.Value == personAliasId.Value ) )
                        {
                            int order = existingAuths.Count > 0 ? existingAuths.Last().Order + 1 : 0;

                            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 = order;
                            authService.Add( auth );

                            rockContext.SaveChanges();

                            Authorization.ReloadAction( iSecured.TypeId, iSecured.Id, CurrentAction );
                        }
                    }
                }
            }

            pnlAddUser.Visible = false;
            phList.Visible = true;

            BindGrid();
        }
示例#6
0
        /// <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 )
        {
            using ( var rockContext = new RockContext() )
            {
                var authService = new AuthService( rockContext );

                foreach ( ListItem li in cblRoleActionList.Items )
                {
                    if ( li.Selected )
                    {
                        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;
                        }

                        var existingAuths = authService.GetAuths( iSecured.TypeId, iSecured.Id, li.Text ).ToList();
                        if ( !existingAuths.Any( a => a.SpecialRole == specialRole && a.GroupId.Equals( groupId ) ) )
                        {
                            int order = existingAuths.Count > 0 ? existingAuths.Last().Order + 1 : 0;

                            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 = order;
                            authService.Add( auth );

                            rockContext.SaveChanges();

                            Authorization.ReloadAction( iSecured.TypeId, iSecured.Id, li.Text );
                        }
                    }
                }
            }

            pnlAddRole.Visible = false;
            phList.Visible = true;

            BindGrid();
        }
示例#7
0
 /// <summary>
 /// Instantiates a new DTO object from the entity
 /// </summary>
 /// <param name="auth"></param>
 public AuthDto(Auth auth)
 {
     CopyFromModel(auth);
 }
示例#8
0
 /// <summary>
 /// To the dto.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public static AuthDto ToDto(this Auth value)
 {
     return(new AuthDto(value));
 }