Project

General

Profile

Patch #28861 » Add-dates-on-context-menu_v3.patch

Mizuki ISHIKAWA, 2020-02-19 08:36

View differences:

app/views/context_menus/issues.html.erb
116 116
      </ul>
117 117
    </li>
118 118
  <% end %>
119
  <% if @issue && (@safe_attributes.include?('start_date') || @safe_attributes.include?('due_date')) %>
120
    <% modal_id = "update-dates-modal-#{Time.current.to_i}" %>
121
    <li><%= context_menu_link [(l(:field_start_date) if @safe_attributes.include?('start_date')), (l(:field_due_date) if @safe_attributes.include?('due_date'))].compact.join(' / '),
122
                              '#', :onclick => "showModal('#{modal_id}', '350px'); return false;" %></li>
123
    <div id="<%= modal_id %>" style="display:none;">
124
      <%= form_tag(issue_path(:id => @issue.id, :back_url => @back), :method => :patch, :id => nil) do %>
125
        <% if @safe_attributes.include?('start_date') %>
126
        <p>
127
          <label for='issue_start_date'><%= l(:field_start_date) %></label>
128
          <%= date_field_tag 'issue[start_date]', '', :value => @issue.start_date, :size => 10, :id => nil %><%= calendar_for('issue_start_date') %>
129
        </p>
130
        <% end %>
119 131

  
132
        <% if @safe_attributes.include?('due_date') %>
133
        <p>
134
          <label for='issue_due_date'><%= l(:field_due_date) %></label>
135
          <%= date_field_tag 'issue[due_date]', '', :value => @issue.due_date, :size => 10, :id => nil %><%= calendar_for('issue_due_date') %>
136
        </p>
137
        <% end %>
138
        <p class="buttons">
139
          <%= button_tag l(:button_submit), :name => nil, :onclick => "hideModal(this);$(this).closest('form').submit();", :data => { :disable_with => false } %>
140
          <%= link_to_function l(:button_cancel), "hideModal(this);" %>
141
        </p>
142
      <% end %>
143
    </div>
144
  <% end %>
120 145
<% if @can[:add_watchers] %>
121 146
  <li class="folder">
122 147
    <a href="#" class="submenu"><%= l(:label_issue_watchers) %></a>
test/functional/context_menus_controller_test.rb
38 38

  
39 39
  def test_context_menu_one_issue
40 40
    @request.session[:user_id] = 2
41
    issue = Issue.find(1)
41 42
    get :issues, :params => {
42
        :ids => [1]
43
        :ids => [issue.id]
43 44
      }
44 45
    assert_response :success
45 46

  
......
57 58
    assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&issue%5Bfixed_version_id%5D=4', :text => 'eCookbook Subproject 1 - 2.0'
58 59
    # Assignees
59 60
    assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&issue%5Bassigned_to_id%5D=3', :text => 'Dave Lopper'
61
    # Start date / Due date
62
    assert_select 'a[href=?]', '#', :text => 'Start date / Due date'
63
    assert_select 'div[id^=update-dates-modal-]' do
64
      assert_select 'form[action=?]', "/issues/#{issue.id}"
65
      assert_select "input[name='issue[start_date]'][value=?]", issue.start_date.to_s
66
      assert_select "input[name='issue[due_date]'][value=?]", issue.due_date.to_s
67
    end
60 68
  end
61 69

  
62 70
  def test_context_menu_one_issue_by_anonymous
......
250 258
    assert_select 'a', :text => 'eCookbook - Shared'
251 259
  end
252 260

  
261
  def test_context_menu_should_not_include_a_date_form_if_date_attributes_are_unsafe
262
    issue = Issue.find(1)
263
    # Change start_date and due_date to unsafe attributes
264
    issue.tracker.core_fields = []
265
    issue.tracker.save
266
    @request.session[:user_id] = 2
267
    get :issues, :params => {
268
        :ids => [issue.id]
269
      }
270
    assert_response :success
271
    assert_select 'a[href=?][onclick=?]', '#', /showModal\('update-dates-modal-/, {:count => 0}
272
  end
273

  
253 274
  def test_context_menu_with_issue_that_is_not_visible_should_fail
254 275
    get :issues, :params => {
255 276
        :ids => [1, 4] # issue 4 is not visible
(7-7/7)