DynamicData - Updating the ListDetails Page - Part 7 (original) (raw)
Articles in this Series
- Introduction - A DynamicData Attribute Based Permission Solution using User Roles.
- Part 1 - Permissions Attribute (Metadata) Classes.
- Part 2 - Sample Metadata for project.
- Part 3 - The Helper Extension Methods.
- Part 4 - Limit Tables shown on Default page and List, Edit & Details etc.
- Part 5 - Generate Columns/Rows (using IAutoFieldGenerator)
- Part 6 - Miscellaneous bits
- Part 7 - Updating the ListDetails Page
- DynamicData - Limit the Filter Fields
Similarly to the List page Listing 1 show the class variables.
protected Boolean denyEdit = false; protected Boolean denyDelete = false; protected Boolean denyDetails = false; protected Boolean denyInsert = false;
Next is the setting of the class variables based on the permissions set returned.
// Get permissions for current table var tablePermissions = table.GetTablePermissions(Roles.GetRolesForUser());
// get status of links for column 0 from table permissions if (tablePermissions.Contains(TablePermissionsAttribute.Permissions.DenyEdit)) denyEdit = true; if (tablePermissions.Contains(TablePermissionsAttribute.Permissions.DenyDelete)) denyDelete = true; if (tablePermissions.Contains(TablePermissionsAttribute.Permissions.DenyDetails)) denyDetails = true; if (tablePermissions.Contains(TablePermissionsAttribute.Permissions.DenyInserts)) denyInsert = true;
This is the error if user got to this by invalid URL for them (e.g. old link or a hack)
// if table is denied read throw error if (tablePermissions.Contains(TablePermissionsAttribute.Permissions.DenyRead)) { Response.Redirect("~/Default.aspx?error=No access to " + table.Name); }
Here the links and DetailsPanel are set to display or hide, also if the DetailsPanel is hidden the don't bother to turn off the buttons.
// set visibility of Details DetailsPanel.Visible = !denyDetails; GridView1.AutoGenerateSelectButton = !denyDetails; GridView1.AutoGenerateEditButton = !denyEdit; GridView1.AutoGenerateDeleteButton = !denyDelete;
if (!denyDetails) { DetailsView1.AutoGenerateInsertButton = !denyInsert; DetailsView1.AutoGenerateEditButton = !denyEdit; DetailsView1.AutoGenerateDeleteButton = !denyDelete; }
I think that about wraps it up for this...
But may be not I think next I may override some of the controls then there will be less code to add per page.
NOTE: you will need to change the routing to see ListDetails pages instead of List, Details, Edit, Insert.