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