OG User Roles and File Upload (upload.module) Issue

Assigned to:somebody
Created:somebody at Sun, 08/12/2007 - 12:07pm
Status:Open (General Task / Priority 1-High)
Case ID:OG User Roles: 72-204

Reported that user with "upload files" role cannot upload files.

It appears that group context is lost when you "attach" a file. arg(0) = upload and arg(1) = js. Need to find a way to use $_SESSION to hold where we are.

This is no help. I found a way to get the group context from the session and if that doesn't work, from the referrer:

// File upload: http://www.scbbs.com/node/135/225#comment-225
if ((arg(0) == 'upload' && arg(1) == 'js') || (arg(0) == 'filemanager' && arg(1) == 'active')) {
$location = 14;
// First, try and get gid from the session cookie
if ($_SESSION['og_last']) $gid = $_SESSION['og_last']->nid;
// If gid is still = 0, then try getting it from referrer
if ($gid == 0 || is_null($gid)) {
if ($ref_arg[1] == 'node' && is_numeric($ref_arg[2]) && $ref_arg[3] == 'edit') {
$nid = (int)$ref_arg[2];
$gid = og_user_roles_getgid($nid, $uid);
// Set group context.
$group_node = node_load($gid);
og_set_group_context($group_node);
}
if ($ref_arg[1] == 'node' && $ref_arg[2] == 'ognodeadd') {
parse_str($ref_query);
$gid = $gids[0];
// Set group context.
$group_node = node_load($gid);
og_set_group_context($group_node);
}
}
}

Still getting "Access denied" pop-up error, even though file uploads (If you click on "Preview", you will see uploaded file in file attachments list): http://www.scbbs.com/node/135/244#comment-244

Looked at upload.module and upload.js. The failure appears to be in _upload_form():

if (user_access('upload files')) {
// This div is hidden when the user uploads through JS.
$form['new'] = array(
'#prefix' => '<div id="attach-hide">',
'#suffix' => '</div>',
);
$form['new']['upload'] = array('#type' => 'file', '#title' => t('Attach new file'), '#size' => 40);
$form['new']['attach'] = array('#type' => 'button', '#value' => t('Attach'), '#name' => 'attach', '#id' => 'attach-button');
// The class triggers the js upload behaviour.
$form['attach-url'] = array('#type' => 'hidden', '#value' => url('upload/js', NULL, NULL, TRUE), '#attributes' => array('class' => 'upload'));
}

Even though this same exact code is executed the first time the attachment form is rendered. For example, here is the initial attachment screen:

Initial Attachment Screen

I browse for file, select it, then click on attach. I get pop-up error:

Pop-up File Upload Error

I click on "OK", and the "Attach" button disappears:

Upload Attach Button Disappears

But, if I click on "Preview" button, I see the file I just uploaded:

Upload Attach Button Re-appears

 

Groups: