示例#1
0
        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)
            {
                int  personId      = ppUser.PersonId.Value;
                bool alreadyExists = false;

                foreach (AuthRule auth in existingAuths)
                {
                    if (auth.PersonId.HasValue && auth.PersonId.Value == personId)
                    {
                        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       = CurrentAction;
                    auth.AllowOrDeny  = "A";
                    auth.SpecialRole  = Rock.Model.SpecialRole.None;
                    auth.PersonId     = personId;
                    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();
        }
示例#2
0
        void rGrid_GridReorder(object sender, GridReorderEventArgs e)
        {
            int entityTypeId = iSecured.TypeId;

            var rockContext = new RockContext();
            var authService = new Rock.Model.AuthService(rockContext);
            List <Rock.Model.Auth> rules = authService.GetAuths(iSecured.TypeId, iSecured.Id, CurrentAction).ToList();

            authService.Reorder(rules, e.OldIndex, e.NewIndex);
            rockContext.SaveChanges();

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

            BindGrid();
        }
示例#3
0
        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((int)rGrid.DataKeys[e.RowIndex]["id"]);
            if (auth != null)
            {
                authService.Delete(auth);
                rockContext.SaveChanges();

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

            BindGrid();
        }
示例#4
0
        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();
        }
        /// <summary>
        /// Handles the GridReorder event of the rGrid control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridReorderEventArgs"/> instance containing the event data.</param>
        protected void rGrid_GridReorder( object sender, GridReorderEventArgs e )
        {
            int entityTypeId = iSecured.TypeId;

            var rockContext = new RockContext();
            var authService = new Rock.Model.AuthService( rockContext );
            List<Rock.Model.Auth> rules = authService.GetAuths( iSecured.TypeId, iSecured.Id, CurrentAction ).ToList();
            authService.Reorder( rules, e.OldIndex, e.NewIndex );
            rockContext.SaveChanges();

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

            BindGrid();
        }
        /// <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();
        }
        /// <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();
        }
        /// <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();
        }
示例#10
0
        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)
                    {
                        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();
        }