@@ -1,80 +1,81 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class QueriesController < ApplicationController |
|
18 | class QueriesController < ApplicationController | |
19 | layout 'base' |
|
19 | layout 'base' | |
20 | menu_item :issues |
|
20 | menu_item :issues | |
21 | before_filter :find_query, :except => :new |
|
21 | before_filter :find_query, :except => :new | |
22 |
before_filter :find_project |
|
22 | before_filter :find_optional_project, :only => :new | |
23 |
|
23 | |||
24 | def new |
|
24 | def new | |
25 | @query = Query.new(params[:query]) |
|
25 | @query = Query.new(params[:query]) | |
26 | @query.project = params[:query_is_for_all] ? nil : @project |
|
26 | @query.project = params[:query_is_for_all] ? nil : @project | |
27 | @query.user = User.current |
|
27 | @query.user = User.current | |
28 | @query.is_public = false unless (@query.project && current_role.allowed_to?(:manage_public_queries)) || User.current.admin? |
|
28 | @query.is_public = false unless (@query.project && current_role.allowed_to?(:manage_public_queries)) || User.current.admin? | |
29 | @query.column_names = nil if params[:default_columns] |
|
29 | @query.column_names = nil if params[:default_columns] | |
30 |
|
30 | |||
31 | params[:fields].each do |field| |
|
31 | params[:fields].each do |field| | |
32 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
32 | @query.add_filter(field, params[:operators][field], params[:values][field]) | |
33 | end if params[:fields] |
|
33 | end if params[:fields] | |
34 |
|
34 | |||
35 | if request.post? && params[:confirm] && @query.save |
|
35 | if request.post? && params[:confirm] && @query.save | |
36 | flash[:notice] = l(:notice_successful_create) |
|
36 | flash[:notice] = l(:notice_successful_create) | |
37 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query |
|
37 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query | |
38 | return |
|
38 | return | |
39 | end |
|
39 | end | |
40 | render :layout => false if request.xhr? |
|
40 | render :layout => false if request.xhr? | |
41 | end |
|
41 | end | |
42 |
|
42 | |||
43 | def edit |
|
43 | def edit | |
44 | if request.post? |
|
44 | if request.post? | |
45 | @query.filters = {} |
|
45 | @query.filters = {} | |
46 | params[:fields].each do |field| |
|
46 | params[:fields].each do |field| | |
47 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
47 | @query.add_filter(field, params[:operators][field], params[:values][field]) | |
48 | end if params[:fields] |
|
48 | end if params[:fields] | |
49 | @query.attributes = params[:query] |
|
49 | @query.attributes = params[:query] | |
50 | @query.project = nil if params[:query_is_for_all] |
|
50 | @query.project = nil if params[:query_is_for_all] | |
51 | @query.is_public = false unless (@query.project && current_role.allowed_to?(:manage_public_queries)) || User.current.admin? |
|
51 | @query.is_public = false unless (@query.project && current_role.allowed_to?(:manage_public_queries)) || User.current.admin? | |
52 | @query.column_names = nil if params[:default_columns] |
|
52 | @query.column_names = nil if params[:default_columns] | |
53 |
|
53 | |||
54 | if @query.save |
|
54 | if @query.save | |
55 | flash[:notice] = l(:notice_successful_update) |
|
55 | flash[:notice] = l(:notice_successful_update) | |
56 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query |
|
56 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query | |
57 | end |
|
57 | end | |
58 | end |
|
58 | end | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | def destroy |
|
61 | def destroy | |
62 | @query.destroy if request.post? |
|
62 | @query.destroy if request.post? | |
63 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 |
|
63 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 | |
64 | end |
|
64 | end | |
65 |
|
65 | |||
66 | private |
|
66 | private | |
67 | def find_query |
|
67 | def find_query | |
68 | @query = Query.find(params[:id]) |
|
68 | @query = Query.find(params[:id]) | |
69 | @project = @query.project |
|
69 | @project = @query.project | |
70 | render_403 unless @query.editable_by?(User.current) |
|
70 | render_403 unless @query.editable_by?(User.current) | |
71 | rescue ActiveRecord::RecordNotFound |
|
71 | rescue ActiveRecord::RecordNotFound | |
72 | render_404 |
|
72 | render_404 | |
73 | end |
|
73 | end | |
74 |
|
74 | |||
75 | def find_project |
|
75 | def find_optional_project | |
76 | @project = Project.find(params[:project_id]) |
|
76 | @project = Project.find(params[:project_id]) if params[:project_id] | |
|
77 | User.current.allowed_to?(:save_queries, @project, :global => true) | |||
77 | rescue ActiveRecord::RecordNotFound |
|
78 | rescue ActiveRecord::RecordNotFound | |
78 | render_404 |
|
79 | render_404 | |
79 | end |
|
80 | end | |
80 | end |
|
81 | end |
@@ -1,277 +1,286 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require "digest/sha1" |
|
18 | require "digest/sha1" | |
19 |
|
19 | |||
20 | class User < ActiveRecord::Base |
|
20 | class User < ActiveRecord::Base | |
21 | # Account statuses |
|
21 | # Account statuses | |
22 | STATUS_ANONYMOUS = 0 |
|
22 | STATUS_ANONYMOUS = 0 | |
23 | STATUS_ACTIVE = 1 |
|
23 | STATUS_ACTIVE = 1 | |
24 | STATUS_REGISTERED = 2 |
|
24 | STATUS_REGISTERED = 2 | |
25 | STATUS_LOCKED = 3 |
|
25 | STATUS_LOCKED = 3 | |
26 |
|
26 | |||
27 | USER_FORMATS = { |
|
27 | USER_FORMATS = { | |
28 | :firstname_lastname => '#{firstname} #{lastname}', |
|
28 | :firstname_lastname => '#{firstname} #{lastname}', | |
29 | :firstname => '#{firstname}', |
|
29 | :firstname => '#{firstname}', | |
30 | :lastname_firstname => '#{lastname} #{firstname}', |
|
30 | :lastname_firstname => '#{lastname} #{firstname}', | |
31 | :lastname_coma_firstname => '#{lastname}, #{firstname}', |
|
31 | :lastname_coma_firstname => '#{lastname}, #{firstname}', | |
32 | :username => '#{login}' |
|
32 | :username => '#{login}' | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | has_many :memberships, :class_name => 'Member', :include => [ :project, :role ], :conditions => "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}", :order => "#{Project.table_name}.name", :dependent => :delete_all |
|
35 | has_many :memberships, :class_name => 'Member', :include => [ :project, :role ], :conditions => "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}", :order => "#{Project.table_name}.name", :dependent => :delete_all | |
36 | has_many :projects, :through => :memberships |
|
36 | has_many :projects, :through => :memberships | |
37 | has_many :custom_values, :dependent => :delete_all, :as => :customized |
|
37 | has_many :custom_values, :dependent => :delete_all, :as => :customized | |
38 | has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify |
|
38 | has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify | |
39 | has_one :preference, :dependent => :destroy, :class_name => 'UserPreference' |
|
39 | has_one :preference, :dependent => :destroy, :class_name => 'UserPreference' | |
40 | has_one :rss_token, :dependent => :destroy, :class_name => 'Token', :conditions => "action='feeds'" |
|
40 | has_one :rss_token, :dependent => :destroy, :class_name => 'Token', :conditions => "action='feeds'" | |
41 | belongs_to :auth_source |
|
41 | belongs_to :auth_source | |
42 |
|
42 | |||
43 | attr_accessor :password, :password_confirmation |
|
43 | attr_accessor :password, :password_confirmation | |
44 | attr_accessor :last_before_login_on |
|
44 | attr_accessor :last_before_login_on | |
45 | # Prevents unauthorized assignments |
|
45 | # Prevents unauthorized assignments | |
46 | attr_protected :login, :admin, :password, :password_confirmation, :hashed_password |
|
46 | attr_protected :login, :admin, :password, :password_confirmation, :hashed_password | |
47 |
|
47 | |||
48 | validates_presence_of :login, :firstname, :lastname, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } |
|
48 | validates_presence_of :login, :firstname, :lastname, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) } | |
49 | validates_uniqueness_of :login, :if => Proc.new { |user| !user.login.blank? } |
|
49 | validates_uniqueness_of :login, :if => Proc.new { |user| !user.login.blank? } | |
50 | validates_uniqueness_of :mail, :if => Proc.new { |user| !user.mail.blank? } |
|
50 | validates_uniqueness_of :mail, :if => Proc.new { |user| !user.mail.blank? } | |
51 | # Login must contain lettres, numbers, underscores only |
|
51 | # Login must contain lettres, numbers, underscores only | |
52 | validates_format_of :login, :with => /^[a-z0-9_\-@\.]*$/i |
|
52 | validates_format_of :login, :with => /^[a-z0-9_\-@\.]*$/i | |
53 | validates_length_of :login, :maximum => 30 |
|
53 | validates_length_of :login, :maximum => 30 | |
54 | validates_format_of :firstname, :lastname, :with => /^[\w\s\'\-]*$/i |
|
54 | validates_format_of :firstname, :lastname, :with => /^[\w\s\'\-]*$/i | |
55 | validates_length_of :firstname, :lastname, :maximum => 30 |
|
55 | validates_length_of :firstname, :lastname, :maximum => 30 | |
56 | validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :allow_nil => true |
|
56 | validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :allow_nil => true | |
57 | validates_length_of :mail, :maximum => 60, :allow_nil => true |
|
57 | validates_length_of :mail, :maximum => 60, :allow_nil => true | |
58 | validates_length_of :password, :minimum => 4, :allow_nil => true |
|
58 | validates_length_of :password, :minimum => 4, :allow_nil => true | |
59 | validates_confirmation_of :password, :allow_nil => true |
|
59 | validates_confirmation_of :password, :allow_nil => true | |
60 | validates_associated :custom_values, :on => :update |
|
60 | validates_associated :custom_values, :on => :update | |
61 |
|
61 | |||
62 | def before_create |
|
62 | def before_create | |
63 | self.mail_notification = false |
|
63 | self.mail_notification = false | |
64 | true |
|
64 | true | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | def before_save |
|
67 | def before_save | |
68 | # update hashed_password if password was set |
|
68 | # update hashed_password if password was set | |
69 | self.hashed_password = User.hash_password(self.password) if self.password |
|
69 | self.hashed_password = User.hash_password(self.password) if self.password | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | def self.active |
|
72 | def self.active | |
73 | with_scope :find => { :conditions => [ "status = ?", STATUS_ACTIVE ] } do |
|
73 | with_scope :find => { :conditions => [ "status = ?", STATUS_ACTIVE ] } do | |
74 | yield |
|
74 | yield | |
75 | end |
|
75 | end | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | def self.find_active(*args) |
|
78 | def self.find_active(*args) | |
79 | active do |
|
79 | active do | |
80 | find(*args) |
|
80 | find(*args) | |
81 | end |
|
81 | end | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | # Returns the user that matches provided login and password, or nil |
|
84 | # Returns the user that matches provided login and password, or nil | |
85 | def self.try_to_login(login, password) |
|
85 | def self.try_to_login(login, password) | |
86 | # Make sure no one can sign in with an empty password |
|
86 | # Make sure no one can sign in with an empty password | |
87 | return nil if password.to_s.empty? |
|
87 | return nil if password.to_s.empty? | |
88 | user = find(:first, :conditions => ["login=?", login]) |
|
88 | user = find(:first, :conditions => ["login=?", login]) | |
89 | if user |
|
89 | if user | |
90 | # user is already in local database |
|
90 | # user is already in local database | |
91 | return nil if !user.active? |
|
91 | return nil if !user.active? | |
92 | if user.auth_source |
|
92 | if user.auth_source | |
93 | # user has an external authentication method |
|
93 | # user has an external authentication method | |
94 | return nil unless user.auth_source.authenticate(login, password) |
|
94 | return nil unless user.auth_source.authenticate(login, password) | |
95 | else |
|
95 | else | |
96 | # authentication with local password |
|
96 | # authentication with local password | |
97 | return nil unless User.hash_password(password) == user.hashed_password |
|
97 | return nil unless User.hash_password(password) == user.hashed_password | |
98 | end |
|
98 | end | |
99 | else |
|
99 | else | |
100 | # user is not yet registered, try to authenticate with available sources |
|
100 | # user is not yet registered, try to authenticate with available sources | |
101 | attrs = AuthSource.authenticate(login, password) |
|
101 | attrs = AuthSource.authenticate(login, password) | |
102 | if attrs |
|
102 | if attrs | |
103 | onthefly = new(*attrs) |
|
103 | onthefly = new(*attrs) | |
104 | onthefly.login = login |
|
104 | onthefly.login = login | |
105 | onthefly.language = Setting.default_language |
|
105 | onthefly.language = Setting.default_language | |
106 | if onthefly.save |
|
106 | if onthefly.save | |
107 | user = find(:first, :conditions => ["login=?", login]) |
|
107 | user = find(:first, :conditions => ["login=?", login]) | |
108 | logger.info("User '#{user.login}' created on the fly.") if logger |
|
108 | logger.info("User '#{user.login}' created on the fly.") if logger | |
109 | end |
|
109 | end | |
110 | end |
|
110 | end | |
111 | end |
|
111 | end | |
112 | user.update_attribute(:last_login_on, Time.now) if user |
|
112 | user.update_attribute(:last_login_on, Time.now) if user | |
113 | user |
|
113 | user | |
114 |
|
114 | |||
115 | rescue => text |
|
115 | rescue => text | |
116 | raise text |
|
116 | raise text | |
117 | end |
|
117 | end | |
118 |
|
118 | |||
119 | # Return user's full name for display |
|
119 | # Return user's full name for display | |
120 | def name(formatter = nil) |
|
120 | def name(formatter = nil) | |
121 | f = USER_FORMATS[formatter || Setting.user_format] || USER_FORMATS[:firstname_lastname] |
|
121 | f = USER_FORMATS[formatter || Setting.user_format] || USER_FORMATS[:firstname_lastname] | |
122 | eval '"' + f + '"' |
|
122 | eval '"' + f + '"' | |
123 | end |
|
123 | end | |
124 |
|
124 | |||
125 | def active? |
|
125 | def active? | |
126 | self.status == STATUS_ACTIVE |
|
126 | self.status == STATUS_ACTIVE | |
127 | end |
|
127 | end | |
128 |
|
128 | |||
129 | def registered? |
|
129 | def registered? | |
130 | self.status == STATUS_REGISTERED |
|
130 | self.status == STATUS_REGISTERED | |
131 | end |
|
131 | end | |
132 |
|
132 | |||
133 | def locked? |
|
133 | def locked? | |
134 | self.status == STATUS_LOCKED |
|
134 | self.status == STATUS_LOCKED | |
135 | end |
|
135 | end | |
136 |
|
136 | |||
137 | def check_password?(clear_password) |
|
137 | def check_password?(clear_password) | |
138 | User.hash_password(clear_password) == self.hashed_password |
|
138 | User.hash_password(clear_password) == self.hashed_password | |
139 | end |
|
139 | end | |
140 |
|
140 | |||
141 | def pref |
|
141 | def pref | |
142 | self.preference ||= UserPreference.new(:user => self) |
|
142 | self.preference ||= UserPreference.new(:user => self) | |
143 | end |
|
143 | end | |
144 |
|
144 | |||
145 | def time_zone |
|
145 | def time_zone | |
146 | self.pref.time_zone.nil? ? nil : TimeZone[self.pref.time_zone] |
|
146 | self.pref.time_zone.nil? ? nil : TimeZone[self.pref.time_zone] | |
147 | end |
|
147 | end | |
148 |
|
148 | |||
149 | def wants_comments_in_reverse_order? |
|
149 | def wants_comments_in_reverse_order? | |
150 | self.pref[:comments_sorting] == 'desc' |
|
150 | self.pref[:comments_sorting] == 'desc' | |
151 | end |
|
151 | end | |
152 |
|
152 | |||
153 | # Return user's RSS key (a 40 chars long string), used to access feeds |
|
153 | # Return user's RSS key (a 40 chars long string), used to access feeds | |
154 | def rss_key |
|
154 | def rss_key | |
155 | token = self.rss_token || Token.create(:user => self, :action => 'feeds') |
|
155 | token = self.rss_token || Token.create(:user => self, :action => 'feeds') | |
156 | token.value |
|
156 | token.value | |
157 | end |
|
157 | end | |
158 |
|
158 | |||
159 | # Return an array of project ids for which the user has explicitly turned mail notifications on |
|
159 | # Return an array of project ids for which the user has explicitly turned mail notifications on | |
160 | def notified_projects_ids |
|
160 | def notified_projects_ids | |
161 | @notified_projects_ids ||= memberships.select {|m| m.mail_notification?}.collect(&:project_id) |
|
161 | @notified_projects_ids ||= memberships.select {|m| m.mail_notification?}.collect(&:project_id) | |
162 | end |
|
162 | end | |
163 |
|
163 | |||
164 | def notified_project_ids=(ids) |
|
164 | def notified_project_ids=(ids) | |
165 | Member.update_all("mail_notification = #{connection.quoted_false}", ['user_id = ?', id]) |
|
165 | Member.update_all("mail_notification = #{connection.quoted_false}", ['user_id = ?', id]) | |
166 | Member.update_all("mail_notification = #{connection.quoted_true}", ['user_id = ? AND project_id IN (?)', id, ids]) if ids && !ids.empty? |
|
166 | Member.update_all("mail_notification = #{connection.quoted_true}", ['user_id = ? AND project_id IN (?)', id, ids]) if ids && !ids.empty? | |
167 | @notified_projects_ids = nil |
|
167 | @notified_projects_ids = nil | |
168 | notified_projects_ids |
|
168 | notified_projects_ids | |
169 | end |
|
169 | end | |
170 |
|
170 | |||
171 | def self.find_by_rss_key(key) |
|
171 | def self.find_by_rss_key(key) | |
172 | token = Token.find_by_value(key) |
|
172 | token = Token.find_by_value(key) | |
173 | token && token.user.active? ? token.user : nil |
|
173 | token && token.user.active? ? token.user : nil | |
174 | end |
|
174 | end | |
175 |
|
175 | |||
176 | def self.find_by_autologin_key(key) |
|
176 | def self.find_by_autologin_key(key) | |
177 | token = Token.find_by_action_and_value('autologin', key) |
|
177 | token = Token.find_by_action_and_value('autologin', key) | |
178 | token && (token.created_on > Setting.autologin.to_i.day.ago) && token.user.active? ? token.user : nil |
|
178 | token && (token.created_on > Setting.autologin.to_i.day.ago) && token.user.active? ? token.user : nil | |
179 | end |
|
179 | end | |
180 |
|
180 | |||
181 | def <=>(user) |
|
181 | def <=>(user) | |
182 | if user.nil? |
|
182 | if user.nil? | |
183 | -1 |
|
183 | -1 | |
184 | elsif lastname.to_s.downcase == user.lastname.to_s.downcase |
|
184 | elsif lastname.to_s.downcase == user.lastname.to_s.downcase | |
185 | firstname.to_s.downcase <=> user.firstname.to_s.downcase |
|
185 | firstname.to_s.downcase <=> user.firstname.to_s.downcase | |
186 | else |
|
186 | else | |
187 | lastname.to_s.downcase <=> user.lastname.to_s.downcase |
|
187 | lastname.to_s.downcase <=> user.lastname.to_s.downcase | |
188 | end |
|
188 | end | |
189 | end |
|
189 | end | |
190 |
|
190 | |||
191 | def to_s |
|
191 | def to_s | |
192 | name |
|
192 | name | |
193 | end |
|
193 | end | |
194 |
|
194 | |||
195 | def logged? |
|
195 | def logged? | |
196 | true |
|
196 | true | |
197 | end |
|
197 | end | |
198 |
|
198 | |||
199 | # Return user's role for project |
|
199 | # Return user's role for project | |
200 | def role_for_project(project) |
|
200 | def role_for_project(project) | |
201 | # No role on archived projects |
|
201 | # No role on archived projects | |
202 | return nil unless project && project.active? |
|
202 | return nil unless project && project.active? | |
203 | if logged? |
|
203 | if logged? | |
204 | # Find project membership |
|
204 | # Find project membership | |
205 | membership = memberships.detect {|m| m.project_id == project.id} |
|
205 | membership = memberships.detect {|m| m.project_id == project.id} | |
206 | if membership |
|
206 | if membership | |
207 | membership.role |
|
207 | membership.role | |
208 | else |
|
208 | else | |
209 | @role_non_member ||= Role.non_member |
|
209 | @role_non_member ||= Role.non_member | |
210 | end |
|
210 | end | |
211 | else |
|
211 | else | |
212 | @role_anonymous ||= Role.anonymous |
|
212 | @role_anonymous ||= Role.anonymous | |
213 | end |
|
213 | end | |
214 | end |
|
214 | end | |
215 |
|
215 | |||
216 | # Return true if the user is a member of project |
|
216 | # Return true if the user is a member of project | |
217 | def member_of?(project) |
|
217 | def member_of?(project) | |
218 | role_for_project(project).member? |
|
218 | role_for_project(project).member? | |
219 | end |
|
219 | end | |
220 |
|
220 | |||
221 | # Return true if the user is allowed to do the specified action on project |
|
221 | # Return true if the user is allowed to do the specified action on project | |
222 | # action can be: |
|
222 | # action can be: | |
223 | # * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit') |
|
223 | # * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit') | |
224 | # * a permission Symbol (eg. :edit_project) |
|
224 | # * a permission Symbol (eg. :edit_project) | |
225 | def allowed_to?(action, project) |
|
225 | def allowed_to?(action, project, options={}) | |
226 | # No action allowed on archived projects |
|
226 | if project | |
227 | return false unless project.active? |
|
227 | # No action allowed on archived projects | |
228 | # No action allowed on disabled modules |
|
228 | return false unless project.active? | |
229 | return false unless project.allows_to?(action) |
|
229 | # No action allowed on disabled modules | |
230 | # Admin users are authorized for anything else |
|
230 | return false unless project.allows_to?(action) | |
231 | return true if admin? |
|
231 | # Admin users are authorized for anything else | |
232 |
|
232 | return true if admin? | ||
233 | role = role_for_project(project) |
|
233 | ||
234 | return false unless role |
|
234 | role = role_for_project(project) | |
235 | role.allowed_to?(action) && (project.is_public? || role.member?) |
|
235 | return false unless role | |
|
236 | role.allowed_to?(action) && (project.is_public? || role.member?) | |||
|
237 | ||||
|
238 | elsif options[:global] | |||
|
239 | # authorize if user has at least one role that has this permission | |||
|
240 | roles = memberships.collect {|m| m.role}.uniq | |||
|
241 | roles.detect {|r| r.allowed_to?(action)} | |||
|
242 | else | |||
|
243 | false | |||
|
244 | end | |||
236 | end |
|
245 | end | |
237 |
|
246 | |||
238 | def self.current=(user) |
|
247 | def self.current=(user) | |
239 | @current_user = user |
|
248 | @current_user = user | |
240 | end |
|
249 | end | |
241 |
|
250 | |||
242 | def self.current |
|
251 | def self.current | |
243 | @current_user ||= User.anonymous |
|
252 | @current_user ||= User.anonymous | |
244 | end |
|
253 | end | |
245 |
|
254 | |||
246 | def self.anonymous |
|
255 | def self.anonymous | |
247 | return @anonymous_user if @anonymous_user |
|
256 | return @anonymous_user if @anonymous_user | |
248 | anonymous_user = AnonymousUser.find(:first) |
|
257 | anonymous_user = AnonymousUser.find(:first) | |
249 | if anonymous_user.nil? |
|
258 | if anonymous_user.nil? | |
250 | anonymous_user = AnonymousUser.create(:lastname => 'Anonymous', :firstname => '', :mail => '', :login => '', :status => 0) |
|
259 | anonymous_user = AnonymousUser.create(:lastname => 'Anonymous', :firstname => '', :mail => '', :login => '', :status => 0) | |
251 | raise 'Unable to create the anonymous user.' if anonymous_user.new_record? |
|
260 | raise 'Unable to create the anonymous user.' if anonymous_user.new_record? | |
252 | end |
|
261 | end | |
253 | @anonymous_user = anonymous_user |
|
262 | @anonymous_user = anonymous_user | |
254 | end |
|
263 | end | |
255 |
|
264 | |||
256 | private |
|
265 | private | |
257 | # Return password digest |
|
266 | # Return password digest | |
258 | def self.hash_password(clear_password) |
|
267 | def self.hash_password(clear_password) | |
259 | Digest::SHA1.hexdigest(clear_password || "") |
|
268 | Digest::SHA1.hexdigest(clear_password || "") | |
260 | end |
|
269 | end | |
261 | end |
|
270 | end | |
262 |
|
271 | |||
263 | class AnonymousUser < User |
|
272 | class AnonymousUser < User | |
264 |
|
273 | |||
265 | def validate_on_create |
|
274 | def validate_on_create | |
266 | # There should be only one AnonymousUser in the database |
|
275 | # There should be only one AnonymousUser in the database | |
267 | errors.add_to_base 'An anonymous user already exists.' if AnonymousUser.find(:first) |
|
276 | errors.add_to_base 'An anonymous user already exists.' if AnonymousUser.find(:first) | |
268 | end |
|
277 | end | |
269 |
|
278 | |||
270 | # Overrides a few properties |
|
279 | # Overrides a few properties | |
271 | def logged?; false end |
|
280 | def logged?; false end | |
272 | def admin; false end |
|
281 | def admin; false end | |
273 | def name; 'Anonymous' end |
|
282 | def name; 'Anonymous' end | |
274 | def mail; nil end |
|
283 | def mail; nil end | |
275 | def time_zone; nil end |
|
284 | def time_zone; nil end | |
276 | def rss_key; nil end |
|
285 | def rss_key; nil end | |
277 | end |
|
286 | end |
@@ -1,14 +1,14 | |||||
1 | <% if @project %> |
|
|||
2 |
|
|
1 | <h3><%= l(:label_issue_plural) %></h3> | |
3 | <%= link_to l(:label_issue_view_all), { :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 } %><br /> |
|
2 | <%= link_to l(:label_issue_view_all), { :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 } %><br /> | |
|
3 | <% if @project %> | |||
4 | <%= link_to l(:field_summary), :controller => 'reports', :action => 'issue_report', :id => @project %><br /> |
|
4 | <%= link_to l(:field_summary), :controller => 'reports', :action => 'issue_report', :id => @project %><br /> | |
5 | <%= link_to l(:label_change_log), :controller => 'projects', :action => 'changelog', :id => @project %> |
|
5 | <%= link_to l(:label_change_log), :controller => 'projects', :action => 'changelog', :id => @project %> | |
6 | <% end %> |
|
6 | <% end %> | |
7 |
|
7 | |||
8 | <% unless sidebar_queries.empty? -%> |
|
8 | <% unless sidebar_queries.empty? -%> | |
9 | <h3><%= l(:label_query_plural) %></h3> |
|
9 | <h3><%= l(:label_query_plural) %></h3> | |
10 |
|
10 | |||
11 | <% sidebar_queries.each do |query| -%> |
|
11 | <% sidebar_queries.each do |query| -%> | |
12 | <%= link_to query.name, :controller => 'issues', :action => 'index', :project_id => @project, :query_id => query %><br /> |
|
12 | <%= link_to query.name, :controller => 'issues', :action => 'index', :project_id => @project, :query_id => query %><br /> | |
13 | <% end -%> |
|
13 | <% end -%> | |
14 | <% end -%> |
|
14 | <% end -%> |
@@ -1,67 +1,67 | |||||
1 | <% if @query.new_record? %> |
|
1 | <% if @query.new_record? %> | |
2 | <h2><%=l(:label_issue_plural)%></h2> |
|
2 | <h2><%=l(:label_issue_plural)%></h2> | |
3 | <% html_title(l(:label_issue_plural)) %> |
|
3 | <% html_title(l(:label_issue_plural)) %> | |
4 |
|
4 | |||
5 | <% form_tag({ :controller => 'queries', :action => 'new' }, :id => 'query_form') do %> |
|
5 | <% form_tag({ :controller => 'queries', :action => 'new' }, :id => 'query_form') do %> | |
6 | <%= hidden_field_tag('project_id', @project.id) if @project %> |
|
6 | <%= hidden_field_tag('project_id', @project.id) if @project %> | |
7 | <fieldset id="filters"><legend><%= l(:label_filter_plural) %></legend> |
|
7 | <fieldset id="filters"><legend><%= l(:label_filter_plural) %></legend> | |
8 | <%= render :partial => 'queries/filters', :locals => {:query => @query} %> |
|
8 | <%= render :partial => 'queries/filters', :locals => {:query => @query} %> | |
9 | <p class="buttons"> |
|
9 | <p class="buttons"> | |
10 | <%= link_to_remote l(:button_apply), |
|
10 | <%= link_to_remote l(:button_apply), | |
11 | { :url => { :set_filter => 1 }, |
|
11 | { :url => { :set_filter => 1 }, | |
12 | :update => "content", |
|
12 | :update => "content", | |
13 | :with => "Form.serialize('query_form')" |
|
13 | :with => "Form.serialize('query_form')" | |
14 | }, :class => 'icon icon-checked' %> |
|
14 | }, :class => 'icon icon-checked' %> | |
15 |
|
15 | |||
16 | <%= link_to_remote l(:button_clear), |
|
16 | <%= link_to_remote l(:button_clear), | |
17 | { :url => { :set_filter => 1 }, |
|
17 | { :url => { :set_filter => 1 }, | |
18 | :update => "content", |
|
18 | :update => "content", | |
19 | }, :class => 'icon icon-reload' %> |
|
19 | }, :class => 'icon icon-reload' %> | |
20 |
|
20 | |||
21 |
<% if |
|
21 | <% if User.current.allowed_to?(:save_queries, @project, :global => true) %> | |
22 | <%= link_to l(:button_save), {}, :onclick => "$('query_form').submit(); return false;", :class => 'icon icon-save' %> |
|
22 | <%= link_to l(:button_save), {}, :onclick => "$('query_form').submit(); return false;", :class => 'icon icon-save' %> | |
23 | <% end %> |
|
23 | <% end %> | |
24 | </p> |
|
24 | </p> | |
25 | </fieldset> |
|
25 | </fieldset> | |
26 | <% end %> |
|
26 | <% end %> | |
27 | <% else %> |
|
27 | <% else %> | |
28 | <div class="contextual"> |
|
28 | <div class="contextual"> | |
29 | <% if @query.editable_by?(User.current) %> |
|
29 | <% if @query.editable_by?(User.current) %> | |
30 | <%= link_to l(:button_edit), {:controller => 'queries', :action => 'edit', :id => @query}, :class => 'icon icon-edit' %> |
|
30 | <%= link_to l(:button_edit), {:controller => 'queries', :action => 'edit', :id => @query}, :class => 'icon icon-edit' %> | |
31 | <%= link_to l(:button_delete), {:controller => 'queries', :action => 'destroy', :id => @query}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %> |
|
31 | <%= link_to l(:button_delete), {:controller => 'queries', :action => 'destroy', :id => @query}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %> | |
32 | <% end %> |
|
32 | <% end %> | |
33 | </div> |
|
33 | </div> | |
34 | <h2><%=h @query.name %></h2> |
|
34 | <h2><%=h @query.name %></h2> | |
35 | <div id="query_form"></div> |
|
35 | <div id="query_form"></div> | |
36 | <% html_title @query.name %> |
|
36 | <% html_title @query.name %> | |
37 | <% end %> |
|
37 | <% end %> | |
38 | <%= error_messages_for 'query' %> |
|
38 | <%= error_messages_for 'query' %> | |
39 | <% if @query.valid? %> |
|
39 | <% if @query.valid? %> | |
40 | <% if @issues.empty? %> |
|
40 | <% if @issues.empty? %> | |
41 | <p class="nodata"><%= l(:label_no_data) %></p> |
|
41 | <p class="nodata"><%= l(:label_no_data) %></p> | |
42 | <% else %> |
|
42 | <% else %> | |
43 | <%= render :partial => 'issues/list', :locals => {:issues => @issues, :query => @query} %> |
|
43 | <%= render :partial => 'issues/list', :locals => {:issues => @issues, :query => @query} %> | |
44 | <p class="pagination"><%= pagination_links_full @issue_pages, @issue_count %></p> |
|
44 | <p class="pagination"><%= pagination_links_full @issue_pages, @issue_count %></p> | |
45 |
|
45 | |||
46 | <p class="other-formats"> |
|
46 | <p class="other-formats"> | |
47 | <%= l(:label_export_to) %> |
|
47 | <%= l(:label_export_to) %> | |
48 | <span><%= link_to 'Atom', {:format => 'atom', :key => User.current.rss_key}, :class => 'feed' %></span> |
|
48 | <span><%= link_to 'Atom', {:format => 'atom', :key => User.current.rss_key}, :class => 'feed' %></span> | |
49 | <span><%= link_to 'CSV', {:format => 'csv'}, :class => 'csv' %></span> |
|
49 | <span><%= link_to 'CSV', {:format => 'csv'}, :class => 'csv' %></span> | |
50 | <span><%= link_to 'PDF', {:format => 'pdf'}, :class => 'pdf' %></span> |
|
50 | <span><%= link_to 'PDF', {:format => 'pdf'}, :class => 'pdf' %></span> | |
51 | </p> |
|
51 | </p> | |
52 | <% end %> |
|
52 | <% end %> | |
53 | <% end %> |
|
53 | <% end %> | |
54 |
|
54 | |||
55 | <% content_for :sidebar do %> |
|
55 | <% content_for :sidebar do %> | |
56 | <%= render :partial => 'issues/sidebar' %> |
|
56 | <%= render :partial => 'issues/sidebar' %> | |
57 | <% end %> |
|
57 | <% end %> | |
58 |
|
58 | |||
59 | <% content_for :header_tags do %> |
|
59 | <% content_for :header_tags do %> | |
60 | <%= auto_discovery_link_tag(:atom, {:query_id => @query, :format => 'atom', :page => nil, :key => User.current.rss_key}, :title => l(:label_issue_plural)) %> |
|
60 | <%= auto_discovery_link_tag(:atom, {:query_id => @query, :format => 'atom', :page => nil, :key => User.current.rss_key}, :title => l(:label_issue_plural)) %> | |
61 | <%= auto_discovery_link_tag(:atom, {:action => 'changes', :query_id => @query, :format => 'atom', :page => nil, :key => User.current.rss_key}, :title => l(:label_changes_details)) %> |
|
61 | <%= auto_discovery_link_tag(:atom, {:action => 'changes', :query_id => @query, :format => 'atom', :page => nil, :key => User.current.rss_key}, :title => l(:label_changes_details)) %> | |
62 | <%= javascript_include_tag 'context_menu' %> |
|
62 | <%= javascript_include_tag 'context_menu' %> | |
63 | <%= stylesheet_link_tag 'context_menu' %> |
|
63 | <%= stylesheet_link_tag 'context_menu' %> | |
64 | <% end %> |
|
64 | <% end %> | |
65 |
|
65 | |||
66 | <div id="context-menu" style="display: none;"></div> |
|
66 | <div id="context-menu" style="display: none;"></div> | |
67 | <%= javascript_tag "new ContextMenu('#{url_for(:controller => 'issues', :action => 'context_menu')}')" %> |
|
67 | <%= javascript_tag "new ContextMenu('#{url_for(:controller => 'issues', :action => 'context_menu')}')" %> |
@@ -1,185 +1,211 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 | require 'queries_controller' |
|
19 | require 'queries_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class QueriesController; def rescue_action(e) raise e end; end |
|
22 | class QueriesController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class QueriesControllerTest < Test::Unit::TestCase |
|
24 | class QueriesControllerTest < Test::Unit::TestCase | |
25 | fixtures :projects, :users, :members, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries |
|
25 | fixtures :projects, :users, :members, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = QueriesController.new |
|
28 | @controller = QueriesController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | User.current = nil |
|
31 | User.current = nil | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def test_get_new |
|
34 | def test_get_new_project_query | |
35 | @request.session[:user_id] = 2 |
|
35 | @request.session[:user_id] = 2 | |
36 | get :new, :project_id => 1 |
|
36 | get :new, :project_id => 1 | |
37 | assert_response :success |
|
37 | assert_response :success | |
38 | assert_template 'new' |
|
38 | assert_template 'new' | |
39 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
39 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
40 | :name => 'query[is_public]', |
|
40 | :name => 'query[is_public]', | |
41 | :checked => nil } |
|
41 | :checked => nil } | |
42 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
42 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
43 | :name => 'query_is_for_all', |
|
43 | :name => 'query_is_for_all', | |
44 | :checked => nil, |
|
44 | :checked => nil, | |
45 | :disabled => nil } |
|
45 | :disabled => nil } | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
|
48 | def test_get_new_global_query | |||
|
49 | @request.session[:user_id] = 2 | |||
|
50 | get :new | |||
|
51 | assert_response :success | |||
|
52 | assert_template 'new' | |||
|
53 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', | |||
|
54 | :name => 'query[is_public]' } | |||
|
55 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |||
|
56 | :name => 'query_is_for_all', | |||
|
57 | :checked => 'checked', | |||
|
58 | :disabled => nil } | |||
|
59 | end | |||
|
60 | ||||
48 | def test_new_project_public_query |
|
61 | def test_new_project_public_query | |
49 | @request.session[:user_id] = 2 |
|
62 | @request.session[:user_id] = 2 | |
50 | post :new, |
|
63 | post :new, | |
51 | :project_id => 'ecookbook', |
|
64 | :project_id => 'ecookbook', | |
52 | :confirm => '1', |
|
65 | :confirm => '1', | |
53 | :default_columns => '1', |
|
66 | :default_columns => '1', | |
54 | :fields => ["status_id", "assigned_to_id"], |
|
67 | :fields => ["status_id", "assigned_to_id"], | |
55 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
68 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
56 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
69 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, | |
57 |
:query => {"name" => "test_new_project_public_query", "is_public" => "1"} |
|
70 | :query => {"name" => "test_new_project_public_query", "is_public" => "1"} | |
58 | :column_names => ["", "tracker", "status", "priority", "subject", "updated_on", "category"] |
|
|||
59 |
|
71 | |||
60 | q = Query.find_by_name('test_new_project_public_query') |
|
72 | q = Query.find_by_name('test_new_project_public_query') | |
61 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => q |
|
73 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => q | |
62 | assert q.is_public? |
|
74 | assert q.is_public? | |
63 | assert q.has_default_columns? |
|
75 | assert q.has_default_columns? | |
64 | assert q.valid? |
|
76 | assert q.valid? | |
65 | end |
|
77 | end | |
66 |
|
78 | |||
67 | def test_new_project_private_query |
|
79 | def test_new_project_private_query | |
68 | @request.session[:user_id] = 3 |
|
80 | @request.session[:user_id] = 3 | |
69 | post :new, |
|
81 | post :new, | |
70 | :project_id => 'ecookbook', |
|
82 | :project_id => 'ecookbook', | |
71 | :confirm => '1', |
|
83 | :confirm => '1', | |
72 | :default_columns => '1', |
|
84 | :default_columns => '1', | |
73 | :fields => ["status_id", "assigned_to_id"], |
|
85 | :fields => ["status_id", "assigned_to_id"], | |
74 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
86 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
75 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
87 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, | |
76 |
:query => {"name" => "test_new_project_private_query", "is_public" => "1"} |
|
88 | :query => {"name" => "test_new_project_private_query", "is_public" => "1"} | |
77 | :column_names => ["", "tracker", "status", "priority", "subject", "updated_on", "category"] |
|
|||
78 |
|
89 | |||
79 | q = Query.find_by_name('test_new_project_private_query') |
|
90 | q = Query.find_by_name('test_new_project_private_query') | |
80 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => q |
|
91 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => q | |
81 | assert !q.is_public? |
|
92 | assert !q.is_public? | |
82 | assert q.has_default_columns? |
|
93 | assert q.has_default_columns? | |
83 | assert q.valid? |
|
94 | assert q.valid? | |
84 | end |
|
95 | end | |
85 |
|
96 | |||
|
97 | def test_new_global_private_query_with_custom_columns | |||
|
98 | @request.session[:user_id] = 3 | |||
|
99 | post :new, | |||
|
100 | :confirm => '1', | |||
|
101 | :fields => ["status_id", "assigned_to_id"], | |||
|
102 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |||
|
103 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, | |||
|
104 | :query => {"name" => "test_new_global_private_query", "is_public" => "1", "column_names" => ["", "tracker", "subject", "priority", "category"]} | |||
|
105 | ||||
|
106 | q = Query.find_by_name('test_new_global_private_query') | |||
|
107 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => q | |||
|
108 | assert !q.is_public? | |||
|
109 | assert !q.has_default_columns? | |||
|
110 | assert_equal [:tracker, :subject, :priority, :category], q.columns.collect {|c| c.name} | |||
|
111 | assert q.valid? | |||
|
112 | end | |||
|
113 | ||||
86 | def test_get_edit_global_public_query |
|
114 | def test_get_edit_global_public_query | |
87 | @request.session[:user_id] = 1 |
|
115 | @request.session[:user_id] = 1 | |
88 | get :edit, :id => 4 |
|
116 | get :edit, :id => 4 | |
89 | assert_response :success |
|
117 | assert_response :success | |
90 | assert_template 'edit' |
|
118 | assert_template 'edit' | |
91 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
119 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
92 | :name => 'query[is_public]', |
|
120 | :name => 'query[is_public]', | |
93 | :checked => 'checked' } |
|
121 | :checked => 'checked' } | |
94 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
122 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
95 | :name => 'query_is_for_all', |
|
123 | :name => 'query_is_for_all', | |
96 | :checked => 'checked', |
|
124 | :checked => 'checked', | |
97 | :disabled => 'disabled' } |
|
125 | :disabled => 'disabled' } | |
98 | end |
|
126 | end | |
99 |
|
127 | |||
100 | def test_edit_global_public_query |
|
128 | def test_edit_global_public_query | |
101 | @request.session[:user_id] = 1 |
|
129 | @request.session[:user_id] = 1 | |
102 | post :edit, |
|
130 | post :edit, | |
103 | :id => 4, |
|
131 | :id => 4, | |
104 | :confirm => '1', |
|
132 | :confirm => '1', | |
105 | :default_columns => '1', |
|
133 | :default_columns => '1', | |
106 | :fields => ["status_id", "assigned_to_id"], |
|
134 | :fields => ["status_id", "assigned_to_id"], | |
107 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
135 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
108 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
136 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, | |
109 |
:query => {"name" => "test_edit_global_public_query", "is_public" => "1"} |
|
137 | :query => {"name" => "test_edit_global_public_query", "is_public" => "1"} | |
110 | :column_names => ["", "tracker", "status", "priority", "subject", "updated_on", "category"] |
|
|||
111 |
|
138 | |||
112 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4 |
|
139 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4 | |
113 | q = Query.find_by_name('test_edit_global_public_query') |
|
140 | q = Query.find_by_name('test_edit_global_public_query') | |
114 | assert q.is_public? |
|
141 | assert q.is_public? | |
115 | assert q.has_default_columns? |
|
142 | assert q.has_default_columns? | |
116 | assert q.valid? |
|
143 | assert q.valid? | |
117 | end |
|
144 | end | |
118 |
|
145 | |||
119 | def test_get_edit_global_private_query |
|
146 | def test_get_edit_global_private_query | |
120 | @request.session[:user_id] = 3 |
|
147 | @request.session[:user_id] = 3 | |
121 | get :edit, :id => 3 |
|
148 | get :edit, :id => 3 | |
122 | assert_response :success |
|
149 | assert_response :success | |
123 | assert_template 'edit' |
|
150 | assert_template 'edit' | |
124 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
151 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
125 | :name => 'query[is_public]' } |
|
152 | :name => 'query[is_public]' } | |
126 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
153 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
127 | :name => 'query_is_for_all', |
|
154 | :name => 'query_is_for_all', | |
128 | :checked => 'checked', |
|
155 | :checked => 'checked', | |
129 | :disabled => 'disabled' } |
|
156 | :disabled => 'disabled' } | |
130 | end |
|
157 | end | |
131 |
|
158 | |||
132 | def test_edit_global_private_query |
|
159 | def test_edit_global_private_query | |
133 | @request.session[:user_id] = 3 |
|
160 | @request.session[:user_id] = 3 | |
134 | post :edit, |
|
161 | post :edit, | |
135 | :id => 3, |
|
162 | :id => 3, | |
136 | :confirm => '1', |
|
163 | :confirm => '1', | |
137 | :default_columns => '1', |
|
164 | :default_columns => '1', | |
138 | :fields => ["status_id", "assigned_to_id"], |
|
165 | :fields => ["status_id", "assigned_to_id"], | |
139 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
166 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
140 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, |
|
167 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, | |
141 |
:query => {"name" => "test_edit_global_private_query", "is_public" => "1"} |
|
168 | :query => {"name" => "test_edit_global_private_query", "is_public" => "1"} | |
142 | :column_names => ["", "tracker", "status", "priority", "subject", "updated_on", "category"] |
|
|||
143 |
|
169 | |||
144 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3 |
|
170 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3 | |
145 | q = Query.find_by_name('test_edit_global_private_query') |
|
171 | q = Query.find_by_name('test_edit_global_private_query') | |
146 | assert !q.is_public? |
|
172 | assert !q.is_public? | |
147 | assert q.has_default_columns? |
|
173 | assert q.has_default_columns? | |
148 | assert q.valid? |
|
174 | assert q.valid? | |
149 | end |
|
175 | end | |
150 |
|
176 | |||
151 | def test_get_edit_project_private_query |
|
177 | def test_get_edit_project_private_query | |
152 | @request.session[:user_id] = 3 |
|
178 | @request.session[:user_id] = 3 | |
153 | get :edit, :id => 2 |
|
179 | get :edit, :id => 2 | |
154 | assert_response :success |
|
180 | assert_response :success | |
155 | assert_template 'edit' |
|
181 | assert_template 'edit' | |
156 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
182 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
157 | :name => 'query[is_public]' } |
|
183 | :name => 'query[is_public]' } | |
158 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
184 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
159 | :name => 'query_is_for_all', |
|
185 | :name => 'query_is_for_all', | |
160 | :checked => nil, |
|
186 | :checked => nil, | |
161 | :disabled => nil } |
|
187 | :disabled => nil } | |
162 | end |
|
188 | end | |
163 |
|
189 | |||
164 | def test_get_edit_project_public_query |
|
190 | def test_get_edit_project_public_query | |
165 | @request.session[:user_id] = 2 |
|
191 | @request.session[:user_id] = 2 | |
166 | get :edit, :id => 1 |
|
192 | get :edit, :id => 1 | |
167 | assert_response :success |
|
193 | assert_response :success | |
168 | assert_template 'edit' |
|
194 | assert_template 'edit' | |
169 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
195 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
170 | :name => 'query[is_public]', |
|
196 | :name => 'query[is_public]', | |
171 | :checked => 'checked' |
|
197 | :checked => 'checked' | |
172 | } |
|
198 | } | |
173 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
199 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
174 | :name => 'query_is_for_all', |
|
200 | :name => 'query_is_for_all', | |
175 | :checked => nil, |
|
201 | :checked => nil, | |
176 | :disabled => 'disabled' } |
|
202 | :disabled => 'disabled' } | |
177 | end |
|
203 | end | |
178 |
|
204 | |||
179 | def test_destroy |
|
205 | def test_destroy | |
180 | @request.session[:user_id] = 2 |
|
206 | @request.session[:user_id] = 2 | |
181 | post :destroy, :id => 1 |
|
207 | post :destroy, :id => 1 | |
182 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil |
|
208 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil | |
183 | assert_nil Query.find_by_id(1) |
|
209 | assert_nil Query.find_by_id(1) | |
184 | end |
|
210 | end | |
185 | end |
|
211 | end |
General Comments 0
You need to be logged in to leave comments.
Login now