Hi,

A user created some projects but when they click on the 'Project' menu item (q=projects) the projects are not listed. The user is given access rights to 'access own projects / access projects & maintain projects'. I also found that group members, given the same access rights are unable to select project from 'create issue' page (q=node/add/project_issue&gids[]=3). They are also unable to see the projects listed. I even tried giving them 'adminster projects' access rights but as I expected, that only gave them access to the Project administration menu.

I've got Drupal 5.2 installed on Apache 2.0 & php 5.1.3 / mysql 5.0.22. I thought my problems were over when I saw the projects and related modules - I am using them with OG and Events module for my project. But I've been having a lot of problems getting all of these modules to work seemlessly with the new version of project module uploaded 19/8/07 (version 5.x-1.0). Among the errors I was getting is this error when I uploaded it to my current site:

Error (1)
warning: Invalid argument supplied for foreach() in D:\00_WWW\Apache\htdocs\drupal\playground_07h\sites\all\modules\category\category.inc on line 716. 
warning: htmlspecialchars() expects parameter 1 to be string, array given in D:\00_WWW\Apache\htdocs\drupal\playground_07h\includes\bootstrap.inc on line 631.

So I did a clean install of Drupal and now users are unable to view files created. I am not using categories (see this post -169528). I am sure it must be something I needed to do but I need some guide.

Please help.

Comments

hunmonk’s picture

Project: Project » Category
Component: Issues » Code

the error you listed is happening in category module, not project module. reassigning.

dantina’s picture

Project: Category » Project
Component: Code » Projects

Hi Hunmonk,

I may be wrong, but I don't think the problem is the category module and I was hoping you'll take another look at this and see if you can help. I think the problem is in the access restrictions within the function project_db_rewrite_sql in project.module. Unfortunately, I don't have enough expertise in php to sort it out and I am hoping you can help me.

On my site, I have 2 groups of users with different access roles: 'lecturer' & 'student'. Both roles have 'access projects' & 'access issues' but only the 'lecturer' role has 'access issues' ('student' role users can only 'access own issues'). Users of both roles need to have access to project types regardless of who creates the content.

I found that if I set 'student' role users up to 'access issues' then they are able to view projects types created by users of 'lecturer' roles - but I need them to be able to 'access projects' but only 'access own issues'. I may be wrong, but here's the section of code that I think I need to modify

    if (module_exists('project_issue')) {
      $access_issues = user_access('access project issues');
      $access_own_issues = user_access('access own project issues');
      $types .= ", 'project_issue'";
    }
    else {
      $access_issues = TRUE;
      $access_own_issues = TRUE;
    }
    if ($admin_projects || ($access_projects && $access_issues)) {
      // User has full access, nothing to re-write.
      return;
    }
    else {
      // We have to make sure {node} is in the query and know the alias.
      if ($primary_table == 'n' || $primary_table == 'node') {
        // Great, it's the primary table and we already know the alias.
        $alias = $primary_table;
      }
      else {
        // Look for {node} in the query.
        if (!($alias = project_find_alias($query, 'node'))) {
          // Not already in the query, JOIN it.
          $return['join'] = "INNER JOIN {node} pn ON pn.nid = ". $primary_table .'.nid';
          $alias = 'pn';
        }
      }
    }
    // At this point, we know we have to restrict something, and we know what
    // the {node} table's alias is in the query.
    $where = array();

    // First, if the type is not one of the project* ones, we don't care.
    $where[] = "($alias.type NOT IN ($types))";

    // Now, see if the current user can access their own, and allow those.
    global $user;
    $uid = $user->uid;
    if (!$access_projects && user_access('access own projects')) {
      $where[] = "($alias.type = 'project_project' AND $alias.uid = $uid)";
    }
    if (!$access_issues && $access_own_issues) {
      $where[] = "($alias.type = 'project_issue' AND $alias.uid = $uid)";
    }

Thank you very much.

dantina’s picture

Title: Project not listed on project page & create issue page » Project not listed on project page & create issue page - correction!

Meant to say the problem is NOT the category module - sorry, typo error :)

hunmonk’s picture

Title: Project not listed on project page & create issue page - correction! » Project not listed on project page & create issue page
Status: Active » Postponed (maintainer needs more info)

please provide me a list of all contributed modules you're using in this install. i have a sneaky suspicion that something else is going on here...

p.s. if you keep changing the issue title, it makes it harder for me to find. :) only change the issue title to further clarify the nature of the issue.

dantina’s picture

Thanks Hunmonk,

Once again I apologise - I am yet to get my head round how all of these works :) Please bear with me.

The modules installed and enabled are as follows: CCK, event, node profile, organic groups, actions, active select, automatic nodetitles, content templates, date api, panels, pathauto, subform element, token, user import, project and views. I've excluded the core - optional modules or the individual items within the groups (please let me know if you need to know the individual items & the core - optional ones enabled). Category is installed but currently disabled after I found out enabling it was the cause of the error:

Duplicate entry '1' for key 1 query: INSERT INTO vocabulary (vid, name, description, help, multiple, required, hierarchy, relations, tags, weight, module) VALUES (1, 'Project release API compatibility', '', '', 0, 0, 1, 0, 0, 0, 'project_release') in \includes\database.mysql.inc on line 172

I hope this is enough information. And by the way, I've found that I needed to allow 'student' role users to "maintain projects" and "administer projects" before they can 'add project release' or 'view projects'. And I am hoping I can write some code to hide the menu items in navigation from them if that's the only way to give them access to projects and project release - I'll give it a shot anyway.

Thanks.

hunmonk’s picture

disable every module in that list except for the project modules, and try to reproduce the bug.

dantina’s picture

Hi Hunmonk,

Did as you suggested - no change. I installed a new drupal site, enabled only the project modules (didn't even enable og project - since I wasn't enabling og) and after setting up roles / users, logged in as the lecturer role user and created the content as before. Users of 'lecturer' role have rights to "access own projects, access projects, maintain projects / access own project issues, access project issues, create project issues etc". Users of 'student' role have rights to "access own projects, access projects / access own project issues, create project issues etc." Only users of 'lecturer' role was able to create Project content (which is great and as it should be), but only users of this role was able to view the content - as before (the screenshots attached shows the view of project listing page for my 'student' & 'lecturer' role users).

However, even if it had worked, it wouldn't have been an ideal solution as I need project to be able to work with events & og modules at the very least.

dantina.

hunmonk’s picture

Status: Postponed (maintainer needs more info) » Active

my goal isn't to restrict what modules you can use, but to get a more focused idea of where the problem is coming from. w/ only core and project installed, we can most likely say it's a project bug.

hunmonk’s picture

Status: Active » Postponed (maintainer needs more info)

please provide a list of the _exact_ permissions both your roles have. reading the issue it's not clear to me.

dantina’s picture

StatusFileSize
new985.5 KB

A list of permissions attached - and please accept my apologies (I forgot to attach the screenshot referred to in my last post).

Thanks a lot, Hunmonk for being so patient with me :)

dantina

hunmonk’s picture

please provide the list in a non-proprietary format. i'm proud to say i'm not a windows user... :)

aclight’s picture

StatusFileSize
new48.27 KB

While I agree that having .doc files as attachments are annoying, it's not like you have to be a windows user to view a .doc. There are plenty of tools besides MS Word on Windows.

But in any case, the attachment has several image files and some text description. I converted the .doc to a .pdf file. Still proprietary, but perhaps it won't offend your sensibilities quite as much :)

@dantina-In the future, if you can create attachments as image files (.png, .jpg, etc.) when appropriate or at least something like a .pdf (where the ability for users on different operating systems to view the file is better, and the risk of things like macro viruses, etc. is diminished) that would be helpful.

aclight’s picture

Status: Postponed (maintainer needs more info) » Active

forgot to change status

hunmonk’s picture

@aclight: given as many issues as i have to process in this queue, i'd rather not have to deal w/ converting file formats. seems reasonable to me to request a common format. :)

at any rate, thanks for the conversion. let's have a look now...

hunmonk’s picture

Assigned: Unassigned » hunmonk
Status: Active » Needs review
StatusFileSize
new1.64 KB

it appears to me that there is an error in the building of the rewrite query. we're restricting project_project and project_issue node types right off the bat, but they don't get included again in the case where the user only has 'access projects' or 'access issues' permissions.

attached patch tries to correct.

dww’s picture

Assigned: hunmonk » dww
StatusFileSize
new1.93 KB

That works, but it makes the resulting SQL needlessly complicated. For example, given a user with 'access projects' but not 'access project issues', your patch generates the following:

(n.type NOT IN ('project_project', 'project_issue')) OR n.type = 'project_project' OR (n.type = 'project_issue' AND n.uid = 10)

If we try a little harder in this function, we can reduce extra WHERE clauses we don't need. Attached patch works, and keeps the SQL more sane. For the same user as the above example, this just generates:

(n.type NOT IN ('project_issue')) OR (n.type = 'project_issue' AND n.uid = 10)

I tried to comment the changes heavily, but let me know if anything doesn't make sense.

dww’s picture

StatusFileSize
new2.6 KB

Here's another version that keeps the SQL just as sane but should be even more clear to understand what's going on...

hunmonk’s picture

Title: Project not listed on project page & create issue page » db_rewrite for projects not respecting some perms
Version: 5.x-1.0 » 5.x-1.x-dev

$where[] = "($alias.type NOT IN (". implode(', ', $restricted_types) ."))";

does that need to be wrapped in an if (!empty($restricted_types)) {} block, or will restricted types always contain something if we've made it this far in the code? just checking...

changing title to describe what we're trying to handle here.

dww’s picture

Right, the only way $restricted_types would be empty is if the user had both 'access projects' and 'access project issues', but in that case, we bail out of this function much earlier (line 116 in a patched copy of project.module from HEAD).

dww’s picture

StatusFileSize
new2.57 KB

Patch for 4.7.x-* (applies to both -1 and -2 branches). Same logic, and it's not even clear why the 5.x patch doesn't apply cleanly, but oh well...

hunmonk’s picture

Status: Needs review » Reviewed & tested by the community

coding style looks good. tested, and things work as expected.

dww’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD, DRUPAL-4-7--2 and DRUPAL-4-7.

Anonymous’s picture

Status: Fixed » Closed (fixed)