Skip to content

Commit 9f93a5b

Browse files
author
waleedjaffar
committed
fixes #70. Authorization problem
1 parent 83d2715 commit 9f93a5b

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

lib/redmine_charts/conditions_utils.rb

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,38 @@ def self.from_params(types, project_id, params)
3030
conditions
3131
end
3232

33-
def self.to_options(types)
33+
def self.to_options(project, types)
3434
conditions = {}
35-
members = User.all.collect { |a| [a.name, a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
35+
36+
#members = User.all.collect { |a| [a.name, a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
37+
members = project.members.collect { |a| [a.name, a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
38+
3639
types.each do |type|
3740
case type
38-
when :user_ids then conditions[:user_ids] = members
39-
when :assigned_to_ids then conditions[:assigned_to_ids] = members
40-
when :author_ids then conditions[:author_ids] = members
41-
when :issue_ids then conditions[:issue_ids] = nil
42-
when :project_ids then conditions[:project_ids] = Project.all.collect { |a| [a.name, a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
43-
when :activity_ids then conditions[:activity_ids] = TimeEntryActivity.all.collect { |a| [a.name, a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
44-
when :category_ids then conditions[:category_ids] = IssueCategory.all.collect { |a| ["#{a.project.name} - #{a.name}", a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
45-
when :fixed_version_ids then conditions[:fixed_version_ids] = Version.all.collect { |a| ["#{a.project.name} - #{a.name}", a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
46-
when :tracker_ids then conditions[:tracker_ids] = Tracker.all.collect { |a| [a.name, a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
47-
when :priority_ids then conditions[:priority_ids] = IssuePriority.all.collect { |a| [a.name, a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
48-
when :status_ids then conditions[:status_ids] = IssueStatus.all.collect { |a| [a.name, a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
41+
when :user_ids then conditions[:user_ids] = members unless members.size == 0
42+
when :assigned_to_ids then conditions[:assigned_to_ids] = members unless members.size == 0
43+
when :author_ids then conditions[:author_ids] = members unless members.size == 0
44+
when :issue_ids then conditions[:issue_ids] = nil
45+
46+
#when :project_ids then conditions[:project_ids] = Project.all.collect { |a| [a.name, a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
47+
#Gets Current project and sub projects (of current projects) to which user has access. Both arrays are merged using |
48+
when :project_ids then conditions[:project_ids] = (project.to_a.collect { |a| [a.name, a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }) | (project.children.visible.all.collect { |a| [a.name, a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase })
49+
50+
when :activity_ids then conditions[:activity_ids] = TimeEntryActivity.all(:conditions => ["active=?",true]).collect { |a| [a.name, a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
51+
52+
#when :category_ids then conditions[:category_ids] = IssueCategory.all.collect { |a| ["#{a.project.name} - #{a.name}", a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
53+
when :category_ids then
54+
categories = project.issue_categories.all.collect { |a| ["#{a.project.name} - #{a.name}", a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
55+
conditions[:category_ids] = categories unless categories.size == 0
56+
57+
#when :fixed_version_ids then conditions[:fixed_version_ids] = Version.all.collect { |a| ["#{a.project.name} - #{a.name}", a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
58+
when :fixed_version_ids then
59+
versions = project.versions.all.collect { |a| ["#{a.project.name} - #{a.name}", a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
60+
conditions[:fixed_version_ids] = versions unless versions.size == 0
61+
62+
when :tracker_ids then conditions[:tracker_ids] = Tracker.all.collect { |a| [a.name, a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
63+
when :priority_ids then conditions[:priority_ids] = IssuePriority.all.collect { |a| [a.name, a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
64+
when :status_ids then conditions[:status_ids] = IssueStatus.all.collect { |a| [a.name, a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
4965
end
5066
end
5167
conditions

0 commit comments

Comments
 (0)