Topic
  • 10 replies
  • Latest Post - ‏2015-07-23T05:39:25Z by Friendy
fdauri
fdauri
18 Posts

Pinned topic How to show or hide a feature based on a user profile

‏2013-06-06T09:51:18Z | ecmhv ecmsupport icn

Hi,

We have developed two features inside a new custom plugin. We would like to control the display of the two feature based on the user that is connected to the ICN (or based on the ldap group which the user belong to). So if the user is not authorize to see the feature, we would like to don't load (or show) the feature after the user login. It's something similar to the administrator's feature: currently on the ICN, if you are not an administrator, the feature icon is not available on the desktop. 

I know that it's possible to create different desktop but the customer doesn't accept this solution.

Any suggestion?

 

Thanks in advance,

 

Francesco

  • ramanandreddy
    ramanandreddy
    1 Post
    ACCEPTED ANSWER

    Re: How to show or hide a feature based on a user profile

    ‏2013-06-07T00:27:49Z  
    • fdauri
    • ‏2013-06-06T13:45:25Z

    Hi nicolas,

     

    thanks for your answer. My main point is the following: how can I dynamically add or remove feature to the desktop after the user login? Do you have a concrete code example?

    My main issue is not the user verification but how to show or hide feature once I have check the user right. 

     

    Thanks again for your support,

     

    Francesco

    ecm.widget.layout.MainLayout.getAvailableFeatures is the method that lists features . This list is used by the layout widget - ecm.widget.layout.NavigatorMainLayout , which based on the default and selected features does the layout of the UI.  So you can override ecm.widget.layout.NavigatorMainLayout.getAvailableFeatures in a plugin with a custom layout widget  to get the desired behavior.

  • nicolas.leralle
    nicolas.leralle
    102 Posts

    Re: How to show or hide a feature based on a user profile

    ‏2013-06-06T12:46:59Z  

    Hi Francesco.

    To my knowledge, there is no equivalent of "Access roles" in ICN. But as you are in your own plugin, you are able to call a custom WebService, which will verify if the user is able to have access to your feature.

     

    Best regards,

    Nicolas

  • fdauri
    fdauri
    18 Posts

    Re: How to show or hide a feature based on a user profile

    ‏2013-06-06T13:45:25Z  

    Hi Francesco.

    To my knowledge, there is no equivalent of "Access roles" in ICN. But as you are in your own plugin, you are able to call a custom WebService, which will verify if the user is able to have access to your feature.

     

    Best regards,

    Nicolas

    Hi nicolas,

     

    thanks for your answer. My main point is the following: how can I dynamically add or remove feature to the desktop after the user login? Do you have a concrete code example?

    My main issue is not the user verification but how to show or hide feature once I have check the user right. 

     

    Thanks again for your support,

     

    Francesco

  • ramanandreddy
    ramanandreddy
    1 Post

    Re: How to show or hide a feature based on a user profile

    ‏2013-06-07T00:27:49Z  
    • fdauri
    • ‏2013-06-06T13:45:25Z

    Hi nicolas,

     

    thanks for your answer. My main point is the following: how can I dynamically add or remove feature to the desktop after the user login? Do you have a concrete code example?

    My main issue is not the user verification but how to show or hide feature once I have check the user right. 

     

    Thanks again for your support,

     

    Francesco

    ecm.widget.layout.MainLayout.getAvailableFeatures is the method that lists features . This list is used by the layout widget - ecm.widget.layout.NavigatorMainLayout , which based on the default and selected features does the layout of the UI.  So you can override ecm.widget.layout.NavigatorMainLayout.getAvailableFeatures in a plugin with a custom layout widget  to get the desired behavior.

  • fdauri
    fdauri
    18 Posts

    Re: How to show or hide a feature based on a user profile

    ‏2013-06-07T13:09:39Z  

    ecm.widget.layout.MainLayout.getAvailableFeatures is the method that lists features . This list is used by the layout widget - ecm.widget.layout.NavigatorMainLayout , which based on the default and selected features does the layout of the UI.  So you can override ecm.widget.layout.NavigatorMainLayout.getAvailableFeatures in a plugin with a custom layout widget  to get the desired behavior.

    Ramananda,

     

    really thank you so much for your precious suggestions!! You have allowed us to unlock a critical situation.

    Thanks again for your support. I'll try the tips.

     

    Francesco

  • W. Darwish
    W. Darwish
    2 Posts

    Re: How to show or hide a feature based on a user profile

    ‏2014-01-14T10:37:46Z  
    • fdauri
    • ‏2013-06-07T13:09:39Z

    Ramananda,

     

    really thank you so much for your precious suggestions!! You have allowed us to unlock a critical situation.

    Thanks again for your support. I'll try the tips.

     

    Francesco

    Francesco,

     

    Were you able to get it to work?

    We have the exact same situation and we are not able to get the username of the logged in user in that area of the code. Would it be possible to post a working sample please?

    W. Darwish

  • arronla
    arronla
    94 Posts

    Re: How to show or hide a feature based on a user profile

    ‏2014-01-14T18:44:48Z  

    Francesco,

     

    Were you able to get it to work?

    We have the exact same situation and we are not able to get the username of the logged in user in that area of the code. Would it be possible to post a working sample please?

    W. Darwish

    If you override getAvailableFeature, you will need to get your own custom layout.  If you don't want to do this, a slightly alternative way is to just "hide" the feature by css or completely remove the feature.  You can do this just by writing a plugin and connecting to the onLogin call.

    Some psuedo code I am writing blindly without checking to see if it actually compiles.

    this.connect(Desktop, "onLogin", function() {
        var userId = Desktop.getAuthenticatingRepository().userId;
        //determine if the user should have access.  If not, hide or remove
        
        //to just hide
        var button = Desktop.getLayout().launchBarContainer.getButtons()[featureId];
        if(button){
                    dojo_style.set(button.domNode, "display", "none");
            
        //to remove
        Desktop.getLayout().launchBarContainer.removeFeatureFromLayout(feature);
        });
    

     

  • PiGG
    PiGG
    71 Posts

    Re: How to show or hide a feature based on a user profile

    ‏2014-09-18T21:47:53Z  
    • arronla
    • ‏2014-01-14T18:44:48Z

    If you override getAvailableFeature, you will need to get your own custom layout.  If you don't want to do this, a slightly alternative way is to just "hide" the feature by css or completely remove the feature.  You can do this just by writing a plugin and connecting to the onLogin call.

    Some psuedo code I am writing blindly without checking to see if it actually compiles.

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">this.connect(Desktop, "onLogin", function() { var userId = Desktop.getAuthenticatingRepository().userId; //determine if the user should have access. If not, hide or remove //to just hide var button = Desktop.getLayout().launchBarContainer.getButtons()[featureId]; if(button){ dojo_style.set(button.domNode, "display", "none"); //to remove Desktop.getLayout().launchBarContainer.removeFeatureFromLayout(feature); }); </pre>

     

    arronla,

    Line #3 //determine if the user should have access.  If not, hide or remove

    How do I determine if the user have access?  In my case, if the user belongs to a ldap group "ABC", then the user has the access and therefor he can see the feature Icon.  Do I have to use the custom Webservice call to verify?

  • fdauri
    fdauri
    18 Posts

    Re: How to show or hide a feature based on a user profile

    ‏2014-09-19T10:22:57Z  
    • PiGG
    • ‏2014-09-18T21:47:53Z

    arronla,

    Line #3 //determine if the user should have access.  If not, hide or remove

    How do I determine if the user have access?  In my case, if the user belongs to a ldap group "ABC", then the user has the access and therefor he can see the feature Icon.  Do I have to use the custom Webservice call to verify?

    Hi all,

    if can be useful, I post my code that currently is used with ICN 2.0.2 FP2:

    The following function remove the feature passed as parameter from the launchBarContainer:
    

     

    var removeFeature = function(featureId) {
    var featuresAvailable = ecm.model.desktop.getFeatures();
    for(var j=0; j<featuresAvailable.length; j++) {
    var f = featuresAvailable[j];
    Logger.logDebug("Finding feature with id " + featureId + " comparing with feature " + f.id);
    if(f.id === featureId) {
    ecm.model.desktop.layoutDijit.launchBarContainer.removeFeatureFromLayout(f);
    ecm.model.desktop.removeFeature(f);
    Logger.logDebug("Feature " + f.id + " removed.");
    }
    }
    }

     

    The following function invokes an ICN service in order to retrieve from ldap all the user information and the group membership.
    

     

    var checkProfile = connect.connect(ecm.model.desktop, "onLogin", this, function() {
    var params = {};
    params.userLogged = ecm.model.desktop.getAuthenticatingRepository().userId;
    ecm.model.Request.invokePluginService("MyPlugin", "LDAPUtilService",
    {
    requestMethod: "GET",
    requestParams: params,
    requestCompleteCallback: function(response) {
    Logger.logDebug("LDAP group name succesfully retireved");
    var profileConfig = {};
    profileConfig.groupProfileA = response.groupProfileA;
    profileConfig.groupProfileB = response.groupProfileB;
    profileConfig.groupProfileC = response.groupProfileC;
    profileConfig.groupProfileD = response.groupProfileD;
    if(!ecm.model._MyPluginProperties) {
    ecm.model._MyPluginProperties = {};
    }
    ecm.model._MyPluginProperties.profileConfig = profileConfig;
    ecm.model._MySPluginProperties.userLdapGroups = response.groups;
    ecm.model._MyPluginProperties.configurationPanel = response.configuration;
     
    var groups = ecm.model._MyPluginProperties.userLdapGroups;
    var userProfiles = [];
    var userProfileGroupNames = [];
    //Check the profile matching the group and the profile name
    for(var i=0; i<groups.length; i++) {
    if(groups[i].groupName === ecm.model._MyPluginProperties.profileConfig.groupProfileA) {
    userProfiles.push("groupProfileA");
    userProfileGroupNames.push(groups[i]);
    }

    [...] After some profiling action, if the user is not allowed to use some features, I remove them:

    removeCSPluginFeature("browsePane");

    [..]

     
    },
    requestFailedCallback: function(error) {
    Logger.logError("Error while retrieving LDAP group name for user CN=" + ecm.model.desktop.getAuthenticatingRepository().userId);
    removeCSPluginFeature("MySectionalFeature");
    var errorDialog = new ecm.widget.dialog.ErrorDialog();
    errorDialog.setMessage("System Error.", "error");
    errorDialog.setTitle("Error");
    errorDialog.setSize(400, 280); 
    errorDialog.show();
    },
    cancellable: false
    });

     

  • PiGG
    PiGG
    71 Posts

    Re: How to show or hide a feature based on a user profile

    ‏2014-09-19T20:28:07Z  
    • fdauri
    • ‏2014-09-19T10:22:57Z

    Hi all,

    if can be useful, I post my code that currently is used with ICN 2.0.2 FP2:

    The following function remove the feature passed as parameter from the launchBarContainer:
    

     

    var removeFeature = function(featureId) {
    var featuresAvailable = ecm.model.desktop.getFeatures();
    for(var j=0; j<featuresAvailable.length; j++) {
    var f = featuresAvailable[j];
    Logger.logDebug("Finding feature with id " + featureId + " comparing with feature " + f.id);
    if(f.id === featureId) {
    ecm.model.desktop.layoutDijit.launchBarContainer.removeFeatureFromLayout(f);
    ecm.model.desktop.removeFeature(f);
    Logger.logDebug("Feature " + f.id + " removed.");
    }
    }
    }

     

    The following function invokes an ICN service in order to retrieve from ldap all the user information and the group membership.
    

     

    var checkProfile = connect.connect(ecm.model.desktop, "onLogin", this, function() {
    var params = {};
    params.userLogged = ecm.model.desktop.getAuthenticatingRepository().userId;
    ecm.model.Request.invokePluginService("MyPlugin", "LDAPUtilService",
    {
    requestMethod: "GET",
    requestParams: params,
    requestCompleteCallback: function(response) {
    Logger.logDebug("LDAP group name succesfully retireved");
    var profileConfig = {};
    profileConfig.groupProfileA = response.groupProfileA;
    profileConfig.groupProfileB = response.groupProfileB;
    profileConfig.groupProfileC = response.groupProfileC;
    profileConfig.groupProfileD = response.groupProfileD;
    if(!ecm.model._MyPluginProperties) {
    ecm.model._MyPluginProperties = {};
    }
    ecm.model._MyPluginProperties.profileConfig = profileConfig;
    ecm.model._MySPluginProperties.userLdapGroups = response.groups;
    ecm.model._MyPluginProperties.configurationPanel = response.configuration;
     
    var groups = ecm.model._MyPluginProperties.userLdapGroups;
    var userProfiles = [];
    var userProfileGroupNames = [];
    //Check the profile matching the group and the profile name
    for(var i=0; i<groups.length; i++) {
    if(groups[i].groupName === ecm.model._MyPluginProperties.profileConfig.groupProfileA) {
    userProfiles.push("groupProfileA");
    userProfileGroupNames.push(groups[i]);
    }

    [...] After some profiling action, if the user is not allowed to use some features, I remove them:

    removeCSPluginFeature("browsePane");

    [..]

     
    },
    requestFailedCallback: function(error) {
    Logger.logError("Error while retrieving LDAP group name for user CN=" + ecm.model.desktop.getAuthenticatingRepository().userId);
    removeCSPluginFeature("MySectionalFeature");
    var errorDialog = new ecm.widget.dialog.ErrorDialog();
    errorDialog.setMessage("System Error.", "error");
    errorDialog.setTitle("Error");
    errorDialog.setSize(400, 280); 
    errorDialog.show();
    },
    cancellable: false
    });

     

    Thanks, fdauri

    Did you write this web service,"MyPlugin", "LDAPUtilService", ? 

    I am a lazy spoiled guy :) who is looking for any existing methods I can piggyback on.  If not, I will have to create my own.  

  • Friendy
    Friendy
    91 Posts

    Re: How to show or hide a feature based on a user profile

    ‏2015-07-23T05:39:25Z  
    • PiGG
    • ‏2014-09-19T20:28:07Z

    Thanks, fdauri

    Did you write this web service,"MyPlugin", "LDAPUtilService", ? 

    I am a lazy spoiled guy :) who is looking for any existing methods I can piggyback on.  If not, I will have to create my own.  

    Hi Michael Pig ,

    do you still have that web service for getting LDAP if you can help me out please :) ?