Has anyone integrated elFinder with OG? What I need is to have a separate file space for each OG, and users can only see/manage the files associated with that group.

I'm thinking that have a folder created (via rules hopefully) on creation of each OG group, named by the group/node id (in case the group name should be changed in the future). I have a panel already that is displaying elFinder in each Organic Group on a "Files" tab. What I need to do is restrict elFinder to show me only files in the folder that belongs to the group and nothing else.

Any suggestions how to set up the config for this?

Comments

Cookie.Monster’s picture

I mostly have this working with OG, with the exception of being able to view and create the proper folder due to a token replacement issue I am having (issue posted about that). Once I have it fully working, I'll come back and post some instructions in case others want to do the same.

CarolineCB’s picture

Were you able to make it work? I am also interested in integrating elfinder with organic groups.

CarolineCB’s picture

Since I've seen questions online about the same issue, I will post here how I was able to integrate the two together. The only thing that I haven't been able to figure out yet is how to create an elfinder profile programmatically (that would make it fully automatic).

I created rules so that a new role is added every time a group is created. These roles don't need any special permissions, they are just there for the elfinder profiles to work.

-When a user is added (or accepted, or activated) as a group member, he is given the role.
-When a user is blocked (or removed, or unsubscribes) from a group, the role is removed.

Since I wanted to display ONLY the folder belonging to the group when displaying the file manager, I added some CSS and JavaScript to hide the other folders.

So here it is, step by step:

Rules

New group created

EVENTS
After saving new content


CONDITIONS
Entity is group

Parameter: Entity: [node]



ACTIONS
Execute custom PHP code

$privatePath = variable_get('file_private_path'); // I am storing everything in a private system path
drupal_mkdir($privatePath . "/" . 'NAMEOFDIRECTORY'); // Change the name for what you want it to be

$role = new stdClass();
$role->name = 'ROLENAME'; // Change the role name to what you want it to be.
user_role_save($role);

// Add role to user who created it -- corrected a bug that the created didn't have the role as he is not "added" to the group.
// Get RID of role (role id)
$user = user_load($node->uid);
$rid = db_query("SELECT r.rid FROM {role} r WHERE r.name = :rname", array(':rname' => $role->name))->fetchField();

// Save the user object with the new roles.
$roles = $user->roles + array($rid => $role->name);
user_save($user, array('roles' => $roles));

I also added a "Send mail to all users of a role" because I need the administrator to create the elfinder profile when the group is created.


New group user


EVENTS
User membership has been approved
User has become a group member


CONDITIONS
Data comparison

Parameter: Data to compare: [og-membership:state], Data value: Active
Make sure the data value is switched to direct input mode so you can select "Active".

ACTIONS
Execute custom PHP code

$role_name = 'ROLENAME';
// To get the group id -> $og_membership->gid;

// Get RID of role (role id)
$rid = db_query("SELECT r.rid FROM {role} r WHERE r.name = :rname", array(':rname' => $role_name))->fetchField();

// Save the user object with the new roles.
if (isset($rid) && $rid != "" && !isset($account->roles[$rid])) {
  $roles = $account->roles + array($rid => $role_name);
  user_save($account, array('roles' => $roles));

  // The user wasn't being added to the group as the user_save() was happening on the old user object, 
  //but after the module had added it.
  og_group('node', $og_membership->gid, array(
    'entity_type' => 'user',
    'entity' => $account,
    'field_name' => FALSE,
    'state' => OG_STATE_ACTIVE,
  ));
}

I added the "active" membership condition because I also have private groups and I did not want my users to have the role without being first approved by the group admin.


User blocked/removed from group


EVENTS
User has been removed from group
User membership has been blocked


CONDITIONS
None


ACTIONS
Execute custom PHP code

$role_name = 'ROLENAME'; // Name of role to remove

$key = array_search($role_name, $account->roles);

if ($key) {
    // Get the rid from the roles table.
    $roles = user_roles(TRUE);
    $rid = array_search($role_name, $roles);
    if ($rid) {
       // Make a copy of the roles array, without the deleted one.
       $new_roles = array();
       foreach($account->roles as $id => $name) {
          if ($id != $rid) {
            $new_roles[$id] = $name;
          }
       }     
       // Saves the user without the role
       user_save($account, array('roles' => $new_roles));

      // There is a bug in the OG module so that the $account still contains the $og_membership after it is saved 
      // without the role   (code on top) when the group admin removes it.
      // In order to really remove the user from the group, the line needs to be added.
      og_ungroup('node', $og_membership->gid, 'user', $account);
     }


CSS

.elfinder-navbar-wrapper {
  visibility: hidden;
}

/* I had a problem with the Opera navigator and this is how I fixed it. */
noindex:-o-prefocus, .elfinder-navbar-wrapper {
  display: inline;
}

.elfinder-cwd-view-icons {
  visibility: hidden;
}

Javascript

The Javascript is kind of a real mess right now so if you are wondering how to do it you can comment here and I'll see how I can help. Since the folders are populated by ajax, I added a button that the person has to press to display the folders. It then grabs the references to the folders names, compares it to the URL and unhides the right folder.

ph0enix’s picture

Title: Organic Group integration » [code] Organic Group integration
Assigned: Unassigned » ph0enix
Issue summary: View changes
Status: Active » Needs review
tyrant’s picture

Hi there, how would I integrate this code into it? Thank you

Cookie.Monster’s picture

Sorry I didn't reply or add any updates. My project was cancelled abruptly and I no longer have access to the code I wrote. I wish I could be more help. :(

Here is a link to a thread where I made a code change in elFinder. It was long ago already so I can't remember why I was doing it, but hopefully it points someone in the right direction https://drupal.org/node/1948058

madhusudan’s picture

+1 for this feature,if this gets official it would be very good feature.
#3 code may work, but thats virtual, because its just CSS and JS for hiding folders and files.

mrpauldriver’s picture

I too am very keen to see support for Organic Groups

nwom’s picture

Category: Support request » Feature request
Status: Needs review » Active
Issue tags: -Organic Groups, -OG, -elFinder

This would be a feature request, and setting to Active (since no patch is attached). Also removing the tags. Please read the issue tag guidelines before adding tags.

ph0enix’s picture

Priority: Normal » Minor
ph0enix’s picture

Status: Active » Closed (duplicate)

Moved #33