]> source.dussan.org Git - redmine.git/commitdiff
Fix that Log time and/or Add notes sections from issue form page do not show or hide...
authorMarius Balteanu <marius.balteanu@zitec.com>
Tue, 22 Mar 2022 07:03:19 +0000 (07:03 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Tue, 22 Mar 2022 07:03:19 +0000 (07:03 +0000)
git-svn-id: https://svn.redmine.org/redmine/trunk@21495 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/views/issues/_edit.html.erb
app/views/issues/edit.js.erb
public/javascripts/application.js
test/application_system_test_case.rb
test/system/issues_test.rb

index 954f606f3cf30f10291cab5476fc0aaabc37d526..226b6f9880f6d155887e0134e00d3ba551006760 100644 (file)
@@ -9,8 +9,8 @@
         </div>
         </fieldset>
     <% end %>
-    <% if User.current.allowed_to?(:log_time, @project) %>
-        <fieldset class="tabular"><legend><%= l(:button_log_time) %></legend>
+    <% if User.current.allowed_to?(:log_time, @issue.project) %>
+        <fieldset class="tabular" id="log_time"><legend><%= l(:button_log_time) %></legend>
         <%= labelled_fields_for :time_entry, @time_entry do |time_entry| %>
         <div class="splitcontent">
         <div class="splitcontentleft">
@@ -28,7 +28,7 @@
     </fieldset>
     <% end %>
     <% if @issue.notes_addable? %>
-      <fieldset><legend><%= l(:field_notes) %></legend>
+      <fieldset id="add_notes"><legend><%= l(:field_notes) %></legend>
       <%= f.text_area :notes, :cols => 60, :rows => 10, :class => 'wiki-edit',
             :data => {
                 :auto_complete => true
@@ -43,7 +43,7 @@
       <%= call_hook(:view_issues_edit_notes_bottom, { :issue => @issue, :notes => @notes, :form => f }) %>
       </fieldset>
 
-      <fieldset><legend><%= l(:label_attachment_plural) %></legend>
+      <fieldset id="add_attachments"><legend><%= l(:label_attachment_plural) %></legend>
         <% if @issue.attachments.any? && @issue.safe_attribute?('deleted_attachment_ids') %>
         <div class="contextual"><%= link_to l(:label_edit_attachments), '#', :onclick => "$('#existing-attachments').toggle(); return false;" %></div>
         <div id="existing-attachments" style="<%= @issue.deleted_attachment_ids.blank? ? 'display:none;' : '' %>">
index 8c94aecebdfa5dd0adf3e4c00dec163841f66ea1..ed8fc3ca832a02b8741db4a6e04878b24d2ff8dd 100644 (file)
@@ -1,7 +1 @@
-replaceIssueFormWith('<%= escape_javascript(render :partial => 'form') %>');
-
-<% if User.current.allowed_to?(:log_time, @issue.project) %>
-  $('#log_time').show();
-<% else %>
-  $('#log_time').hide();
-<% end %>
+replaceIssueFormWith('<%= escape_javascript(render :partial => 'edit') %>');
index 91da192290589e7243de65d5019a0888ff78fdbc..efff38da7dcdbf13ec590683eedb511fafbcd743 100644 (file)
@@ -622,8 +622,13 @@ function replaceIssueFormWith(html){
       replacement.find('#'+object_id).val($(this).val());
     }
   });
-  $('#all_attributes').empty();
-  $('#all_attributes').prepend(replacement);
+
+  if ($('form.new_issue').length > 0) {
+    $('#all_attributes').empty();
+    $('#all_attributes').prepend(replacement);
+  } else {
+    $('#issue-form').replaceWith(replacement);
+  }
 }
 
 function updateBulkEditFrom(url) {
index a8b6f55d590a2ae12193a9fec7bb5ed155fca35e..d813f0ce3e6aba0de9115fc4b877d7b8631cd565 100644 (file)
@@ -81,6 +81,12 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
     assert_equal '/my/page', current_path
   end
 
+  def wait_for_ajax
+    Timeout.timeout(Capybara.default_max_wait_time) do
+      loop until page.evaluate_script("jQuery.active").zero?
+    end
+  end
+
   def clear_downloaded_files
     FileUtils.rm downloaded_files
   end
index 4d048608895b7d31dbd639d6e72d8700edb55ef0..935470e1acf7a40339afdcd6275eb71086ec413b 100644 (file)
@@ -587,4 +587,41 @@ class IssuesSystemTest < ApplicationSystemTestCase
       assert page.has_text? 'Related to Bug #7'
     end
   end
+
+  def test_update_issue_form_should_include_time_entry_form_only_for_users_with_permission
+    log_user('jsmith', 'jsmith')
+
+    visit '/issues/2'
+    page.first(:link, 'Edit').click
+
+    # assert log time form exits for user with required permissions on the current project
+    assert page.has_css?('#log_time')
+
+    # Change project to trigger an update on issue form
+    page.find('#issue_project_id').select('» Private child of eCookbook')
+    wait_for_ajax
+
+    # assert log time form does not exist anymore for user without required permissions on the new project
+    assert_not page.has_css?('#log_time')
+  end
+
+  def test_update_issue_form_should_include_add_notes_form_only_for_users_with_permission
+    log_user('jsmith', 'jsmith')
+
+    visit '/issues/2'
+    page.first(:link, 'Edit').click
+
+    # assert add notes form exits for user with required permissions on the current project
+    assert page.has_css?('#add_notes')
+
+    # remove add issue notes permission from Manager role
+    Role.find_by_name('Manager').remove_permission! :add_issue_notes
+
+    # Change project to trigger an update on issue form
+    page.find('#issue_project_id').select('» Private child of eCookbook')
+    wait_for_ajax
+
+    # assert add notes form does not exist anymore for user without required permissions on the new project
+    assert_not page.has_css?('#add_notes')
+  end
 end