Revision 441:cbce1fd3b1b7 app/controllers/.svn/text-base

View differences:

app/controllers/.svn/text-base/activities_controller.rb.svn-base
5 5

  
6 6
  def index
7 7
    @days = Setting.activity_days_default.to_i
8
    
8

  
9 9
    if params[:from]
10 10
      begin; @date_to = params[:from].to_date + 1; rescue; end
11 11
    end
......
14 14
    @date_from = @date_to - @days
15 15
    @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
16 16
    @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
17
    
18
    @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project, 
17

  
18
    @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project,
19 19
                                                             :with_subprojects => @with_subprojects,
20 20
                                                             :author => @author)
21 21
    @activity.scope_select {|t| !params["show_#{t}"].nil?}
22 22
    @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty?
23 23

  
24 24
    events = @activity.events(@date_from, @date_to)
25
    
25

  
26 26
    if events.empty? || stale?(:etag => [@activity.scope, @date_to, @date_from, @with_subprojects, @author, events.first, User.current, current_language])
27 27
      respond_to do |format|
28
        format.html { 
28
        format.html {
29 29
          @events_by_day = events.group_by(&:event_date)
30 30
          render :layout => false if request.xhr?
31 31
        }
......
40 40
        }
41 41
      end
42 42
    end
43
    
43

  
44 44
  rescue ActiveRecord::RecordNotFound
45 45
    render_404
46 46
  end
......
55 55
  rescue ActiveRecord::RecordNotFound
56 56
    render_404
57 57
  end
58

  
59 58
end
app/controllers/.svn/text-base/admin_controller.rb.svn-base
17 17

  
18 18
class AdminController < ApplicationController
19 19
  layout 'admin'
20
  
21 20
  before_filter :require_admin
22

  
23 21
  helper :sort
24 22
  include SortHelper	
25 23

  
......
30 28
  def projects
31 29
    @status = params[:status] ? params[:status].to_i : 1
32 30
    c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status])
33
    
34 31
    unless params[:name].blank?
35 32
      name = "%#{params[:name].strip.downcase}%"
36 33
      c << ["LOWER(identifier) LIKE ? OR LOWER(name) LIKE ?", name, name]
37 34
    end
38
    
39 35
    @projects = Project.find :all, :order => 'lft',
40 36
                                   :conditions => c.conditions
41 37

  
42 38
    render :action => "projects", :layout => false if request.xhr?
43 39
  end
44
  
40

  
45 41
  def plugins
46 42
    @plugins = Redmine::Plugin.all
47 43
  end
48
  
44

  
49 45
  # Loads the default configuration
50 46
  # (roles, trackers, statuses, workflow, enumerations)
51 47
  def default_configuration
......
59 55
    end
60 56
    redirect_to :action => 'index'
61 57
  end
62
  
58

  
63 59
  def test_email
64 60
    raise_delivery_errors = ActionMailer::Base.raise_delivery_errors
65 61
    # Force ActionMailer to raise delivery errors so we can catch it
......
73 69
    ActionMailer::Base.raise_delivery_errors = raise_delivery_errors
74 70
    redirect_to :controller => 'settings', :action => 'edit', :tab => 'notifications'
75 71
  end
76
  
72

  
77 73
  def info
78 74
    @db_adapter_name = ActiveRecord::Base.connection.adapter_name
79 75
    @checklist = [
80
      [:text_default_administrator_account_changed, User.find(:first, :conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?],
76
      [:text_default_administrator_account_changed,
77
          User.find(:first,
78
                    :conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?],
81 79
      [:text_file_repository_writable, File.writable?(Attachment.storage_path)],
82
      [:text_plugin_assets_writable, File.writable?(Engines.public_directory)],
83
      [:text_rmagick_available, Object.const_defined?(:Magick)]
80
      [:text_plugin_assets_writable,   File.writable?(Engines.public_directory)],
81
      [:text_rmagick_available,        Object.const_defined?(:Magick)]
84 82
    ]
85
  end  
83
  end
86 84
end
app/controllers/.svn/text-base/application_controller.rb.svn-base
1
# redMine - project management software
2
# Copyright (C) 2006-2007  Jean-Philippe Lang
1
# Redmine - project management software
2
# Copyright (C) 2006-2011  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.
......
23 23

  
24 24
  layout 'base'
25 25
  exempt_from_layout 'builder', 'rsb'
26
  
26

  
27 27
  # Remove broken cookie after upgrade from 0.8.x (#4292)
28 28
  # See https://rails.lighthouseapp.com/projects/8994/tickets/3360
29 29
  # TODO: remove it when Rails is fixed
30 30
  before_filter :delete_broken_cookies
31 31
  def delete_broken_cookies
32 32
    if cookies['_redmine_session'] && cookies['_redmine_session'] !~ /--/
33
      cookies.delete '_redmine_session'    
33
      cookies.delete '_redmine_session'
34 34
      redirect_to home_path
35 35
      return false
36 36
    end
37 37
  end
38
  
38

  
39 39
  before_filter :user_setup, :check_if_login_required, :set_localization
40 40
  filter_parameter_logging :password
41 41
  protect_from_forgery
42
  
42

  
43 43
  rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token
44
  
44

  
45 45
  include Redmine::Search::Controller
46 46
  include Redmine::MenuManager::MenuController
47 47
  helper Redmine::MenuManager::MenuHelper
48
  
48

  
49 49
  Redmine::Scm::Base.all.each do |scm|
50 50
    require_dependency "repository/#{scm.underscore}"
51 51
  end
......
56 56
    # Find the current user
57 57
    User.current = find_current_user
58 58
  end
59
  
59

  
60 60
  # Returns the current user or nil if no user is logged in
61 61
  # and starts a session if needed
62 62
  def find_current_user
......
94 94
      User.current = User.anonymous
95 95
    end
96 96
  end
97
  
97

  
98 98
  # check if login is globally required to access the application
99 99
  def check_if_login_required
100 100
    # no check needed if user is already logged in
101 101
    return true if User.current.logged?
102 102
    require_login if Setting.login_required?
103
  end 
104
  
103
  end
104

  
105 105
  def set_localization
106 106
    lang = nil
107 107
    if User.current.logged?
......
117 117
    lang ||= Setting.default_language
118 118
    set_language_if_valid(lang)
119 119
  end
120
  
120

  
121 121
  def require_login
122 122
    if !User.current.logged?
123 123
      # Extract only the basic url parameters on non-GET requests
......
146 146
    end
147 147
    true
148 148
  end
149
  
149

  
150 150
  def deny_access
151 151
    User.current.logged? ? render_403 : require_login
152 152
  end
......
197 197
  # Finds and sets @project based on @object.project
198 198
  def find_project_from_association
199 199
    render_404 unless @object.present?
200
    
200

  
201 201
    @project = @object.project
202 202
  rescue ActiveRecord::RecordNotFound
203 203
    render_404
......
221 221
  def find_issues
222 222
    @issues = Issue.find_all_by_id(params[:id] || params[:ids])
223 223
    raise ActiveRecord::RecordNotFound if @issues.empty?
224
    if @issues.detect {|issue| !issue.visible?}
225
      deny_access
226
      return
227
    end
224 228
    @projects = @issues.collect(&:project).compact.uniq
225 229
    @project = @projects.first if @projects.size == 1
226 230
  rescue ActiveRecord::RecordNotFound
227 231
    render_404
228 232
  end
229
  
233

  
230 234
  # Check if project is unique before bulk operations
231 235
  def check_project_uniqueness
232 236
    unless @project
......
235 239
      return false
236 240
    end
237 241
  end
238
  
242

  
239 243
  # make sure that the user is a member of the project (or admin) if project is private
240 244
  # used as a before_filter for actions that do not require any particular permission on the project
241 245
  def check_project_privacy
......
271 275
      end
272 276
    end
273 277
    redirect_to default
278
    false
274 279
  end
275
  
280

  
276 281
  def render_403(options={})
277 282
    @project = nil
278 283
    render_error({:message => :notice_not_authorized, :status => 403}.merge(options))
279 284
    return false
280 285
  end
281
    
286

  
282 287
  def render_404(options={})
283 288
    render_error({:message => :notice_file_not_found, :status => 404}.merge(options))
284 289
    return false
285 290
  end
286
  
291

  
287 292
  # Renders an error response
288 293
  def render_error(arg)
289 294
    arg = {:message => arg} unless arg.is_a?(Hash)
290
    
295

  
291 296
    @message = arg[:message]
292 297
    @message = l(@message) if @message.is_a?(Symbol)
293 298
    @status = arg[:status] || 500
294
    
299

  
295 300
    respond_to do |format|
296 301
      format.html {
297 302
        render :template => 'common/error', :layout => use_layout, :status => @status
......
309 314
  def use_layout
310 315
    request.xhr? ? false : 'base'
311 316
  end
312
  
317

  
313 318
  def invalid_authenticity_token
314 319
    if api_request?
315 320
      logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)."
316 321
    end
317 322
    render_error "Invalid form authenticity token."
318 323
  end
319
  
320
  def render_feed(items, options={})    
324

  
325
  def render_feed(items, options={})
321 326
    @items = items || []
322 327
    @items.sort! {|x,y| y.event_datetime <=> x.event_datetime }
323 328
    @items = @items.slice(0, Setting.feeds_limit.to_i)
324 329
    @title = options[:title] || Setting.app_title
325 330
    render :template => "common/feed.atom.rxml", :layout => false, :content_type => 'application/atom+xml'
326 331
  end
327
  
332

  
328 333
  def self.accept_key_auth(*actions)
329 334
    actions = actions.flatten.map(&:to_s)
330 335
    write_inheritable_attribute('accept_key_auth_actions', actions)
331 336
  end
332
  
337

  
333 338
  def accept_key_auth_actions
334 339
    self.class.read_inheritable_attribute('accept_key_auth_actions') || []
335 340
  end
336
  
341

  
337 342
  # Returns the number of objects that should be displayed
338 343
  # on the paginated list
339 344
  def per_page_option
......
369 374
      offset = 0 if offset < 0
370 375
    end
371 376
    offset ||= 0
372
    
377

  
373 378
    [offset, limit]
374 379
  end
375
  
380

  
376 381
  # qvalues http header parser
377 382
  # code taken from webrick
378 383
  def parse_qvalues(value)
......
393 398
  rescue
394 399
    nil
395 400
  end
396
  
401

  
397 402
  # Returns a string that can be used as filename value in Content-Disposition header
398 403
  def filename_for_content_disposition(name)
399 404
    request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name
400 405
  end
401
  
406

  
402 407
  def api_request?
403 408
    %w(xml json).include? params[:format]
404 409
  end
405
  
410

  
406 411
  # Returns the API key present in the request
407 412
  def api_key_from_request
408 413
    if params[:key].present?
......
459 464
    )
460 465
    render options
461 466
  end
462
  
467

  
463 468
  # Overrides #default_template so that the api template
464 469
  # is used automatically if it exists
465 470
  def default_template(action_name = self.action_name)
......
473 478
    end
474 479
    super
475 480
  end
476
  
481

  
477 482
  # Overrides #pick_layout so that #render with no arguments
478 483
  # doesn't use the layout for api requests
479 484
  def pick_layout(*args)
app/controllers/.svn/text-base/attachments_controller.rb.svn-base
1 1
# Redmine - project management software
2
# Copyright (C) 2006-2008  Jean-Philippe Lang
2
# Copyright (C) 2006-2011  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.
......
19 19
  before_filter :find_project
20 20
  before_filter :file_readable, :read_authorize, :except => :destroy
21 21
  before_filter :delete_authorize, :only => :destroy
22
  
22

  
23 23
  verify :method => :post, :only => :destroy
24
  
24

  
25 25
  def show
26 26
    if @attachment.is_diff?
27 27
      @diff = File.new(@attachment.diskfile, "rb").read
......
33 33
      download
34 34
    end
35 35
  end
36
  
36

  
37 37
  def download
38 38
    if @attachment.container.is_a?(Version) || @attachment.container.is_a?(Project)
39 39
      @attachment.increment_download
40 40
    end
41
    
41

  
42 42
    # images are sent inline
43 43
    send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
44
                                    :type => detect_content_type(@attachment), 
44
                                    :type => detect_content_type(@attachment),
45 45
                                    :disposition => (@attachment.image? ? 'inline' : 'attachment')
46
   
46

  
47 47
  end
48
  
48

  
49 49
  def destroy
50 50
    # Make sure association callbacks are called
51 51
    @attachment.container.attachments.delete(@attachment)
......
53 53
  rescue ::ActionController::RedirectBackError
54 54
    redirect_to :controller => 'projects', :action => 'show', :id => @project
55 55
  end
56
  
56

  
57 57
private
58 58
  def find_project
59 59
    @attachment = Attachment.find(params[:id])
......
63 63
  rescue ActiveRecord::RecordNotFound
64 64
    render_404
65 65
  end
66
  
66

  
67 67
  # Checks that the file exists and is readable
68 68
  def file_readable
69 69
    @attachment.readable? ? true : render_404
70 70
  end
71
  
71

  
72 72
  def read_authorize
73 73
    @attachment.visible? ? true : deny_access
74 74
  end
75
  
75

  
76 76
  def delete_authorize
77 77
    @attachment.deletable? ? true : deny_access
78 78
  end
79
  
79

  
80 80
  def detect_content_type(attachment)
81 81
    content_type = attachment.content_type
82 82
    if content_type.blank?
app/controllers/.svn/text-base/calendars_controller.rb.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
# 
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
# 
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

  
1 18
class CalendarsController < ApplicationController
2 19
  menu_item :calendar
3 20
  before_filter :find_optional_project
......
36 53
    
37 54
    render :action => 'show', :layout => false if request.xhr?
38 55
  end
39
  
40
  def update
41
    show
42
  end
43

  
44 56
end
app/controllers/.svn/text-base/context_menus_controller.rb.svn-base
1 1
class ContextMenusController < ApplicationController
2 2
  helper :watchers
3
  helper :issues
3 4
  
4 5
  def issues
5 6
    @issues = Issue.visible.all(:conditions => {:id => params[:ids]}, :include => :project)
......
40 41
    
41 42
    render :layout => false
42 43
  end
43
  
44

  
45
  def time_entries
46
    @time_entries = TimeEntry.all(
47
       :conditions => {:id => params[:ids]}, :include => :project)
48
    @projects = @time_entries.collect(&:project).compact.uniq
49
    @project = @projects.first if @projects.size == 1
50
    @activities = TimeEntryActivity.shared.active
51
    @can = {:edit   => User.current.allowed_to?(:log_time, @projects),
52
            :update => User.current.allowed_to?(:log_time, @projects),
53
            :delete => User.current.allowed_to?(:log_time, @projects)
54
            }
55
    @back = back_url
56
    render :layout => false
57
  end  
44 58
end
app/controllers/.svn/text-base/custom_fields_controller.rb.svn-base
38 38
      flash[:notice] = l(:notice_successful_create)
39 39
      call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
40 40
      redirect_to :action => 'index', :tab => @custom_field.class.name
41
    else
42
      @trackers = Tracker.find(:all, :order => 'position')
41 43
    end
42
    @trackers = Tracker.find(:all, :order => 'position')
43 44
  end
44 45

  
45 46
  def edit
......
48 49
      flash[:notice] = l(:notice_successful_update)
49 50
      call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
50 51
      redirect_to :action => 'index', :tab => @custom_field.class.name
52
    else
53
      @trackers = Tracker.find(:all, :order => 'position')
51 54
    end
52
    @trackers = Tracker.find(:all, :order => 'position')
53 55
  end
54 56
  
55 57
  def destroy
app/controllers/.svn/text-base/enumerations_controller.rb.svn-base
75 75
      # No associated objects
76 76
      @enumeration.destroy
77 77
      redirect_to :action => 'index'
78
      return
78 79
    elsif params[:reassign_to_id]
79 80
      if reassign_to = @enumeration.class.find_by_id(params[:reassign_to_id])
80 81
        @enumeration.destroy(reassign_to)
81 82
        redirect_to :action => 'index'
83
        return
82 84
      end
83 85
    end
84 86
    @enumerations = @enumeration.class.find(:all) - [@enumeration]
app/controllers/.svn/text-base/files_controller.rb.svn-base
13 13
                'created_on' => "#{Attachment.table_name}.created_on",
14 14
                'size' => "#{Attachment.table_name}.filesize",
15 15
                'downloads' => "#{Attachment.table_name}.downloads"
16
                
16

  
17 17
    @containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)]
18 18
    @containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
19 19
    render :layout => !request.xhr?
app/controllers/.svn/text-base/gantts_controller.rb.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
# 
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
# 
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

  
1 18
class GanttsController < ApplicationController
2 19
  menu_item :gantt
3 20
  before_filter :find_optional_project
......
28 45
      format.pdf  { send_data(@gantt.to_pdf, :type => 'application/pdf', :filename => "#{basename}.pdf") }
29 46
    end
30 47
  end
31

  
32
  def update
33
    show
34
  end
35

  
36 48
end
app/controllers/.svn/text-base/groups_controller.rb.svn-base
132 132
  
133 133
  def autocomplete_for_user
134 134
    @group = Group.find(params[:id])
135
    @users = User.active.like(params[:q]).find(:all, :limit => 100) - @group.users
135
    @users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100)
136 136
    render :layout => false
137 137
  end
138 138
  
app/controllers/.svn/text-base/issue_categories_controller.rb.svn-base
65 65
      # No issue assigned to this category
66 66
      @category.destroy
67 67
      redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories'
68
      return
68 69
    elsif params[:todo]
69 70
      reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id]) if params[:todo] == 'reassign'
70 71
      @category.destroy(reassign_to)
71 72
      redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories'
73
      return
72 74
    end
73 75
    @categories = @project.issue_categories - [@category]
74 76
  end
app/controllers/.svn/text-base/issue_moves_controller.rb.svn-base
2 2
  default_search_scope :issues
3 3
  before_filter :find_issues, :check_project_uniqueness
4 4
  before_filter :authorize
5
  
5

  
6 6
  def new
7 7
    prepare_for_issue_move
8 8
    render :layout => false if request.xhr?
......
48 48
    @copy = params[:copy_options] && params[:copy_options][:copy]
49 49
    @allowed_projects = Issue.allowed_target_projects_on_move
50 50
    @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
51
    @target_project ||= @project    
51
    @target_project ||= @project
52 52
    @trackers = @target_project.trackers
53 53
    @available_statuses = Workflow.available_statuses(@project)
54 54
    @notes = params[:notes]
app/controllers/.svn/text-base/issues_controller.rb.svn-base
1 1
# Redmine - project management software
2
# Copyright (C) 2006-2008  Jean-Philippe Lang
2
# Copyright (C) 2006-2011  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.
......
18 18
class IssuesController < ApplicationController
19 19
  menu_item :new_issue, :only => [:new, :create]
20 20
  default_search_scope :issues
21
  
21

  
22 22
  before_filter :find_issue, :only => [:show, :edit, :update]
23 23
  before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :move, :perform_move, :destroy]
24 24
  before_filter :check_project_uniqueness, :only => [:move, :perform_move]
......
30 30
  accept_key_auth :index, :show, :create, :update, :destroy
31 31

  
32 32
  rescue_from Query::StatementInvalid, :with => :query_statement_invalid
33
  
33

  
34 34
  helper :journals
35 35
  helper :projects
36
  include ProjectsHelper   
36
  include ProjectsHelper
37 37
  helper :custom_fields
38 38
  include CustomFieldsHelper
39 39
  helper :issue_relations
......
60 60
  verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
61 61
  verify :method => :post, :only => :bulk_update, :render => {:nothing => true, :status => :method_not_allowed }
62 62
  verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
63
  
63

  
64 64
  def index
65 65
    retrieve_query
66 66
    sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
67 67
    sort_update(@query.sortable_columns)
68
    
68

  
69 69
    if @query.valid?
70 70
      case params[:format]
71 71
      when 'csv', 'pdf'
......
77 77
      else
78 78
        @limit = per_page_option
79 79
      end
80
      
80

  
81 81
      @issue_count = @query.issue_count
82 82
      @issue_pages = Paginator.new self, @issue_count, @limit, params['page']
83 83
      @offset ||= @issue_pages.current.offset
84 84
      @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
85
                              :order => sort_clause, 
86
                              :offset => @offset, 
85
                              :order => sort_clause,
86
                              :offset => @offset,
87 87
                              :limit => @limit)
88 88
      @issue_count_by_group = @query.issue_count_by_group
89
      
89

  
90 90
      respond_to do |format|
91 91
        format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
92 92
        format.api
......
101 101
  rescue ActiveRecord::RecordNotFound
102 102
    render_404
103 103
  end
104
  
104

  
105 105
  def show
106 106
    @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
107 107
    @journals.each_with_index {|j,i| j.indice = i+1}
108 108
    @journals.reverse! if User.current.wants_comments_in_reverse_order?
109
    @changesets = @issue.changesets.visible.all
110
    @changesets.reverse! if User.current.wants_comments_in_reverse_order?
109

  
110
    if User.current.allowed_to?(:view_changesets, @project)
111
      @changesets = @issue.changesets.visible.all
112
      @changesets.reverse! if User.current.wants_comments_in_reverse_order?
113
    end
114

  
111 115
    @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
112 116
    @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
113 117
    @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
114 118
    @priorities = IssuePriority.all
115
    @time_entry = TimeEntry.new
119
    @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
116 120
    respond_to do |format|
117 121
      format.html { render :template => 'issues/show.rhtml' }
118 122
      format.api
......
152 156
      end
153 157
    end
154 158
  end
155
    
159

  
156 160
  def edit
157 161
    update_issue_from_params
158 162

  
......
214 218
    set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
215 219
    redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
216 220
  end
217
  
221

  
218 222
  def destroy
219 223
    @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
220 224
    if @hours > 0
......
236 240
        return unless api_request?
237 241
      end
238 242
    end
239
    @issues.each(&:destroy)
243
    @issues.each do |issue|
244
      begin
245
        issue.reload.destroy
246
      rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
247
        # nothing to do, issue was already deleted (eg. by a parent)
248
      end
249
    end
240 250
    respond_to do |format|
241 251
      format.html { redirect_back_or_default(:action => 'index', :project_id => @project) }
242 252
      format.api  { head :ok }
......
245 255

  
246 256
private
247 257
  def find_issue
258
    # Issue.visible.find(...) can not be used to redirect user to the login form
259
    # if the issue actually exists but requires authentication
248 260
    @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
261
    unless @issue.visible?
262
      deny_access
263
      return
264
    end
249 265
    @project = @issue.project
250 266
  rescue ActiveRecord::RecordNotFound
251 267
    render_404
252 268
  end
253
  
269

  
254 270
  def find_project
255 271
    project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
256 272
    @project = Project.find(project_id)
257 273
  rescue ActiveRecord::RecordNotFound
258 274
    render_404
259 275
  end
260
  
276

  
261 277
  # Used by #edit and #update to set some common instance variables
262 278
  # from the params
263 279
  # TODO: Refactor, not everything in here is needed by #edit
......
265 281
    @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
266 282
    @priorities = IssuePriority.all
267 283
    @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
268
    @time_entry = TimeEntry.new
284
    @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
269 285
    @time_entry.attributes = params[:time_entry]
270
    
286

  
271 287
    @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil)
272 288
    @issue.init_journal(User.current, @notes)
273 289
    @issue.safe_attributes = params[:issue]
......
283 299
    else
284 300
      @issue = @project.issues.visible.find(params[:id])
285 301
    end
286
    
302

  
287 303
    @issue.project = @project
288 304
    # Tracker must be set before custom field values
289 305
    @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
app/controllers/.svn/text-base/journals_controller.rb.svn-base
24 24
  menu_item :issues
25 25
  
26 26
  helper :issues
27
  helper :custom_fields
27 28
  helper :queries
28 29
  include QueriesHelper
29 30
  helper :sort
app/controllers/.svn/text-base/mail_handler_controller.rb.svn-base
1
# redMine - project management software
2
# Copyright (C) 2006-2008  Jean-Philippe Lang
1
# Redmine - project management software
2
# Copyright (C) 2006-2011  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 MailHandlerController < ActionController::Base
19 19
  before_filter :check_credential
20
  
20

  
21 21
  verify :method => :post,
22 22
         :only => :index,
23 23
         :render => { :nothing => true, :status => 405 }
24
         
24

  
25 25
  # Submits an incoming email to MailHandler
26 26
  def index
27 27
    options = params.dup
......
32 32
      render :nothing => true, :status => :unprocessable_entity
33 33
    end
34 34
  end
35
  
35

  
36 36
  private
37
  
37

  
38 38
  def check_credential
39 39
    User.current = nil
40 40
    unless Setting.mail_handler_api_enabled? && params[:key].to_s == Setting.mail_handler_api_key
app/controllers/.svn/text-base/news_controller.rb.svn-base
1
# redMine - project management software
2
# Copyright (C) 2006  Jean-Philippe Lang
1
# Redmine - project management software
2
# Copyright (C) 2006-2011  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
......
25 25
  before_filter :find_optional_project, :only => :index
26 26
  accept_key_auth :index
27 27
  
28
  helper :watchers
29
  
28 30
  def index
29 31
    case params[:format]
30 32
    when 'xml', 'json'
app/controllers/.svn/text-base/previews_controller.rb.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
# 
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
# 
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

  
1 18
class PreviewsController < ApplicationController
2 19
  before_filter :find_project
3 20

  
app/controllers/.svn/text-base/projects_controller.rb.svn-base
1 1
# Redmine - project management software
2
# Copyright (C) 2006-2009  Jean-Philippe Lang
2
# Copyright (C) 2006-2011  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
......
117 117
      Mailer.with_deliveries(params[:notifications] == '1') do
118 118
        @project = Project.new
119 119
        @project.safe_attributes = params[:project]
120
        @project.enabled_module_names = params[:enabled_modules]
121 120
        if validate_parent_id && @project.copy(@source_project, :only => params[:only])
122 121
          @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
123 122
          flash[:notice] = l(:notice_successful_create)
......
143 142
    end
144 143
    
145 144
    @users_by_role = @project.users_by_role
146
    @subprojects = @project.children.visible
145
    @subprojects = @project.children.visible.all
147 146
    @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
148 147
    @trackers = @project.rolled_up_trackers
149 148
    
......
156 155
                                            :include => [:project, :status, :tracker],
157 156
                                            :conditions => cond)
158 157
    
159
    TimeEntry.visible_by(User.current) do
160
      @total_hours = TimeEntry.sum(:hours, 
161
                                   :include => :project,
162
                                   :conditions => cond).to_f
158
    if User.current.allowed_to?(:view_time_entries, @project)
159
      @total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f
163 160
    end
161
    
164 162
    @key = User.current.rss_key
165 163
    
166 164
    respond_to do |format|
app/controllers/.svn/text-base/queries_controller.rb.svn-base
25 25
    @query.project = params[:query_is_for_all] ? nil : @project
26 26
    @query.user = User.current
27 27
    @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
28
    
29
    @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) if params[:fields] || params[:f]
30
    @query.group_by ||= params[:group_by]
31
    @query.column_names = params[:c] if params[:c]
28 32
    @query.column_names = nil if params[:default_columns]
29 33
    
30
    @query.add_filters(params[:fields], params[:operators], params[:values]) if params[:fields]
31
    @query.group_by ||= params[:group_by]
32
    
33 34
    if request.post? && params[:confirm] && @query.save
34 35
      flash[:notice] = l(:notice_successful_create)
35 36
      redirect_to :controller => 'issues', :action => 'index', :project_id => @project, :query_id => @query
......
41 42
  def edit
42 43
    if request.post?
43 44
      @query.filters = {}
44
      @query.add_filters(params[:fields], params[:operators], params[:values]) if params[:fields]
45
      @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) if params[:fields] || params[:f]
45 46
      @query.attributes = params[:query]
46 47
      @query.project = nil if params[:query_is_for_all]
47 48
      @query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
49
      @query.group_by ||= params[:group_by]
50
      @query.column_names = params[:c] if params[:c]
48 51
      @query.column_names = nil if params[:default_columns]
49 52
      
50 53
      if @query.save
app/controllers/.svn/text-base/repositories_controller.rb.svn-base
1 1
# Redmine - project management software
2
# Copyright (C) 2006-2009  Jean-Philippe Lang
2
# Copyright (C) 2006-2011  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.
......
26 26
  menu_item :repository
27 27
  menu_item :settings, :only => :edit
28 28
  default_search_scope :changesets
29
  
29

  
30 30
  before_filter :find_repository, :except => :edit
31 31
  before_filter :find_project, :only => :edit
32 32
  before_filter :authorize
33 33
  accept_key_auth :revisions
34
  
34

  
35 35
  rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
36
  
36

  
37 37
  def edit
38 38
    @repository = @project.repository
39
    if !@repository
39
    if !@repository && !params[:repository_scm].blank?
40 40
      @repository = Repository.factory(params[:repository_scm])
41 41
      @repository.project = @project if @repository
42 42
    end
43 43
    if request.post? && @repository
44
      @repository.attributes = params[:repository]
44
      p1 = params[:repository]
45
      p       = {}
46
      p_extra = {}
47
      p1.each do |k, v|
48
        if k =~ /^extra_/
49
          p_extra[k] = v
50
        else
51
          p[k] = v
52
        end
53
      end
54
      @repository.attributes = p
55
      @repository.merge_extra_info(p_extra)
45 56
      @repository.save
46 57
    end
47 58
    render(:update) do |page|
48
      page.replace_html "tab-content-repository", :partial => 'projects/settings/repository'
59
      page.replace_html "tab-content-repository",
60
                        :partial => 'projects/settings/repository'
49 61
      if @repository && !@project.repository
50
        @project.reload #needed to reload association
62
        @project.reload # needed to reload association
51 63
        page.replace_html "main-menu", render_main_menu(@project)
52 64
      end
53 65
    end
54 66
  end
55
  
67

  
56 68
  def committers
57 69
    @committers = @repository.committers
58 70
    @users = @project.users
......
70 82

  
71 83
  def destroy
72 84
    @repository.destroy
73
    redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository'
85
    redirect_to :controller => 'projects',
86
                :action     => 'settings',
87
                :id         => @project,
88
                :tab        => 'repository'
74 89
  end
75 90

  
76 91
  def show
77 92
    @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
78 93

  
79 94
    @entries = @repository.entries(@path, @rev)
95
    @changeset = @repository.find_changeset_by_name(@rev)
80 96
    if request.xhr?
81 97
      @entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
82 98
    else
......
122 138

  
123 139
    @content = @repository.cat(@path, @rev)
124 140
    (show_error_not_found; return) unless @content
125
    if 'raw' == params[:format] || @content.is_binary_data? ||
126
         (@entry.size && @entry.size > Setting.file_max_size_displayed.to_i.kilobyte)
141
    if 'raw' == params[:format] ||
142
         (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
143
         ! is_entry_text_data?(@content, @path)
127 144
      # Force the download
128
      send_data @content, :filename => filename_for_content_disposition(@path.split('/').last)
145
      send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) }
146
      send_type = Redmine::MimeType.of(@path)
147
      send_opt[:type] = send_type.to_s if send_type
148
      send_data @content, send_opt
129 149
    else
130 150
      # Prevent empty lines when displaying a file with Windows style eol
151
      # TODO: UTF-16
152
      # Is this needs? AttachmentsController reads file simply.
131 153
      @content.gsub!("\r\n", "\n")
132 154
      @changeset = @repository.find_changeset_by_name(@rev)
133
   end
155
    end
134 156
  end
135 157

  
158
  def is_entry_text_data?(ent, path)
159
    # UTF-16 contains "\x00".
160
    # It is very strict that file contains less than 30% of ascii symbols
161
    # in non Western Europe.
162
    return true if Redmine::MimeType.is_type?('text', path)
163
    # Ruby 1.8.6 has a bug of integer divisions.
164
    # http://apidock.com/ruby/v1_8_6_287/String/is_binary_data%3F
165
    return false if ent.is_binary_data?
166
    true
167
  end
168
  private :is_entry_text_data?
169

  
136 170
  def annotate
137 171
    @entry = @repository.entry(@path, @rev)
138 172
    (show_error_not_found; return) unless @entry
......
167 201
    else
168 202
      @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
169 203
      @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
170
      
204

  
171 205
      # Save diff type as user preference
172 206
      if User.current.logged? && @diff_type != User.current.pref[:diff_type]
173 207
        User.current.pref[:diff_type] = @diff_type
174 208
        User.current.preference.save
175 209
      end
176
      
177
      @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")    
210
      @cache_key = "repositories/diff/#{@repository.id}/" + 
211
                      Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
178 212
      unless read_fragment(@cache_key)
179 213
        @diff = @repository.diff(@path, @rev, @rev_to)
180 214
        show_error_not_found unless @diff
......
204 238
      render_404
205 239
    end
206 240
  end
207
  
241

  
208 242
  private
209 243

  
210 244
  REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i
......
217 251
    @path ||= ''
218 252
    @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].strip
219 253
    @rev_to = params[:rev_to]
220
    
254

  
221 255
    unless @rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE)
222 256
      if @repository.branches.blank?
223 257
        raise InvalidRevisionParam
......
232 266
  def show_error_not_found
233 267
    render_error :message => l(:error_scm_not_found), :status => 404
234 268
  end
235
  
269

  
236 270
  # Handler for Redmine::Scm::Adapters::CommandFailed exception
237 271
  def show_error_command_failed(exception)
238 272
    render_error l(:error_scm_command_failed, exception.message)
239 273
  end
240
  
274

  
241 275
  def graph_commits_per_month(repository)
242 276
    @date_to = Date.today
243 277
    @date_from = @date_to << 11
244 278
    @date_from = Date.civil(@date_from.year, @date_from.month, 1)
245
    commits_by_day = repository.changesets.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
279
    commits_by_day = repository.changesets.count(
280
                          :all, :group => :commit_date,
281
                          :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
246 282
    commits_by_month = [0] * 12
247 283
    commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last }
248 284

  
249
    changes_by_day = repository.changes.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
285
    changes_by_day = repository.changes.count(
286
                          :all, :group => :commit_date,
287
                          :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
250 288
    changes_by_month = [0] * 12
251 289
    changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last }
252
   
290

  
253 291
    fields = []
254 292
    12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)}
255
  
293

  
256 294
    graph = SVG::Graph::Bar.new(
257 295
      :height => 300,
258 296
      :width => 800,
......
264 302
      :graph_title => l(:label_commits_per_month),
265 303
      :show_graph_title => true
266 304
    )
267
    
305

  
268 306
    graph.add_data(
269 307
      :data => commits_by_month[0..11].reverse,
270 308
      :title => l(:label_revision_plural)
......
274 312
      :data => changes_by_month[0..11].reverse,
275 313
      :title => l(:label_change_plural)
276 314
    )
277
    
315

  
278 316
    graph.burn
279 317
  end
280 318

  
......
284 322

  
285 323
    changes_by_author = repository.changes.count(:all, :group => :committer)
286 324
    h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
287
    
325

  
288 326
    fields = commits_by_author.collect {|r| r.first}
289 327
    commits_data = commits_by_author.collect {|r| r.last}
290 328
    changes_data = commits_by_author.collect {|r| h[r.first] || 0}
291
    
329

  
292 330
    fields = fields + [""]*(10 - fields.length) if fields.length<10
293 331
    commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10
294 332
    changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10
295
    
333

  
296 334
    # Remove email adress in usernames
297 335
    fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
298
    
336

  
299 337
    graph = SVG::Graph::BarHorizontal.new(
300 338
      :height => 400,
301 339
      :width => 800,
......
307 345
      :graph_title => l(:label_commits_per_author),
308 346
      :show_graph_title => true
309 347
    )
310
    
311 348
    graph.add_data(
312 349
      :data => commits_data,
313 350
      :title => l(:label_revision_plural)
314 351
    )
315

  
316 352
    graph.add_data(
317 353
      :data => changes_data,
318 354
      :title => l(:label_change_plural)
319 355
    )
320
       
321 356
    graph.burn
322 357
  end
358
end
323 359

  
324
end
325
  
326 360
class Date
327 361
  def months_ago(date = Date.today)
328 362
    (date.year - self.year)*12 + (date.month - self.month)
app/controllers/.svn/text-base/roles_controller.rb.svn-base
38 38
      end
39 39
      flash[:notice] = l(:notice_successful_create)
40 40
      redirect_to :action => 'index'
41
    else
42
      @permissions = @role.setable_permissions
43
      @roles = Role.find :all, :order => 'builtin, position'
41 44
    end
42
    @permissions = @role.setable_permissions
43
    @roles = Role.find :all, :order => 'builtin, position'
44 45
  end
45 46

  
46 47
  def edit
......
48 49
    if request.post? and @role.update_attributes(params[:role])
49 50
      flash[:notice] = l(:notice_successful_update)
50 51
      redirect_to :action => 'index'
52
    else
53
      @permissions = @role.setable_permissions  
51 54
    end
52
    @permissions = @role.setable_permissions
53 55
  end
54 56

  
55 57
  def destroy
app/controllers/.svn/text-base/settings_controller.rb.svn-base
1
# redMine - project management software
2
# Copyright (C) 2006-2007  Jean-Philippe Lang
1
# Redmine - project management software
2
# Copyright (C) 2006-2011  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
......
17 17

  
18 18
class SettingsController < ApplicationController
19 19
  layout 'admin'
20
  
20

  
21 21
  before_filter :require_admin
22 22

  
23 23
  def index
......
36 36
      end
37 37
      flash[:notice] = l(:notice_successful_update)
38 38
      redirect_to :action => 'edit', :tab => params[:tab]
39
      return
39
    else
40
      @options = {}
41
      @options[:user_format] = User::USER_FORMATS.keys.collect {|f| [User.current.name(f), f.to_s] }
42
      @deliveries = ActionMailer::Base.perform_deliveries
43

  
44
      @guessed_host_and_path = request.host_with_port.dup
45
      @guessed_host_and_path << ('/'+ Redmine::Utils.relative_url_root.gsub(%r{^\/}, '')) unless Redmine::Utils.relative_url_root.blank?
46

  
47
      Redmine::Themes.rescan
40 48
    end
41
    @options = {}
42
    @options[:user_format] = User::USER_FORMATS.keys.collect {|f| [User.current.name(f), f.to_s] }
43
    @deliveries = ActionMailer::Base.perform_deliveries
44

  
45
    @guessed_host_and_path = request.host_with_port.dup
46
    @guessed_host_and_path << ('/'+ Redmine::Utils.relative_url_root.gsub(%r{^\/}, '')) unless Redmine::Utils.relative_url_root.blank?
47
    
48
    Redmine::Themes.rescan
49 49
  end
50 50

  
51 51
  def plugin
......
54 54
      Setting["plugin_#{@plugin.id}"] = params[:settings]
55 55
      flash[:notice] = l(:notice_successful_update)
56 56
      redirect_to :action => 'plugin', :id => @plugin.id
57
    else
58
      @partial = @plugin.settings[:partial]
59
      @settings = Setting["plugin_#{@plugin.id}"]
57 60
    end
58
    @partial = @plugin.settings[:partial]
59
    @settings = Setting["plugin_#{@plugin.id}"]
60 61
  rescue Redmine::PluginNotFound
61 62
    render_404
62 63
  end
app/controllers/.svn/text-base/timelog_controller.rb.svn-base
18 18
class TimelogController < ApplicationController
19 19
  menu_item :issues
20 20
  before_filter :find_project, :only => [:new, :create]
21
  before_filter :find_time_entry, :only => [:show, :edit, :update, :destroy]
21
  before_filter :find_time_entry, :only => [:show, :edit, :update]
22
  before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy]
22 23
  before_filter :authorize, :except => [:index]
23 24
  before_filter :find_optional_project, :only => [:index]
24 25
  accept_key_auth :index, :show, :create, :update, :destroy
......
40 41
                'hours' => 'hours'
41 42
    
42 43
    cond = ARCondition.new
43
    if @project.nil?
44
      cond << Project.allowed_to_condition(User.current, :view_time_entries)
45
    elsif @issue.nil?
44
    if @issue
45
      cond << "#{Issue.table_name}.root_id = #{@issue.root_id} AND #{Issue.table_name}.lft >= #{@issue.lft} AND #{Issue.table_name}.rgt <= #{@issue.rgt}"
46
    elsif @project
46 47
      cond << @project.project_condition(Setting.display_subprojects_issues?)
47
    else
48
      cond << "#{Issue.table_name}.root_id = #{@issue.root_id} AND #{Issue.table_name}.lft >= #{@issue.lft} AND #{Issue.table_name}.rgt <= #{@issue.rgt}"
49 48
    end
50 49
    
51 50
    retrieve_date_range
52 51
    cond << ['spent_on BETWEEN ? AND ?', @from, @to]
53 52

  
54
    TimeEntry.visible_by(User.current) do
55
      respond_to do |format|
56
        format.html {
57
          # Paginate results
58
          @entry_count = TimeEntry.count(:include => [:project, :issue], :conditions => cond.conditions)
59
          @entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
60
          @entries = TimeEntry.find(:all, 
61
                                    :include => [:project, :activity, :user, {:issue => :tracker}],
62
                                    :conditions => cond.conditions,
63
                                    :order => sort_clause,
64
                                    :limit  =>  @entry_pages.items_per_page,
65
                                    :offset =>  @entry_pages.current.offset)
66
          @total_hours = TimeEntry.sum(:hours, :include => [:project, :issue], :conditions => cond.conditions).to_f
53
    respond_to do |format|
54
      format.html {
55
        # Paginate results
56
        @entry_count = TimeEntry.visible.count(:include => [:project, :issue], :conditions => cond.conditions)
57
        @entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
58
        @entries = TimeEntry.visible.find(:all, 
59
                                  :include => [:project, :activity, :user, {:issue => :tracker}],
60
                                  :conditions => cond.conditions,
61
                                  :order => sort_clause,
62
                                  :limit  =>  @entry_pages.items_per_page,
63
                                  :offset =>  @entry_pages.current.offset)
64
        @total_hours = TimeEntry.visible.sum(:hours, :include => [:project, :issue], :conditions => cond.conditions).to_f
67 65

  
68
          render :layout => !request.xhr?
69
        }
70
        format.api  {
71
          @entry_count = TimeEntry.count(:include => [:project, :issue], :conditions => cond.conditions)
72
          @entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
73
          @entries = TimeEntry.find(:all, 
74
                                    :include => [:project, :activity, :user, {:issue => :tracker}],
75
                                    :conditions => cond.conditions,
76
                                    :order => sort_clause,
77
                                    :limit  =>  @entry_pages.items_per_page,
78
                                    :offset =>  @entry_pages.current.offset)
79
        }
80
        format.atom {
81
          entries = TimeEntry.find(:all,
82
                                   :include => [:project, :activity, :user, {:issue => :tracker}],
83
                                   :conditions => cond.conditions,
84
                                   :order => "#{TimeEntry.table_name}.created_on DESC",
85
                                   :limit => Setting.feeds_limit.to_i)
86
          render_feed(entries, :title => l(:label_spent_time))
87
        }
88
        format.csv {
89
          # Export all entries
90
          @entries = TimeEntry.find(:all, 
91
                                    :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
92
                                    :conditions => cond.conditions,
93
                                    :order => sort_clause)
94
          send_data(entries_to_csv(@entries), :type => 'text/csv; header=present', :filename => 'timelog.csv')
95
        }
96
      end
66
        render :layout => !request.xhr?
67
      }
68
      format.api  {
69
        @entry_count = TimeEntry.visible.count(:include => [:project, :issue], :conditions => cond.conditions)
70
        @offset, @limit = api_offset_and_limit
71
        @entries = TimeEntry.visible.find(:all, 
72
                                  :include => [:project, :activity, :user, {:issue => :tracker}],
73
                                  :conditions => cond.conditions,
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff