In the current version, when a user has multiple roles with IMCE enabled, IMCE will only display the folder for the role with the highest priority (which is I believe the role with the role with the smallest ID.

This is logical for personal folders: this way ensure that a user only use a single personal folder.

However, for roles which are assigned to shared folders, a user should be able to contribute to all the shared folders for the roles which are assigned to them, especially have a personal folder, and be able to contribute to a shared folder.

Would it be possible to implement this?

Files: 

Comments

Version:5.x-1.2» 6.x-1.3

Is there a way to get it working ?

Status:Active» Needs review
StatusFileSize
new1.01 KB

Here is a patch to merge all allowed directories from multiple assigned roles.

Permissions and allowed extensions are those from the smaller weight.

Please review

subscribe

Status:Needs review» Closed (won't fix)

This may result in complete rewrite of the configuration profiles.
1 to 1 relation is simpler, which is better.

... which is far from real life !
To achieve such a result with 1 to 1 relation need too much deep and complex configuration profiles which is not really better.

If I transpose your comment for users and roles, a user should have only one role in a 1 to 1 simpler relation too, which would be better...
I don't think RBAC patterns go that way.

Please, can you think about it ?

I don't know if this will help the discussion, but I found a way to do what I need without the patch. Just had to view the problem from a different angle. The approach I have taken is to have multiple shared folders under a single Profile. I define a single profile for all my authors and in the profile I define the folder path with:

php: $names = array(); foreach($user->og_groups as $group){array_push($names,$group[title]);}return $names;

With this configuration, each author sees a single folder for each Organic Group which they are a member. In the end, I like this better than the multiple profiles and roles because the configuration is taken care of in OG.

subscribe

Version:6.x-1.3» 6.x-2.0-beta3

Patch in Comment #2 works for me against 6.x-2.0-beta3 also. Thanks @heltem!

@pgillis : Thank you very much for the great hint.

I changed it to this code :
php: $names = array(); foreach($user->roles as $group){array_push($names,$group);}return $names;

Now a user has access to his shared folder(s) corresponding the role(s) he belongs to.

Hi, I've tried the code from #6 and #9 but I get the following error:
Undefined property: stdClass::$og_groups in eval() (line 1 of /var/www/getloc/sites/all/modules/imce/inc/imce.page.inc(767) : eval()'d code).

It looks like og_groups isn't loaded.

#5: Agree - see as well my comment here:
http://drupal.org/node/1093734#comment-5193938

#10: Drupal7? I had the same error there.

I managed to get it working in Drupal 7 with OG 7.x-dev from 15th of November 2011 (that one introduced og_get_groups_by_user()). In og/og.module I added a function at the end (take care: I have no idea of PHP actually, it fires a DB query for each group, but it works[TM])

<?php
function og_get_group_labels_by_user($account = NULL) {
  if (empty(
$account)) {
    global
$user;
   
$account = $user;
  }
  
$labels = array();
  
$gids = og_get_groups_by_user();
   foreach (
$gids as $group => $gid) {
     
$group = db_select('og', 'o')
         ->
fields('o', array('label'))
         ->
condition('gid', $gid)
         ->
execute()
         ->
fetchObject();
     
$labels[] = $group->label;
   }
   return
$labels;
}
?>

And in IMCE I used:
php: $groups = og_get_group_labels_by_user(); return $groups;

Tokens would be really nice in IMCE, really.

#10 and #12: New version of og -7.x2.0alpha1
I had the same problem as in #10 trying to implement group folders in imce for Drupal 7. The problem is the $user does not contain "og_groups" as mentioned in #6. I'll test the new version of og using the "og_get_groups_by_user" used in #12 and listed here: http://drupalcontrib.org/api/drupal/contributions!og!og.module/7 function. Unfortunately this function is not part of the recommended release 7.x1.3.

Version:6.x-2.0-beta3» 7.x-1.5

Has anyone had success with this so far?

On my site, some users have several roles and need to match more than 1 IMCE profile. I'm on Drupal 7.

Is Organic Groups required for this to work?

Should I use something other than IMCE for this?

In case of IMCE you could use "dynamic" directory paths by using the $user variable. In that case you could set even user specific imce profiles. In case of group profiles you can use organic groups but as I mentioned above it's not that easy. You could also try Filedepot but I have not been able to get this module to work so far. You could also try elFinder, but you will still have to teach him how to treat different profiles. So we're back at IMCE again.

To make #12 work with 7.x-2.x-dev you can use this code

<?php
function og_get_group_labels_by_user($account = NULL) {
  if (empty(
$account)) {
    global
$user;
   
$account = $user;
  }
 
$labels = array();
 
$gnode = og_get_groups_by_user();
 
$gids = $gnode['node'];
  foreach (
$gids as $group => $gid) {
   
$group = db_select('node', 'o')
    ->
fields('o', array('title'))
    ->
condition('nid', $gid)
    ->
execute()
    ->
fetchObject();
   
$labels[] = $group->title;
  }
  return
$labels;
}
?>

#6 & #9 : Works great, thanks for the hint !

The solution in #9 worked for me. I altered the PHP so that authenticated_users can't upload arbitrary files and I wanted all file uploads to start in /LCCC Documents. Modify as you see fit:

php:

$names = array();
$auth_user_string = "authenticated user";

foreach($user->roles as $group)
{
/* We block any old authenticated_user role from uploading
We also start all uploads in /LCCC Documents */
if (strcmp($group, $auth_user_string) < 0) {
array_push($names,"LCCC Documents/" . $group);
}
}
return $names;

#6 and #9, In which file should this piece of code be placed??

I'm speaking for the Drupal 6 (with 7 this is different).
You can place it in the field 'PHP to filter roles by:' into the LDAP -> Groups -> 'LDAP group into Drupal role filtering'

Hello,
I've created a sandbox project here to encapsulate the function detailed in #16

StatusFileSize
new4.87 KB

Alternative approach with views integration:

1. Create a view with name "og groups by user" based on users (Show "Users")
2. Add a contextual filter on User:uid with a default value of "User:uid from currently logged in user"
3. Add a relationship to OG membership: Group Node from OG membership
4. Tweak the output to show a HTML-list (unordered) with fields. Remove all css wrappers and stuff from output.
5. Add field "(Group node from OG membership) Content: Title" to "Fields"

Now you should have a view that lists the groups you're a member of.

6. Save the view and jump into the IMCE settings and edit the profile for "normal" users aka "not-admins":

7. First directory path field gives access to the personal directory (as username) in the users directory:
php: return 'users/'.$user->name;

8. Second directory path field gives access to all group-directories the user is member of inside the groups directory:
php: $names = array(); foreach(views_get_view_result('og_groups_by_user') as $group){array_push($names,'groups/'.preg_replace('/[^a-z0-9]/i', '_',$group->node_og_membership_title));}return $names;

This script is fetching the groups of the current user, is replacing all special chars with "_" and returning the groups for IMCE as folders.

9. Now switch to the admin-profile in IMCE:
10. Simply copy the entries from the normal user profile and additionally add the two directories "users" and "groups". Check the "recursive"-option.
With this the admin-profile has access to all user and group directories.

Done. Attached the view-export. Sorry for the project-related swedish translations... ;-)

#22 worked nicely for me. Would be nice if IMCE opened to the proper group folder....

There is a bug/change in OG 7.x-2.x (https://drupal.org/node/1890370)
that breaks the query. To fix it you have to add an additional relationship (see https://drupal.org/comment/7201968#comment-7201968)

Here is the updated view:

$view = new view();
$view->name = 'og_groups_by_user';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'og groups by user';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'access user profiles';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['exposed_form']['options']['reset_button_label'] = 'Återställ';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['style_options']['default_row_class'] = FALSE;
$handler->display->display_options['style_options']['row_class_special'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['row_options']['default_field_elements'] = FALSE;
/* Relationship: OG membership: OG membership from User */
$handler->display->display_options['relationships']['og_membership_rel']['id'] = 'og_membership_rel';
$handler->display->display_options['relationships']['og_membership_rel']['table'] = 'users';
$handler->display->display_options['relationships']['og_membership_rel']['field'] = 'og_membership_rel';
/* Relationship: OG membership: Group Node from OG membership */
$handler->display->display_options['relationships']['og_membership_related_node_group']['id'] = 'og_membership_related_node_group';
$handler->display->display_options['relationships']['og_membership_related_node_group']['table'] = 'og_membership';
$handler->display->display_options['relationships']['og_membership_related_node_group']['field'] = 'og_membership_related_node_group';
$handler->display->display_options['relationships']['og_membership_related_node_group']['relationship'] = 'og_membership_rel';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['relationship'] = 'og_membership_related_node_group';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['title']['element_default_classes'] = FALSE;
$handler->display->display_options['fields']['title']['hide_alter_empty'] = FALSE;
$handler->display->display_options['fields']['title']['link_to_node'] = FALSE;
/* Sort criterion: User: Created date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'users';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: User: Uid */
$handler->display->display_options['arguments']['uid']['id'] = 'uid';
$handler->display->display_options['arguments']['uid']['table'] = 'users';
$handler->display->display_options['arguments']['uid']['field'] = 'uid';
$handler->display->display_options['arguments']['uid']['default_action'] = 'default';
$handler->display->display_options['arguments']['uid']['exception']['title'] = 'Alla';
$handler->display->display_options['arguments']['uid']['default_argument_type'] = 'current_user';
$handler->display->display_options['arguments']['uid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['uid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['uid']['summary_options']['items_per_page'] = '25';
/* Filter criterion: User: Active */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'users';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = '1';
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;