0001-Allow-editing-a-time-entry-logged-on-a-locked-user.patch

Marius BALTEANU, 2020-02-09 15:21

Download (3.75 KB)

View differences:

app/helpers/timelog_helper.rb
44 44

  
45 45
  def user_collection_for_select_options(time_entry)
46 46
    collection = time_entry.assignable_users
47
    collection << time_entry.user unless time_entry.user.nil? && !collection.include?(time_entry.user)
47 48
    principals_options_for_select(collection, time_entry.user_id.to_s)
48 49
  end
49 50

  
app/models/time_entry.rb
146 146
      end
147 147
    end
148 148
    errors.add :project_id, :invalid if project.nil?
149
    errors.add :user_id, :invalid if user_id != author_id && !self.assignable_users.map(&:id).include?(user_id)
149
    if user_id_changed? && user_id != author_id && !self.assignable_users.map(&:id).include?(user_id)
150
      errors.add :user_id, :invalid
151
    end
150 152
    errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) || @invalid_issue_id
151 153
    errors.add :activity_id, :inclusion if activity_id_changed? && project && !project.activities.include?(activity)
152 154
    if spent_on_changed? && user
test/functional/timelog_controller_test.rb
186 186
    assert_select 'a[href=?]', '/projects/ecookbook/time_entries', {:text => 'Cancel'}
187 187
  end
188 188

  
189
  def test_get_edit_with_an_existing_time_entry_with_locked_user
190
    user = User.find(3)
191
    entry = TimeEntry.generate!(:user_id => user.id, :comments => "Time entry on a future locked user")
192
    entry.save!
193

  
194
    user.status = User::STATUS_LOCKED
195
    user.save!
196
    Role.find_by_name('Manager').add_permission! :log_time_for_other_users
197
    @request.session[:user_id] = 2
198

  
199
    get :edit, :params => {
200
      :id => entry.id
201
    }
202

  
203
    assert_response :success
204

  
205
    assert_select 'select[name=?]', 'time_entry[user_id]' do
206
      # User with id 3 should be selected even if it's locked
207
      assert_select 'option[value="3"][selected=selected]'
208
    end
209
  end
210

  
189 211
  def test_post_create
190 212
    @request.session[:user_id] = 3
191 213
    assert_difference 'TimeEntry.count' do
......
639 661
    assert_select 'p[id=?]', 'errorExplanation', :text => I18n.t(:error_not_allowed_to_log_time_for_other_users)
640 662
  end
641 663

  
664
  def test_update_should_allow_updating_existing_entry_logged_on_a_locked_user
665
    entry = TimeEntry.generate!(:user_id => 2, :hours => 4, :comments => "Time entry on a future locked user")
666
    Role.find_by_name('Manager').add_permission! :log_time_for_other_users
667
    @request.session[:user_id] = 2
668

  
669
    put :update, :params => {
670
      :id => entry.id,
671
      :time_entry => {
672
        :hours => '6'
673
      }
674
    }
675

  
676
    assert_response :redirect
677

  
678
    entry.reload
679
    # Ensure user didn't change
680
    assert_equal 2, entry.user_id
681
    assert_equal 6.0, entry.hours
682
  end
683

  
642 684
  def test_get_bulk_edit
643 685
    @request.session[:user_id] = 2
644 686

  
645
-