Project

General

Profile

Defect #34641 » 34641-v3.patch

Yuichi HARADA, 2021-02-09 02:22

View differences:

app/views/issues/_edit.html.erb
9 9
        </div>
10 10
        </fieldset>
11 11
    <% end %>
12
    <% if User.current.allowed_to?(:log_time, @project) %>
13
        <fieldset class="tabular"><legend><%= l(:button_log_time) %></legend>
12
      <fieldset id="log_time" class="tabular<%= ' hidden' unless User.current.allowed_to?(:log_time, @project) %>"><legend><%= l(:button_log_time) %></legend>
14 13
        <%= labelled_fields_for :time_entry, @time_entry do |time_entry| %>
15 14
        <div class="splitcontent">
16 15
        <div class="splitcontentleft">
......
25 24
          <p><%= custom_field_tag_with_label :time_entry, value %></p>
26 25
        <% end %>
27 26
        <% end %>
28
    </fieldset>
29
    <% end %>
27
      </fieldset>
30 28
    <% if @issue.notes_addable? %>
31 29
      <fieldset><legend><%= l(:field_notes) %></legend>
32 30
      <%= f.text_area :notes, :cols => 60, :rows => 10, :class => 'wiki-edit',
app/views/issues/edit.js.erb
1 1
replaceIssueFormWith('<%= escape_javascript(render :partial => 'form') %>');
2 2

  
3 3
<% if User.current.allowed_to?(:log_time, @issue.project) %>
4
  $('#log_time').show();
4
  $('#log_time').removeClass('hidden');
5 5
<% else %>
6
  $('#log_time').hide();
6
  $('#log_time').addClass('hidden');
7 7
<% end %>
test/functional/issues_controller_test.rb
5551 5551
    @request.session[:user_id] = 2
5552 5552
    Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
5553 5553
    get(:edit, :params => {:id => 1})
5554
    assert_select 'input[name=?]', 'time_entry[hours]'
5554
    assert_select '#log_time:not(.hidden)' do
5555
      assert_select 'input[name=?]', 'time_entry[hours]'
5556
    end
5555 5557
  end
5556 5558

  
5557 5559
  def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
5558 5560
    @request.session[:user_id] = 2
5559 5561
    Role.find_by_name('Manager').remove_permission! :log_time
5560 5562
    get(:edit, :params => {:id => 1})
5561
    assert_select 'input[name=?]', 'time_entry[hours]', 0
5563
    assert_select '#log_time.hidden' do
5564
      assert_select 'input[name=?]', 'time_entry[hours]'
5565
    end
5562 5566
  end
5563 5567

  
5564 5568
  def test_get_edit_with_params
test/system/issues_test.rb
571 571
      assert page.has_text? 'Related to Bug #7'
572 572
    end
573 573
  end
574

  
575
  def test_edit_should_show_log_time_block_dynamically
576
    project = Project.find('ecookbook') # eCookbook
577
    project.enabled_module_names = project.enabled_module_names - ['time_tracking']
578
    project.save!
579
    Member.create!(:project => Project.find('subproject1'), :roles => [Role.find_by_name('Manager')], :principal => User.find_by_login('dlopper'))
580

  
581
    log_user('dlopper', 'foo')
582

  
583
    visit '/issues/1'
584
    page.first(:link, 'Edit').click
585

  
586
    within('#issue-form') do
587
      assert page.has_select?('Project', :with_options => ['eCookbook', 'eCookbook Subproject 1'])
588
      assert page.has_select?('Project', :selected => 'eCookbook')
589
      assert page.has_selector?('#log_time.hidden', :visible => false)
590

  
591
      select 'eCookbook Subproject 1', :from => 'Project'
592
      assert page.has_select?('Project', :selected => '  » eCookbook Subproject 1')
593
      assert page.has_selector?('#log_time', :visible => true)
594
    end
595
  end
596

  
597
  def test_edit_should_hide_log_time_block_dynamically
598
    project = Project.find('subproject1') # eCookbook Subproject 1
599
    project.enabled_module_names = project.enabled_module_names - ['time_tracking']
600
    project.save!
601
    Member.create!(:project => project, :roles => [Role.find_by_name('Manager')], :principal => User.find_by_login('dlopper'))
602

  
603
    log_user('dlopper', 'foo')
604

  
605
    visit '/issues/1'
606
    page.first(:link, 'Edit').click
607

  
608
    within('#issue-form') do
609
      assert page.has_select?('Project', :with_options => ['eCookbook', 'eCookbook Subproject 1'])
610
      assert page.has_select?('Project', :selected => 'eCookbook')
611
      assert page.has_selector?('#log_time', :visible => true)
612

  
613
      select 'eCookbook Subproject 1', :from => 'Project'
614
      assert page.has_select?('Project', :selected => '  » eCookbook Subproject 1')
615
      assert page.has_selector?('#log_time.hidden', :visible => false)
616
    end
617
  end
574 618
end
(3-3/5)