maxrossello / redmine_extended_watchers

Grant additional issue and project view permissions to watcher users
GNU General Public License v3.0
44 stars 20 forks source link

Activity pages broken. #5

Closed drasill closed 10 years ago

drasill commented 10 years ago

I seem to have a bug in the "activity" pages.

https://gist.github.com/drasill/c773f1e15c38fa48b969#file-sql-error-L38

There's a missing ")".

I'm not sure of what I'm doing, but it seems that this modification fixes it :

diff --git a/lib/extended_watchers_issue_patch.rb b/lib/extended_watchers_issue_patch.rb
index 355dcf0..84f8ffe 100644
--- a/lib/extended_watchers_issue_patch.rb
+++ b/lib/extended_watchers_issue_patch.rb
@@ -22,9 +22,8 @@ module ExtendedWatchersIssuePatch
             prj_clause = options.nil? || options[:project].nil? ? nil : " #{Project.table_name}.id = #{options[:project].id}"
             prj_clause << " OR (#{Project.table_name}.lft > #{options[:project].lft} AND #{Project.table_name}.rgt < #{options[:project].rgt})" if !options.nil? and !options[:project].nil? and options[:with_subprojects]
             watched_group_issues_clause = ""
-            watched_group_issues_clause <<  " OR #{table_name}.id IN (#{watched_issues.join(',')}" <<
-                (prj_clause.nil? ? "" : " AND ( #{prj_clause} )")  <<
-                ")"  unless watched_issues.empty?
+            watched_group_issues_clause <<  " OR #{table_name}.id IN (#{watched_issues.join(',')})" <<
+                (prj_clause.nil? ? "" : " AND ( #{prj_clause} )") unless watched_issues.empty?

             condition = "( " + Project.allowed_to_condition(user, :view_issues, options) do |role, user|
               # Keep the code DRY
maxrossello commented 10 years ago

Hi, your patch makes a lot of sense, thank you. I've taken it into the latest version.

What I'm wondering is why I can't replicate the problem. SQL syntax is generated wrong, but my MySql accepts it. Are you using a different kind of database?

drasill commented 10 years ago

Oh, yes indeed, I'm using Postgresql; I didn't think the query could work with another DB.

I instead though you would not have this error because you'd always have a "prj_clause".

maxrossello commented 10 years ago

Indeed, strange MySql behavior. Thank you again!

drasill commented 10 years ago

Thank to you, this plugin is very useful to me ;)