Project

General

Profile

Actions

Defect #29848

closed

Query to determine role ids is incorrect

Added by Frank Schwarz about 6 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Database
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Invalid
Affected version:

Description

After migrating to stable branch 3.4, the issues page stopped listing entries except for admin users.

Some debugging revealed a query, that seems to be the cuprit:

SELECT 
  `members`.`user_id`, 
  `members`.`role_id`, 
  `members`.`project_id` 
FROM `members` 
  INNER JOIN `projects` ON `projects`.`id` = `members`.`project_id` 
  INNER JOIN `member_roles` ON `member_roles`.`member_id` = `members`.`id` 
WHERE 
  (projects.status <> 9) AND 
  (members.user_id = 7 OR (projects.is_public = 1 AND members.user_id = 36));

For some reasons unkown to me, the column `members`.`role_id` is always 0. However in table `member_roles`, the corresponding column is filled correctly. IMHO, the query should actually look like this one:

SELECT 
  `members`.`user_id`, 
  `member_roles`.`role_id`,  -- **** instead of `members`.`role_id`
  `members`.`project_id` 
FROM `members` 
  INNER JOIN `projects` ON `projects`.`id` = `members`.`project_id` 
  INNER JOIN `member_roles` ON `member_roles`.`member_id` = `members`.`id` 
WHERE 
  (projects.status <> 9) AND 
  (members.user_id = 7 OR (projects.is_public = 1 AND members.user_id = 36));

The suggested patch is this:

git diff user.rb

diff --git a/app/models/user.rb b/app/models/user.rb
index 357856609..0f0d7d64b 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -614,7 +614,7 @@ class User < Principal
       members = Member.joins(:project, :member_roles).
         where("#{Project.table_name}.status <> 9").
         where("#{Member.table_name}.user_id = ? OR (#{Project.table_name}.is_public = ? AND #{Member.table_name}.user_id = ?)", self.id, true, group_id).
-        pluck(:user_id, :role_id, :project_id)
+        pluck(:user_id, "#{MemberRole.table_name}.role_id", :project_id)

       hash = {}
       members.each do |user_id, role_id, project_id|
Actions

Also available in: Atom PDF