User Permissions

How to allow blog, files, pages and other modules only for groups?

  • That may requite quite a long answer. How familiar are you with Elgg plugin development? Which Elgg version are you developing for?

  • I had to do the same in an Elgg site. I solved this by using as base the Roles plugin (https://github.com/arckinteractive/Roles).

    So in my_plugin_roles_extension I used the following hook:

    elgg_register_plugin_hook_handler("roles:config", "role", "myplugin_roles_config", 550);

    ......

    function myplugin_roles_config($hook_name, $entity_type, $return_value, $params) {
        $roles = array(
            DEFAULT_ROLE => array(
                'title' => 'roles:role:DEFAULT_ROLE',
                'permissions' => array(
                    'pages' => array(
                        'blog/add' => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                        'blog/add/{$self_guid}'=> array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                        'bookmarks/add' => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                        'bookmarks/add/{$self_guid}'=> array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                        'file/add' => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                        'file/add/{$self_guid}' => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                        'pages/add' => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                        'pages/add/{$self_guid}' => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                        'blog/all' => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                        'bookmarks/all' => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                        'file/all' => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                        'pages/all' => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                        'activity/' => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                        'members/' => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                    ),
                    'menus' => array(
                        'site::members' => array('rule' => 'deny'),
                        'site::activity' => array('rule' => 'deny'),
                        'page::groups:owned' => array('rule' => 'deny'),
                    ),
                ),
            ),
        );
            
        if (!is_array($return_value)) {
            return $roles;
        }
        else {
            return array_merge($return_value, $roles);
        }
    }

    Of course I customized the main menu so the usual main options were not visible any more.

  • 1. Little Experience.

    2. Elgg 2.0.2

  • Nikos, thank you for your help,
    this function can be in the file "start.php" my theme?

     

  • @Angelo Rocha: yes, it could be there. But you should read and understand how Roles plugin works in order to apply the right rules in the right way. This was just an example.

  • Hi Nikos, unfortunately for me it is not working, see how I did:

    In my theme, in the file "start.php":

    function change_roles_config( $hook_name, $entity_type, $return_value, $params ) {
       $roles = array(
          DEFAULT_ROLE => array(
             'title'       => 'roles:role:DEFAULT_ROLE',
             'permissions' => array(
                'pages' => array(
                   'blog/add'                   => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                   'blog/add/{$self_guid}'      => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                   'bookmarks/add'              => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                   'bookmarks/add/{$self_guid}' => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                   'file/add'                   => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                   'file/add/{$self_guid}'      => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                   'pages/add'                  => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                   'pages/add/{$self_guid}'     => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                   'blog/all'                   => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                   'bookmarks/all'              => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                   'file/all'                   => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                   'pages/all'                  => array( 'rule' => 'deny', 'forward' => 'dashboard' ),
                ),
             ),
          ),
       );
       if ( ! is_array( $return_value ) ) {
          return $roles;
       } else {
          return array_merge( $return_value, $roles );
       }
    }
    
    elgg_register_plugin_hook_handler( "roles:config", "role", "change_roles_config", 550 );

    But nothing happens, the intention is to make the blog modules, pages, files, etc. Available only for groups, there is another way? Sorry for my bad english.

  • elgg_register_plugin_hook_handler should be inside the init() function and change_roles_config should be outside the init() function.

    So, your start.php will be like this:

    <?php
    
    elgg_register_event_handler('init', 'system', 'plugin_init');
    
    function plugin_init() {
      elgg_register_plugin_hook_handler( "roles:config", "role", "change_roles_config", 550 );
    }
      
    function change_roles_config( $hook_name, $entity_type, $return_value, $params ) {
       ....
       ....
       ....
    }
    
    ?>
    
  • Rohit. thanks for help, see my start.php in pastebin: http://pastebin.com/qCzRs892

    Nothing happens.

    Default users still have access to the modules on the dashboard.

  • Ooops...

    Roles Mod on top.

    Work Fine.