Beispiel #1
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)
        {
            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();
        }
Beispiel #2
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;

            foreach (ListItem li in cbUsers.Items)
            {
                if (li.Selected)
                {
                    bool alreadyExists = false;

                    int personId = Int32.Parse(li.Value);

                    foreach (AuthRule auth in existingAuths)
                    {
                        if (auth.PersonId.HasValue && auth.PersonId.Value == personId)
                        {
                            alreadyExists = true;
                            break;
                        }
                    }

                    if (!alreadyExists)
                    {
                        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, CurrentPersonId);
                        authService.Save(auth, CurrentPersonId);

                        actionUpdated = true;
                    }
                }
            }

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

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

            BindGrid();
        }
Beispiel #3
0
        protected void rGrid_Delete(object sender, RowEventArgs e)
        {
            Rock.Model.Auth auth = authService.Get((int)rGrid.DataKeys[e.RowIndex]["id"]);
            if (auth != null)
            {
                authService.Delete(auth, CurrentPersonId);
                authService.Save(auth, CurrentPersonId);

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

            BindGrid();
        }
Beispiel #4
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();
        }
Beispiel #5
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"];

                Rock.Model.Auth auth = authService.Get(id);
                if (auth != null)
                {
                    auth.AllowOrDeny = rblAllowDeny.SelectedValue;
                    authService.Save(auth, CurrentPersonId);

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

            BindGrid();
        }
Beispiel #6
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 )
                    {
                        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();
        }
Beispiel #7
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;

            foreach ( ListItem li in cbUsers.Items )
            {
                if ( li.Selected )
                {
                    bool alreadyExists = false;

                    int personId = Int32.Parse( li.Value );

                    foreach ( AuthRule auth in existingAuths )
                        if ( auth.PersonId.HasValue && auth.PersonId.Value == personId )
                        {
                            alreadyExists = true;
                            break;
                        }

                    if ( !alreadyExists )
                    {
                        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, CurrentPersonId );
                        authService.Save( auth, CurrentPersonId );

                        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();
        }
Beispiel #9
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)
                    {
                        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();
        }