34303.patch

Go MAEDA, 2020-12-07 14:53

Download (4.87 KB)

View differences:

app/controllers/context_menus_controller.rb
36 36
      :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
37 37
      :copy => User.current.allowed_to?(:copy_issues, @projects) && Issue.allowed_target_projects.any?,
38 38
      :add_watchers => User.current.allowed_to?(:add_issue_watchers, @projects),
39
      :delete => @issues.all?(&:deletable?)
39
      :delete => @issues.all?(&:deletable?),
40
      :add_subtask => @issue && !@issue.closed? && User.current.allowed_to?(:manage_subtasks, @project)
40 41
    }
41 42

  
42 43
    @assignables = @issues.map(&:assignable_users).reduce(:&)
app/helpers/issues_helper.rb
235 235

  
236 236
  # Returns a link for adding a new subtask to the given issue
237 237
  def link_to_new_subtask(issue)
238
    link_to(l(:button_add), url_for_new_subtask(issue))
239
  end
240

  
241
  def url_for_new_subtask(issue)
238 242
    attrs = {
239 243
      :parent_issue_id => issue
240 244
    }
241 245
    attrs[:tracker_id] = issue.tracker unless issue.tracker.disabled_core_fields.include?('parent_issue_id')
242
    link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs, :back_url => issue_path(issue)))
246
    params = {:issue => attrs}
247
    params[:back_url] = issue_path(issue) if controller_name == 'issues' && action_name == 'show'
248
    new_project_issue_path(issue.project, params)
243 249
  end
244 250

  
245 251
  def trackers_options_for_select(issue)
app/views/context_menus/issues.html.erb
151 151
  <li><%= context_menu_link l(:button_log_time), new_issue_time_entry_path(@issue),
152 152
          :class => 'icon icon-time-add' %></li>
153 153
  <% end %>
154
  <% if @can[:add_subtask] -%>
155
  <li><%= context_menu_link l(:button_add_subtask), url_for_new_subtask(@issue),
156
          :class => 'icon icon-add' %></li>
157
  <% end %>
154 158
  <li><%= context_menu_link l(:button_copy), project_copy_issue_path(@project, @issue),
155 159
          :class => 'icon icon-copy', :disabled => !@can[:copy] %></li>
156 160
<% else %>
config/locales/en.yml
1160 1160
  button_project_bookmark_delete: Remove bookmark
1161 1161
  button_filter: Filter
1162 1162
  button_actions: Actions
1163
  button_add_subtask: Add subtask
1163 1164

  
1164 1165
  status_active: active
1165 1166
  status_registered: registered
test/functional/context_menus_controller_test.rb
290 290
    assert_select 'a', :text => 'eCookbook - Shared'
291 291
  end
292 292

  
293
  def test_context_menu_should_include_add_subtask_link
294
    @request.session[:user_id] = 2
295
    get(
296
      :issues,
297
      :params => {
298
        :ids => [1]
299
      }
300
    )
301
    assert_response :success
302

  
303
    assert_select 'a.icon-add[href=?]', '/projects/ecookbook/issues/new?issue%5Bparent_issue_id%5D=1&issue%5Btracker_id%5D=1', :text => 'Add subtask'
304
  end
305

  
306
  def test_context_menu_with_closed_issue_should_not_include_add_subtask_link
307
    @request.session[:user_id] = 2
308
    get(
309
      :issues,
310
      :params => {
311
        :ids => [8]
312
      }
313
    )
314
    assert_response :success
315

  
316
    assert_select 'a.icon-add', :text => 'Add subtask', :count => 0
317
  end
318

  
319
  def test_context_menu_multiple_issues_should_not_include_add_subtask_link
320
    @request.session[:user_id] = 2
321
    get(
322
      :issues,
323
      :params => {
324
        :ids => [1, 2]
325
      }
326
    )
327
    assert_response :success
328

  
329
    assert_select 'a.icon-add', :text => 'Add subtask', :count => 0
330
  end
331

  
293 332
  def test_context_menu_with_issue_that_is_not_visible_should_fail
294 333
    get(
295 334
      :issues,
test/helpers/issues_helper_test.rb
360 360
      assert_equal '06/06/2019', issue_due_date_details(issue)
361 361
    end
362 362
  end
363

  
364
  def test_url_for_new_subtask
365
    issue = Issue.find(1)
366
    params = {:issue => {:parent_issue_id => issue.id, :tracker_id => issue.tracker.id}}
367
    assert_equal new_project_issue_path(issue.project, params),
368
                 url_for_new_subtask(issue)
369
  end
363 370
end