locked
How to open AddEdit screen or View Screen, depending on user permission (HTML Client) RRS feed

  • Question

  • Hi, I'm trying to open a screen depending on user permission, following Beth Massi's article A simple way of checking user permissions from the HTML Client.

    I have created my own function for the ItemTap_execute event, as follow:

    myapp.BrowseOP.TableOP_ItemTap_execute = function (screen) {
        // show AddEdit or View screen, depending on user permission
        screen.getCanManageOP().then(function success() {
            myapp.showAddEditOP(screen.OPs.selectedItem);
        }, function error() {
            myapp.showViewOP(screen.OPs.selectedItem);
        });
    
    };

    I disabled the CanManageOP permission for debugging, nonetheless the AddEdit screen shows, instead of the View one.

    The exact same code works for hiding/disabling controls, I thought it would work.


    PS: getCanManageOP() retrieves a query property which handles the user permission checking on canExecute, as shown in the article.
    Monday, March 31, 2014 6:08 PM

All replies

  • Did you implement the code found under the Define a Query heading in the blog post? That first block of code is key to making the call to GetCanManagerOP fail if the user does not have permission.


    Justin Anderson, LightSwitch Development Team

    Monday, March 31, 2014 7:56 PM
    Moderator
  • Did you implement the code found under the Define a Query heading in the blog post? That first block of code is key to making the call to GetCanManagerOP fail if the user does not have permission.


    Justin Anderson, LightSwitch Development Team


    Yes, and I tested it hiding the AddNewOP button on the browse screen, and it works. So, is the _ItemTap_execute code OK?
    Monday, March 31, 2014 8:06 PM
  • I found that the behavior is caused because getCanManageOP() is called twice: once when the screen is created (to disable a button) and once on ItemTap_execute. I commented the first call and the second one Works as expected.

    Does anybody know a way around this? (other than creating another query)

    thanks.

    Nico.

    Monday, March 31, 2014 10:43 PM
  • I switched to this approach: Using LightSwitch ServerApplicationContext and WebAPI to Get User Permissions, and use a mix of both articles.

    The problem is I am getting myapp.permissions = undefined when checking for permissions when the screen is created (as pointed out by Ken Carrier in the comments of the article above mentioned).

    Tuesday, April 1, 2014 10:44 PM
  • getJSON() function is working asynchronously. Keep this in mind.
    Tuesday, March 21, 2017 10:49 AM