Project:Media Manager
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

I've been using the mmedia_node feature to upload and create documents as nodes. Pretty cool. However, I noticed that when I set the "media_document" content type as an Organic Group post, there is no associated "create document" link on the OG page.

I did some digging and it appears this is because the module for Document content type (i.e., media_document) is "mmedia_node". This is what is returned by: $module = node_get_types('module', $type);

The problem here is that the perm hook is in the "mmedia.module", not the "mmedia_node.module". Therefore, OG (and OGUR for that matter) can't find the permissions for this content type.

I'm not sure if anything can easily be done about this, but if so, it would be nice to have media nodes compatible with Organic Groups.

Thanks.

Comments

#1

I added this to the mmedia_nodes.module:

<?php
/**
*  Implementation of hook_perm().
*/
function mmedia_nodes_perm() {
 
$perms = array(
   
'create media_document',
   
'edit media_document',
   
'delete media_document',
  );

  return
$perms;
}
?>

It resolves some of the issues associated with being able to create and edit media_documents within groups. "Create" link still doesn't appear on OG menu, but a media_document node can now be manipulated within a group.

#2

Personally, I've never had any experience with Organic Groups, so I have no idea on how to do these things.
If I can get some time, I'll look at what to do to get it to work.

#3

Could you try adding this to the mmedia_nodes.module, and telling me if this succeeds?

/**
* Implementation of hook_perm().
*/
function mmedia_nodes_perm() {
  $perms = array();

  $types = mapi_type_list();
  foreach ($types as $type) {
    $perms[] = 'create media_'. $type;
    $perms[] = 'edit any media_'. $type;
    $perms[] = 'edit own media_'. $type;
    $perms[] = 'delete any media'. $type;
    $perms[] = 'delete own media_'. $type;
  }

  return $perms;
}

/**
* Implementation of hook_access().
*/
function mmedia_nodes_access($op, $node, $account) {
  // node must be a valid type for this to handle it
  if (!in_array($node->type, mapi_type_list())) {
    return FALSE;
  }

  switch ($op) {
    case 'create':
      return user_access('create media_'. $node->type, $account) ? TRUE : NULL;
    case 'update':
      return user_access('edit any media_'. $node->type, $account) || (user_access('edit own media_'. $node->type, $account) && ($account->uid == $node->uid)) ? TRUE : NULL;
    case 'delete':
      return user_access('delete any media_'. $node->type, $account) || (user_access('delete own media_'. $node->type, $account) && ($account->uid == $node->uid)) ? TRUE : NULL;
  }
}

If this functions with no problems, I'll add it into CVS.

#4

OK, will do and report back.

#5

Thanks for the quick response. Below is the code that is working with OG. It now creates the "create" link. Also, my ogur code (which double checks these permissions) does not fail on update.

It appears that the mapi type that is actually written into the $node could be different from that maintained in mapi_type_list(), at least it is in the case I've been testing. So, my I modified your code to accomodate that possibility.

<?php
/**
* Implementation of hook_perm().
*/
function mmedia_nodes_perm() {
 
$perms = array();

 
$types = mapi_type_list();
  foreach (
$types as $type) {
   
$perms[] = 'create media_'. $type;
   
$perms[] = 'edit any media_'. $type;
   
$perms[] = 'edit own media_'. $type;
   
$perms[] = 'delete any media_'. $type;
   
$perms[] = 'delete own media_'. $type;
  }

  return
$perms;
}

/**
* Implementation of hook_access().
*/
function mmedia_nodes_access($op, $node, $account) {

  if (
is_object($node)) {
   
$type = $node->type;
  } else {
   
$type = $node;
  }

  if (
substr($type,0,6) == 'media_') $type = substr($type, 6); // Get the mapi type name

  // node must be a valid type for this to handle it
 
if (!in_array($type, mapi_type_list())) {
    return
FALSE;
  }

   switch (
$op) {
    case
'create':
      return
user_access('create media_'. $type, $account) ? TRUE : NULL;
    case
'update':
      return
user_access('edit any media_'. $type, $account) || (user_access('edit own media_'. $type, $account) && ($account->uid == $node->uid)) ? TRUE : NULL;
    case
'delete':
      return
user_access('delete any media_'. $type, $account) || (user_access('delete own media_'. $type, $account) && ($account->uid == $node->uid)) ? TRUE : NULL;
  }
}
?>

This appears to be working correctly now with media documents. Give me a few days to really test it out completely before committing. Again, thanks a bunch.

#6

Status:active» fixed

Ok, I've added this an another fix for the permissions to view a node type to the CVS version.

#7

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.