Revision 1297:0a574315af3e .svn/pristine/3d

View differences:

.svn/pristine/3d/3d39eaf1a13ab4e59f2f962003d5f13e35d876e3.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2012  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

  
18
class TimelogController < ApplicationController
19
  menu_item :issues
20

  
21
  before_filter :find_project_for_new_time_entry, :only => [:create]
22
  before_filter :find_time_entry, :only => [:show, :edit, :update]
23
  before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy]
24
  before_filter :authorize, :except => [:new, :index, :report]
25

  
26
  before_filter :find_optional_project, :only => [:index, :report]
27
  before_filter :find_optional_project_for_new_time_entry, :only => [:new]
28
  before_filter :authorize_global, :only => [:new, :index, :report]
29

  
30
  accept_rss_auth :index
31
  accept_api_auth :index, :show, :create, :update, :destroy
32

  
33
  helper :sort
34
  include SortHelper
35
  helper :issues
36
  include TimelogHelper
37
  helper :custom_fields
38
  include CustomFieldsHelper
39

  
40
  def index
41
    sort_init 'spent_on', 'desc'
42
    sort_update 'spent_on' => ['spent_on', "#{TimeEntry.table_name}.created_on"],
43
                'user' => 'user_id',
44
                'activity' => 'activity_id',
45
                'project' => "#{Project.table_name}.name",
46
                'issue' => 'issue_id',
47
                'hours' => 'hours'
48

  
49
    retrieve_date_range
50

  
51
    scope = TimeEntry.visible.spent_between(@from, @to)
52
    if @issue
53
      scope = scope.on_issue(@issue)
54
    elsif @project
55
      scope = scope.on_project(@project, Setting.display_subprojects_issues?)
56
    end
57

  
58
    respond_to do |format|
59
      format.html {
60
        # Paginate results
61
        @entry_count = scope.count
62
        @entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
63
        @entries = scope.all(
64
          :include => [:project, :activity, :user, {:issue => :tracker}],
65
          :order => sort_clause,
66
          :limit  =>  @entry_pages.items_per_page,
67
          :offset =>  @entry_pages.current.offset
68
        )
69
        @total_hours = scope.sum(:hours).to_f
70

  
71
        render :layout => !request.xhr?
72
      }
73
      format.api  {
74
        @entry_count = scope.count
75
        @offset, @limit = api_offset_and_limit
76
        @entries = scope.all(
77
          :include => [:project, :activity, :user, {:issue => :tracker}],
78
          :order => sort_clause,
79
          :limit  => @limit,
80
          :offset => @offset
81
        )
82
      }
83
      format.atom {
84
        entries = scope.all(
85
          :include => [:project, :activity, :user, {:issue => :tracker}],
86
          :order => "#{TimeEntry.table_name}.created_on DESC",
87
          :limit => Setting.feeds_limit.to_i
88
        )
89
        render_feed(entries, :title => l(:label_spent_time))
90
      }
91
      format.csv {
92
        # Export all entries
93
        @entries = scope.all(
94
          :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
95
          :order => sort_clause
96
        )
97
        send_data(entries_to_csv(@entries), :type => 'text/csv; header=present', :filename => 'timelog.csv')
98
      }
99
    end
100
  end
101

  
102
  def report
103
    retrieve_date_range
104
    @report = Redmine::Helpers::TimeReport.new(@project, @issue, params[:criteria], params[:columns], @from, @to)
105

  
106
    respond_to do |format|
107
      format.html { render :layout => !request.xhr? }
108
      format.csv  { send_data(report_to_csv(@report), :type => 'text/csv; header=present', :filename => 'timelog.csv') }
109
    end
110
  end
111

  
112
  def show
113
    respond_to do |format|
114
      # TODO: Implement html response
115
      format.html { render :nothing => true, :status => 406 }
116
      format.api
117
    end
118
  end
119

  
120
  def new
121
    @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today)
122
    @time_entry.safe_attributes = params[:time_entry]
123
  end
124

  
125
  def create
126
    @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today)
127
    @time_entry.safe_attributes = params[:time_entry]
128

  
129
    call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
130

  
131
    if @time_entry.save
132
      respond_to do |format|
133
        format.html {
134
          flash[:notice] = l(:notice_successful_create)
135
          if params[:continue]
136
            if params[:project_id]
137
              redirect_to :action => 'new', :project_id => @time_entry.project, :issue_id => @time_entry.issue,
138
                :time_entry => {:issue_id => @time_entry.issue_id, :activity_id => @time_entry.activity_id},
139
                :back_url => params[:back_url]
140
            else
141
              redirect_to :action => 'new',
142
                :time_entry => {:project_id => @time_entry.project_id, :issue_id => @time_entry.issue_id, :activity_id => @time_entry.activity_id},
143
                :back_url => params[:back_url]
144
            end
145
          else
146
            redirect_back_or_default :action => 'index', :project_id => @time_entry.project
147
          end
148
        }
149
        format.api  { render :action => 'show', :status => :created, :location => time_entry_url(@time_entry) }
150
      end
151
    else
152
      respond_to do |format|
153
        format.html { render :action => 'new' }
154
        format.api  { render_validation_errors(@time_entry) }
155
      end
156
    end
157
  end
158

  
159
  def edit
160
    @time_entry.safe_attributes = params[:time_entry]
161
  end
162

  
163
  def update
164
    @time_entry.safe_attributes = params[:time_entry]
165

  
166
    call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
167

  
168
    if @time_entry.save
169
      respond_to do |format|
170
        format.html {
171
          flash[:notice] = l(:notice_successful_update)
172
          redirect_back_or_default :action => 'index', :project_id => @time_entry.project
173
        }
174
        format.api  { render_api_ok }
175
      end
176
    else
177
      respond_to do |format|
178
        format.html { render :action => 'edit' }
179
        format.api  { render_validation_errors(@time_entry) }
180
      end
181
    end
182
  end
183

  
184
  def bulk_edit
185
    @available_activities = TimeEntryActivity.shared.active
186
    @custom_fields = TimeEntry.first.available_custom_fields
187
  end
188

  
189
  def bulk_update
190
    attributes = parse_params_for_bulk_time_entry_attributes(params)
191

  
192
    unsaved_time_entry_ids = []
193
    @time_entries.each do |time_entry|
194
      time_entry.reload
195
      time_entry.safe_attributes = attributes
196
      call_hook(:controller_time_entries_bulk_edit_before_save, { :params => params, :time_entry => time_entry })
197
      unless time_entry.save
198
        # Keep unsaved time_entry ids to display them in flash error
199
        unsaved_time_entry_ids << time_entry.id
200
      end
201
    end
202
    set_flash_from_bulk_time_entry_save(@time_entries, unsaved_time_entry_ids)
203
    redirect_back_or_default({:controller => 'timelog', :action => 'index', :project_id => @projects.first})
204
  end
205

  
206
  def destroy
207
    destroyed = TimeEntry.transaction do
208
      @time_entries.each do |t|
209
        unless t.destroy && t.destroyed?
210
          raise ActiveRecord::Rollback
211
        end
212
      end
213
    end
214

  
215
    respond_to do |format|
216
      format.html {
217
        if destroyed
218
          flash[:notice] = l(:notice_successful_delete)
219
        else
220
          flash[:error] = l(:notice_unable_delete_time_entry)
221
        end
222
        redirect_back_or_default(:action => 'index', :project_id => @projects.first)
223
      }
224
      format.api  {
225
        if destroyed
226
          render_api_ok
227
        else
228
          render_validation_errors(@time_entries)
229
        end
230
      }
231
    end
232
  end
233

  
234
private
235
  def find_time_entry
236
    @time_entry = TimeEntry.find(params[:id])
237
    unless @time_entry.editable_by?(User.current)
238
      render_403
239
      return false
240
    end
241
    @project = @time_entry.project
242
  rescue ActiveRecord::RecordNotFound
243
    render_404
244
  end
245

  
246
  def find_time_entries
247
    @time_entries = TimeEntry.find_all_by_id(params[:id] || params[:ids])
248
    raise ActiveRecord::RecordNotFound if @time_entries.empty?
249
    @projects = @time_entries.collect(&:project).compact.uniq
250
    @project = @projects.first if @projects.size == 1
251
  rescue ActiveRecord::RecordNotFound
252
    render_404
253
  end
254

  
255
  def set_flash_from_bulk_time_entry_save(time_entries, unsaved_time_entry_ids)
256
    if unsaved_time_entry_ids.empty?
257
      flash[:notice] = l(:notice_successful_update) unless time_entries.empty?
258
    else
259
      flash[:error] = l(:notice_failed_to_save_time_entries,
260
                        :count => unsaved_time_entry_ids.size,
261
                        :total => time_entries.size,
262
                        :ids => '#' + unsaved_time_entry_ids.join(', #'))
263
    end
264
  end
265

  
266
  def find_optional_project_for_new_time_entry
267
    if (project_id = (params[:project_id] || params[:time_entry] && params[:time_entry][:project_id])).present?
268
      @project = Project.find(project_id)
269
    end
270
    if (issue_id = (params[:issue_id] || params[:time_entry] && params[:time_entry][:issue_id])).present?
271
      @issue = Issue.find(issue_id)
272
      @project ||= @issue.project
273
    end
274
  rescue ActiveRecord::RecordNotFound
275
    render_404
276
  end
277

  
278
  def find_project_for_new_time_entry
279
    find_optional_project_for_new_time_entry
280
    if @project.nil?
281
      render_404
282
    end
283
  end
284

  
285
  def find_optional_project
286
    if !params[:issue_id].blank?
287
      @issue = Issue.find(params[:issue_id])
288
      @project = @issue.project
289
    elsif !params[:project_id].blank?
290
      @project = Project.find(params[:project_id])
291
    end
292
  end
293

  
294
  # Retrieves the date range based on predefined ranges or specific from/to param dates
295
  def retrieve_date_range
296
    @free_period = false
297
    @from, @to = nil, nil
298

  
299
    if params[:period_type] == '1' || (params[:period_type].nil? && !params[:period].nil?)
300
      case params[:period].to_s
301
      when 'today'
302
        @from = @to = Date.today
303
      when 'yesterday'
304
        @from = @to = Date.today - 1
305
      when 'current_week'
306
        @from = Date.today - (Date.today.cwday - 1)%7
307
        @to = @from + 6
308
      when 'last_week'
309
        @from = Date.today - 7 - (Date.today.cwday - 1)%7
310
        @to = @from + 6
311
      when 'last_2_weeks'
312
        @from = Date.today - 14 - (Date.today.cwday - 1)%7
313
        @to = @from + 13
314
      when '7_days'
315
        @from = Date.today - 7
316
        @to = Date.today
317
      when 'current_month'
318
        @from = Date.civil(Date.today.year, Date.today.month, 1)
319
        @to = (@from >> 1) - 1
320
      when 'last_month'
321
        @from = Date.civil(Date.today.year, Date.today.month, 1) << 1
322
        @to = (@from >> 1) - 1
323
      when '30_days'
324
        @from = Date.today - 30
325
        @to = Date.today
326
      when 'current_year'
327
        @from = Date.civil(Date.today.year, 1, 1)
328
        @to = Date.civil(Date.today.year, 12, 31)
329
      end
330
    elsif params[:period_type] == '2' || (params[:period_type].nil? && (!params[:from].nil? || !params[:to].nil?))
331
      begin; @from = params[:from].to_s.to_date unless params[:from].blank?; rescue; end
332
      begin; @to = params[:to].to_s.to_date unless params[:to].blank?; rescue; end
333
      @free_period = true
334
    else
335
      # default
336
    end
337

  
338
    @from, @to = @to, @from if @from && @to && @from > @to
339
  end
340

  
341
  def parse_params_for_bulk_time_entry_attributes(params)
342
    attributes = (params[:time_entry] || {}).reject {|k,v| v.blank?}
343
    attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
344
    attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
345
    attributes
346
  end
347
end
.svn/pristine/3d/3d5312afd2b7a1501b0ec17ef249ac149a4a5a3f.svn-base
1
# encoding: utf-8
2
#
3
# Redmine - project management software
4
# Copyright (C) 2006-2012  Jean-Philippe Lang
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; either version 2
9
# of the License, or (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19

  
20
require File.expand_path('../../test_helper', __FILE__)
21
require 'attachments_controller'
22

  
23
# Re-raise errors caught by the controller.
24
class AttachmentsController; def rescue_action(e) raise e end; end
25

  
26
class AttachmentsControllerTest < ActionController::TestCase
27
  fixtures :users, :projects, :roles, :members, :member_roles,
28
           :enabled_modules, :issues, :trackers, :attachments,
29
           :versions, :wiki_pages, :wikis, :documents
30

  
31
  def setup
32
    @controller = AttachmentsController.new
33
    @request    = ActionController::TestRequest.new
34
    @response   = ActionController::TestResponse.new
35
    User.current = nil
36
    set_fixtures_attachments_directory
37
  end
38

  
39
  def teardown
40
    set_tmp_attachments_directory
41
  end
42

  
43
  def test_show_diff
44
    ['inline', 'sbs'].each do |dt|
45
      # 060719210727_changeset_utf8.diff
46
      get :show, :id => 14, :type => dt
47
      assert_response :success
48
      assert_template 'diff'
49
      assert_equal 'text/html', @response.content_type
50
      assert_tag 'th',
51
        :attributes => {:class => /filename/},
52
        :content => /issues_controller.rb\t\(révision 1484\)/
53
      assert_tag 'td',
54
        :attributes => {:class => /line-code/},
55
        :content => /Demande créée avec succès/
56
    end
57
    set_tmp_attachments_directory
58
  end
59

  
60
  def test_show_diff_replcace_cannot_convert_content
61
    with_settings :repositories_encodings => 'UTF-8' do
62
      ['inline', 'sbs'].each do |dt|
63
        # 060719210727_changeset_iso8859-1.diff
64
        get :show, :id => 5, :type => dt
65
        assert_response :success
66
        assert_template 'diff'
67
        assert_equal 'text/html', @response.content_type
68
        assert_tag 'th',
69
          :attributes => {:class => "filename"},
70
          :content => /issues_controller.rb\t\(r\?vision 1484\)/
71
        assert_tag 'td',
72
          :attributes => {:class => /line-code/},
73
          :content => /Demande cr\?\?e avec succ\?s/
74
      end
75
    end
76
    set_tmp_attachments_directory
77
  end
78

  
79
  def test_show_diff_latin_1
80
    with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
81
      ['inline', 'sbs'].each do |dt|
82
        # 060719210727_changeset_iso8859-1.diff
83
        get :show, :id => 5, :type => dt
84
        assert_response :success
85
        assert_template 'diff'
86
        assert_equal 'text/html', @response.content_type
87
        assert_tag 'th',
88
          :attributes => {:class => "filename"},
89
          :content => /issues_controller.rb\t\(révision 1484\)/
90
        assert_tag 'td',
91
          :attributes => {:class => /line-code/},
92
          :content => /Demande créée avec succès/
93
      end
94
    end
95
    set_tmp_attachments_directory
96
  end
97

  
98
  def test_save_diff_type
99
    user1 = User.find(1)
100
    user1.pref[:diff_type] = nil
101
    user1.preference.save
102
    user = User.find(1)
103
    assert_nil user.pref[:diff_type]
104

  
105
    @request.session[:user_id] = 1 # admin
106
    get :show, :id => 5
107
    assert_response :success
108
    assert_template 'diff'
109
    user.reload
110
    assert_equal "inline", user.pref[:diff_type]
111
    get :show, :id => 5, :type => 'sbs'
112
    assert_response :success
113
    assert_template 'diff'
114
    user.reload
115
    assert_equal "sbs", user.pref[:diff_type]
116
  end
117

  
118
  def test_diff_show_filename_in_mercurial_export
119
    set_tmp_attachments_directory
120
    a = Attachment.new(:container => Issue.find(1),
121
                       :file => uploaded_test_file("hg-export.diff", "text/plain"),
122
                       :author => User.find(1))
123
    assert a.save
124
    assert_equal 'hg-export.diff', a.filename
125

  
126
    get :show, :id => a.id, :type => 'inline'
127
    assert_response :success
128
    assert_template 'diff'
129
    assert_equal 'text/html', @response.content_type
130
    assert_select 'th.filename', :text => 'test1.txt'
131
  end
132

  
133
  def test_show_text_file
134
    get :show, :id => 4
135
    assert_response :success
136
    assert_template 'file'
137
    assert_equal 'text/html', @response.content_type
138
    set_tmp_attachments_directory
139
  end
140

  
141
  def test_show_text_file_utf_8
142
    set_tmp_attachments_directory
143
    a = Attachment.new(:container => Issue.find(1),
144
                       :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
145
                       :author => User.find(1))
146
    assert a.save
147
    assert_equal 'japanese-utf-8.txt', a.filename
148

  
149
    str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
150
    str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
151

  
152
    get :show, :id => a.id
153
    assert_response :success
154
    assert_template 'file'
155
    assert_equal 'text/html', @response.content_type
156
    assert_tag :tag => 'th',
157
               :content => '1',
158
               :attributes => { :class => 'line-num' },
159
               :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
160
  end
161

  
162
  def test_show_text_file_replcace_cannot_convert_content
163
    set_tmp_attachments_directory
164
    with_settings :repositories_encodings => 'UTF-8' do
165
      a = Attachment.new(:container => Issue.find(1),
166
                         :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
167
                         :author => User.find(1))
168
      assert a.save
169
      assert_equal 'iso8859-1.txt', a.filename
170

  
171
      get :show, :id => a.id
172
      assert_response :success
173
      assert_template 'file'
174
      assert_equal 'text/html', @response.content_type
175
      assert_tag :tag => 'th',
176
                 :content => '7',
177
                 :attributes => { :class => 'line-num' },
178
                 :sibling => { :tag => 'td', :content => /Demande cr\?\?e avec succ\?s/ }
179
    end
180
  end
181

  
182
  def test_show_text_file_latin_1
183
    set_tmp_attachments_directory
184
    with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
185
      a = Attachment.new(:container => Issue.find(1),
186
                         :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
187
                         :author => User.find(1))
188
      assert a.save
189
      assert_equal 'iso8859-1.txt', a.filename
190

  
191
      get :show, :id => a.id
192
      assert_response :success
193
      assert_template 'file'
194
      assert_equal 'text/html', @response.content_type
195
      assert_tag :tag => 'th',
196
                 :content => '7',
197
                 :attributes => { :class => 'line-num' },
198
                 :sibling => { :tag => 'td', :content => /Demande créée avec succès/ }
199
      end
200
  end
201

  
202
  def test_show_text_file_should_send_if_too_big
203
    Setting.file_max_size_displayed = 512
204
    Attachment.find(4).update_attribute :filesize, 754.kilobyte
205

  
206
    get :show, :id => 4
207
    assert_response :success
208
    assert_equal 'application/x-ruby', @response.content_type
209
    set_tmp_attachments_directory
210
  end
211

  
212
  def test_show_other
213
    get :show, :id => 6
214
    assert_response :success
215
    assert_equal 'application/octet-stream', @response.content_type
216
    set_tmp_attachments_directory
217
  end
218

  
219
  def test_show_file_from_private_issue_without_permission
220
    get :show, :id => 15
221
    assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
222
    set_tmp_attachments_directory
223
  end
224

  
225
  def test_show_file_from_private_issue_with_permission
226
    @request.session[:user_id] = 2
227
    get :show, :id => 15
228
    assert_response :success
229
    assert_tag 'h2', :content => /private.diff/
230
    set_tmp_attachments_directory
231
  end
232

  
233
  def test_show_file_without_container_should_be_denied
234
    set_tmp_attachments_directory
235
    attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
236

  
237
    @request.session[:user_id] = 2
238
    get :show, :id => attachment.id
239
    assert_response 403
240
  end
241

  
242
  def test_show_invalid_should_respond_with_404
243
    get :show, :id => 999
244
    assert_response 404
245
  end
246

  
247
  def test_download_text_file
248
    get :download, :id => 4
249
    assert_response :success
250
    assert_equal 'application/x-ruby', @response.content_type
251
    set_tmp_attachments_directory
252
  end
253

  
254
  def test_download_version_file_with_issue_tracking_disabled
255
    Project.find(1).disable_module! :issue_tracking
256
    get :download, :id => 9
257
    assert_response :success
258
  end
259

  
260
  def test_download_should_assign_content_type_if_blank
261
    Attachment.find(4).update_attribute(:content_type, '')
262

  
263
    get :download, :id => 4
264
    assert_response :success
265
    assert_equal 'text/x-ruby', @response.content_type
266
    set_tmp_attachments_directory
267
  end
268

  
269
  def test_download_missing_file
270
    get :download, :id => 2
271
    assert_response 404
272
    set_tmp_attachments_directory
273
  end
274

  
275
  def test_download_should_be_denied_without_permission
276
    get :download, :id => 7
277
    assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
278
    set_tmp_attachments_directory
279
  end
280

  
281
  if convert_installed?
282
    def test_thumbnail
283
      Attachment.clear_thumbnails
284
      @request.session[:user_id] = 2
285

  
286
      get :thumbnail, :id => 16
287
      assert_response :success
288
      assert_equal 'image/png', response.content_type
289
    end
290

  
291
    def test_thumbnail_should_not_exceed_maximum_size
292
      Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 800}
293

  
294
      @request.session[:user_id] = 2
295
      get :thumbnail, :id => 16, :size => 2000
296
    end
297

  
298
    def test_thumbnail_should_round_size
299
      Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 250}
300

  
301
      @request.session[:user_id] = 2
302
      get :thumbnail, :id => 16, :size => 260
303
    end
304

  
305
    def test_thumbnail_should_return_404_for_non_image_attachment
306
      @request.session[:user_id] = 2
307

  
308
      get :thumbnail, :id => 15
309
      assert_response 404
310
    end
311

  
312
    def test_thumbnail_should_return_404_if_thumbnail_generation_failed
313
      Attachment.any_instance.stubs(:thumbnail).returns(nil)
314
      @request.session[:user_id] = 2
315

  
316
      get :thumbnail, :id => 16
317
      assert_response 404
318
    end
319

  
320
    def test_thumbnail_should_be_denied_without_permission
321
      get :thumbnail, :id => 16
322
      assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fthumbnail%2F16'
323
    end
324
  else
325
    puts '(ImageMagick convert not available)'
326
  end
327

  
328
  def test_destroy_issue_attachment
329
    set_tmp_attachments_directory
330
    issue = Issue.find(3)
331
    @request.session[:user_id] = 2
332

  
333
    assert_difference 'issue.attachments.count', -1 do
334
      assert_difference 'Journal.count' do
335
        delete :destroy, :id => 1
336
        assert_redirected_to '/projects/ecookbook'
337
      end
338
    end
339
    assert_nil Attachment.find_by_id(1)
340
    j = Journal.first(:order => 'id DESC')
341
    assert_equal issue, j.journalized
342
    assert_equal 'attachment', j.details.first.property
343
    assert_equal '1', j.details.first.prop_key
344
    assert_equal 'error281.txt', j.details.first.old_value
345
    assert_equal User.find(2), j.user
346
  end
347

  
348
  def test_destroy_wiki_page_attachment
349
    set_tmp_attachments_directory
350
    @request.session[:user_id] = 2
351
    assert_difference 'Attachment.count', -1 do
352
      delete :destroy, :id => 3
353
      assert_response 302
354
    end
355
  end
356

  
357
  def test_destroy_project_attachment
358
    set_tmp_attachments_directory
359
    @request.session[:user_id] = 2
360
    assert_difference 'Attachment.count', -1 do
361
      delete :destroy, :id => 8
362
      assert_response 302
363
    end
364
  end
365

  
366
  def test_destroy_version_attachment
367
    set_tmp_attachments_directory
368
    @request.session[:user_id] = 2
369
    assert_difference 'Attachment.count', -1 do
370
      delete :destroy, :id => 9
371
      assert_response 302
372
    end
373
  end
374

  
375
  def test_destroy_without_permission
376
    set_tmp_attachments_directory
377
    assert_no_difference 'Attachment.count' do
378
      delete :destroy, :id => 3
379
    end
380
    assert_response 302
381
    assert Attachment.find_by_id(3)
382
  end
383
end
.svn/pristine/3d/3d70721df6b551b90581f71def1a31b05dec4f44.svn-base
1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
<meta charset="utf-8" />
5
<title><%=h html_title %></title>
6
<meta name="description" content="<%= Redmine::Info.app_name %>" />
7
<meta name="keywords" content="issue,bug,tracker" />
8
<%= csrf_meta_tag %>
9
<%= favicon %>
10
<%= stylesheet_link_tag 'jquery/jquery-ui-1.8.21', 'application', :media => 'all' %>
11
<%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %>
12
<%= javascript_heads %>
13
<%= heads_for_theme %>
14
<%= call_hook :view_layouts_base_html_head %>
15
<!-- page specific tags -->
16
<%= yield :header_tags -%>
17
</head>
18
<body class="<%=h body_css_classes %>">
19
<div id="wrapper">
20
<div id="wrapper2">
21
<div id="wrapper3">
22
<div id="top-menu">
23
    <div id="account">
24
        <%= render_menu :account_menu -%>
25
    </div>
26
    <%= content_tag('div', "#{l(:label_logged_as)} #{link_to_user(User.current, :format => :username)}".html_safe, :id => 'loggedas') if User.current.logged? %>
27
    <%= render_menu :top_menu if User.current.logged? || !Setting.login_required? -%>
28
</div>
29

  
30
<div id="header">
31
    <% if User.current.logged? || !Setting.login_required? %>
32
    <div id="quick-search">
33
        <%= form_tag({:controller => 'search', :action => 'index', :id => @project}, :method => :get ) do %>
34
        <%= hidden_field_tag(controller.default_search_scope, 1, :id => nil) if controller.default_search_scope %>
35
        <label for='q'>
36
          <%= link_to l(:label_search), {:controller => 'search', :action => 'index', :id => @project}, :accesskey => accesskey(:search) %>:
37
        </label>
38
        <%= text_field_tag 'q', @question, :size => 20, :class => 'small', :accesskey => accesskey(:quick_search) %>
39
        <% end %>
40
        <%= render_project_jump_box %>
41
    </div>
42
    <% end %>
43

  
44
    <h1><%= page_header_title %></h1>
45

  
46
    <% if display_main_menu?(@project) %>
47
    <div id="main-menu">
48
        <%= render_main_menu(@project) %>
49
    </div>
50
    <% end %>
51
</div>
52

  
53
<div id="main" class="<%= sidebar_content? ? '' : 'nosidebar' %>">
54
    <div id="sidebar">
55
        <%= yield :sidebar %>
56
        <%= view_layouts_base_sidebar_hook_response %>
57
    </div>
58

  
59
    <div id="content">
60
        <%= render_flash_messages %>
61
        <%= yield %>
62
        <%= call_hook :view_layouts_base_content %>
63
        <div style="clear:both;"></div>
64
    </div>
65
</div>
66
</div>
67

  
68
<div id="ajax-indicator" style="display:none;"><span><%= l(:label_loading) %></span></div>
69
<div id="ajax-modal" style="display:none;"></div>
70

  
71
<div id="footer">
72
  <div class="bgl"><div class="bgr">
73
    Powered by <%= link_to Redmine::Info.app_name, Redmine::Info.url %> &copy; 2006-2012 Jean-Philippe Lang
74
  </div></div>
75
</div>
76
</div>
77
</div>
78
<%= call_hook :view_layouts_base_body_bottom %>
79
</body>
80
</html>
.svn/pristine/3d/3d708c19507cb5d1ea8104b5420cd367defc0853.svn-base
1
/* Italian initialisation for the jQuery UI date picker plugin. */
2
/* Written by Antonello Pasella (antonello.pasella@gmail.com). */
3
jQuery(function($){
4
	$.datepicker.regional['it'] = {
5
		closeText: 'Chiudi',
6
		prevText: '&#x3c;Prec',
7
		nextText: 'Succ&#x3e;',
8
		currentText: 'Oggi',
9
		monthNames: ['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno',
10
			'Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'],
11
		monthNamesShort: ['Gen','Feb','Mar','Apr','Mag','Giu',
12
			'Lug','Ago','Set','Ott','Nov','Dic'],
13
		dayNames: ['Domenica','Luned&#236','Marted&#236','Mercoled&#236','Gioved&#236','Venerd&#236','Sabato'],
14
		dayNamesShort: ['Dom','Lun','Mar','Mer','Gio','Ven','Sab'],
15
		dayNamesMin: ['Do','Lu','Ma','Me','Gi','Ve','Sa'],
16
		weekHeader: 'Sm',
17
		dateFormat: 'dd/mm/yy',
18
		firstDay: 1,
19
		isRTL: false,
20
		showMonthAfterYear: false,
21
		yearSuffix: ''};
22
	$.datepicker.setDefaults($.datepicker.regional['it']);
23
});

Also available in: Unified diff