Exemplo n.º 1
0
        /// <summary>
        /// Handles the RowDataBound event of the control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridViewRowEventArgs"/> instance containing the event data.</param>
        protected void gResults_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                AuthGridRow row      = ( AuthGridRow )e.Row.DataItem;
                LinkButton  lbUnlock = ( LinkButton )e.Row.Cells[6].Controls[0];

                lbUnlock.Visible = row.IsUnlockable;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Bind the grid to the authorization records found in the database.
        /// </summary>
        /// <param name="entitySecured">The securable entity to query authorization records of.</param>
        /// <param name="person">The person whose access level we are checking.</param>
        void BindGrid(ISecured entitySecured, Person person)
        {
            //
            // Walk all the supported actions and build a row of results.
            //
            List <AuthGridRow> rows = new List <AuthGridRow>();

            foreach (var action in entitySecured.SupportedActions)
            {
                ISecured authorative = null;
                var      auth        = ItemAuthorized(entitySecured, action.Key, person, true, true, out authorative);

                if (auth != null)
                {
                    var    authEntity   = authorative as IEntity;
                    string friendlyName = "Unknown";

                    if (auth.SpecialRole != SpecialRole.None)
                    {
                        friendlyName = auth.SpecialRole.ToStringSafe().SplitCase();
                    }
                    else if (auth.PersonAlias != null)
                    {
                        friendlyName = auth.PersonAlias.ToStringSafe();
                    }
                    else if (auth.Group != null)
                    {
                        friendlyName = auth.Group.ToStringSafe();
                    }

                    var row = new AuthGridRow();
                    row.Id     = auth.Id;
                    row.Action = auth.Action;
                    if (authEntity != null)
                    {
                        row.EntityType = authEntity.TypeName;
                        row.EntityId   = authEntity.Id != 0 ? ( int? )authEntity.Id : null;
                        row.EntityName = authEntity.Id != 0 ? authEntity.ToString() : "(Entity Administration Security)";
                    }
                    else
                    {
                        row.EntityId = null;

                        if (authorative as GlobalDefault != null)
                        {
                            row.EntityType = "(Global Default)";
                            row.EntityName = string.Empty;
                        }
                        else
                        {
                            row.EntityType = "Unknown";
                            row.EntityName = "Unknown";
                        }
                    }
                    row.Access       = auth.AllowOrDeny == "A" ? "<span class='label label-success'>Allow</span>" : "<span class='label label-danger'>Deny</span>";
                    row.Role         = friendlyName;
                    row.IsUnlockable = auth.AllowOrDeny != "A";

                    rows.Add(row);
                }
                else
                {
                    var row = new AuthGridRow();
                    row.Id           = 0;
                    row.Action       = action.Key;
                    row.EntityType   = string.Empty;
                    row.EntityId     = null;
                    row.EntityName   = string.Empty;
                    row.Access       = "<span class='label label-default'>Unknown</span>";
                    row.Role         = "No explicit permissions found";
                    row.IsUnlockable = false;

                    rows.Add(row);
                }
            }

            gResults.DataSource = rows;
            gResults.DataBind();
        }