We’ll continue the process of adding screens for managing LightSwitch security. This section we will deal with Role administration.
- In Visual Studio
- Create a new Browse Screen
- Screen Name: RolesBrowse
- Screen Data: LsSecurityData.Roles
- Change the Roles List to a Tile List
- Add a button to the Command Bar
- Choose an existing method, Roles, addAndEditNew, New Screen
- Screen Name: RoleAddEdit
- Screen Data: LsSecurityData.Role
- Additional Data: Role Details
- Move the Name field under the Command Bar
- Delete the empty Columns Layout
- Back to the RolesBrowse screen
- Roles Tile List, Item Tap in Properties, viewSelected, New Screen
- Screen Name: RoleView
- Screen Data: LsSecurityData.Role
- Additional Data: RoleAssignments and RolePermissions
- We don’t need the Details
- On the RoleView screen
- In properties for the screen, select Show As Dialog
- Move Role Permissions tab to be first
- For the Role Permissions List, change to Tile List
- Delete the Role Name and Permission Id fields
- Change the Permission Summary to be a row layout
- Move the Id and Name fields up one level
- Delete the empty row layout
- Change the Role Assignments List also to a Tile List
- Delete all the fields but the User Summary
- Change the User Summary to a row layout
- Move the User Name and Full Name fields up one level
- Delete the left over row layout with the password field
- Select the Role Permissions Tab, in properties, select Edit PostRender Code
- Add the following code into the method to show our Role Name in the header
contentItem.dataBind("screen.Role.Name", function (newValue) { contentItem.screen.details.displayName = newValue + " Role"; });
- For the Permissions Tile List, in properties, Item Tap
- Write my own method, name it RolePermissions1_ItemTap
- On the Command Bar for the Role Permissions tab
- Add a button, Write my own method, name it DeleteEntireRole
- Add a button, Write my own method, name it DeleteRolePermission
- For DeleteRolePermission button, uncheck the Is Visible
- Add another button, Choose an existing method
- Select under Role Permissions, addAndEditNew, New Screen
- Screen Name: RolePermissionAddEdit
- Screen Data: LsSecurityData.RolePermission
- Additional Data: Details
- Move the Permission modal picker under the Command Bar
- Delete the rest
- Save the solution for good measure
- Back to the Role View Screen
- On the Command Bar for Role Assignments
- Add a button, Write my own method, name it DeleteRoleAssignment
- So as not to get too boring, I’ll just show the entire code below for all the appropriate methods in the RoleView.lsml.js file
// Add the role name to our screen header myapp.RoleView.RolePermissions_postRender = function (element, contentItem) { contentItem.dataBind("screen.Role.Name", function (newValue) { contentItem.screen.details.displayName = newValue + " Role"; }); }; // We only bother with asking for permission on critical cascading deletes myapp.RoleView.DeleteEntireRole_execute = function (screen) { // Setup a dialog box to verify ok to delete msls.showMessageBox("Are you sure you want to delete the \nentire Role, including all associated data?", { title: "Delete Entire Role", buttons: msls.MessageBoxButtons.yesNo }).then(function (e) { if (e == msls.MessageBoxResult.yes) { screen.Role.deleteEntity(); myapp.commitChanges(); } }); }; // Delete the selected role assignment myapp.RoleView.DeleteRoleAssignment_execute = function (screen) { // Setup a dialog box to verify ok to delete msls.showMessageBox("Are you sure you want to delete the\nRole Assignment?", { title: "Delete Role Assignment", buttons: msls.MessageBoxButtons.yesNo }).then(function (e) { if (e == msls.MessageBoxResult.yes) { if (screen.RoleAssignments.selectedItem) { screen.RoleAssignments.selectedItem.deleteEntity(); myapp.applyChanges(); } screen.findContentItem("DeleteRoleAssignment").isVisible = false; } }); }; // Delete the selected role permission myapp.RoleView.DeleteRolePermission_execute = function (screen) { // Setup a dialog box to verify ok to delete msls.showMessageBox("Are you sure you want to delete the\nRole Permission?", { title: "Delete Role Permission", buttons: msls.MessageBoxButtons.yesNo }).then(function (e) { if (e == msls.MessageBoxResult.yes) { if (screen.RolePermissions.selectedItem) { screen.RolePermissions.selectedItem.deleteEntity(); myapp.applyChanges(); } screen.findContentItem("DeleteRolePermission").isVisible = false; screen.findContentItem("DeleteEntireRole").isVisible = true; } }); }; // When a role assignment is tapped, flip around buttons in view myapp.RoleView.RoleAssignments1_ItemTap_execute = function (screen) { screen.findContentItem("DeleteRoleAssignment").isVisible = true; }; // When a role permission is tapped, flip around buttons in view myapp.RoleView.RolePermissions1_ItemTap_execute = function (screen) { screen.findContentItem("DeleteEntireRole").isVisible = false; screen.findContentItem("DeleteRolePermission").isVisible = true; };
Don’t forget to change the icons for your buttons and perhaps friendlier display names. Look at our project for some examples.
Whew… Next… Screens For User Management
Here are the topics and their logical order:
- Create the project
- Add external CSS
- Add external scripts
- Update the default.htm
- Add LogIn/LogOut/Register/ChangePassword
- Create the security data source
- Screens for permissions
- — You
- Screens for user management
- Tables for tile menus
- Screens for icon management
- Screens for menu management
- Create a tile menu screen
- Create a database project
- How to deploy successfully
- Wrap up
I have also posted a question on forums and hopefully can get some answers
http://social.msdn.microsoft.com/Forums/vstudio/en-US/be98c933-04e8-4212-be7b-833aa60954e5/securitydata-odata-services-does-not-bring-back-related-roleassignments-and-rolepermissions?forum=lightswitch
I have the same issue. From view role, it is not get any related RolAssignments and RolePermissions. It is the same in both html and desktop clients
HI Dale,
i downloaded fiddler and this is what it Shows when i klick on Administrator to Show Permissions and Assignments:
GET: /LsSecurityData.svc/Roles(‘Administrator’)/RoleAssignments?$expand=User&$top=15
RAW:
HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Length: 99
Content-Type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8
Server: Microsoft-IIS/8.0
X-Content-Type-Options: nosniff
DataServiceVersion: 3.0;
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcRW50d2lja2x1bmdcd2FzdGVJVFx3YXN0ZUlUXGJpblxEZWJ1Z1xMc1NlY3VyaXR5RGF0YS5zdmNcUm9sZXMoJ0FkbWluaXN0cmF0b3InKVxSb2xlQXNzaWdubWVudHM=?=
X-Powered-By: ASP.NET
Date: Tue, 20 May 2014 06:46:24 GMT
{“odata.metadata”:”http://localhost:49983/LsSecurityData.svc/$metadata#RoleAssignments”,”value”:[]}
Hi Dale,
i have a strange behaviour at this Point. when i run the app i can add role assigments to a role. all works fine. but when i stop the app and run again and go to the roles browse Screen and tap a role no assignments were shown.
Please have a look at the Video:
http://screencast.com/t/fq0FxuBDG3G5
I’ve worked out ur tutorial several times and when i come to this Point ist always the same behaviour. can find out what happens.
Im using vs 2013 update 2 (tried it with update 1 too, same behaviour)
PS: When i start your Project all works fine. are you using an other Version of VS? perhaps ist a bug in VS 2013 with odata datasources?! it seems that lightswitch in vs 2013 doesnt load the related data…
Please help
Thomas
Hi Dale,
sorry I mean Role Permissions. Altough i think that Role Assignments did not work for me too.
Regards
Thomas