We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31640
    • 100 Posts
    I am developping a cmp to display data from a 3th party table.

    I display the data in a read only grid.
    When you right click on the record i have a menu with an update action.

    I received the requirement to create a user with only read only access to that grid.

    So i was thinking of hiding the menu with the update action for this specific user.
    Is this possible?

    So can i access the user access role in the extjs javascript? Or do i need to do this in another way...

    Any help is appreciated smiley [ed. note: visvoer last edited this post 11 years, 7 months ago.]
      • 33968
      • 863 Posts
      Sure. Using Doodles as an example, you can create a new access policy template and add a new permission: doodles.edit_grid

      Then assign this permission only to user groups who you want to be able to edit the grid. The others will be read-only.

      Create a plugin running on the OnManagerPageInit event:
      <?php
      // check for 'edit_grid' permission and add to the ModExt permissions object
      $gridEditPermission = $modx->hasPermission('doodles.edit_grid') ? 1 : 0;
      $modx->regClientStartupHTMLBlock('<script type="text/javascript">
          Ext.onReady(function() {
              MODx.perm.edit_grid = '.$gridEditPermission.';
          });
      </script>');
      


      In your ExtJS code, you can check for permissions like this:
      ,getMenu: function() {
          var menu = [];
          if (MODx.perm.edit_grid) {
              menu = [{
                  text: _('doodles.doodle_update')
                  ,handler: this.updateDoodle
              },'-',{
                  text: _('doodles.doodle_remove')
                  ,handler: this.removeDoodle
              }];
          }
          return menu;
      }
      
        • 31640
        • 100 Posts
        thanks a lot, this what was i was searching for...