0001-Add-Assign-to-me-link-to-issue-form.patch

Marius BALTEANU, 2018-08-01 08:08

Download (5.5 KB)

View differences:

app/views/issues/_attributes.html.erb
15 15
<% end %>
16 16

  
17 17
<% if @issue.safe_attribute? 'assigned_to_id' %>
18
<p><%= f.select :assigned_to_id, principals_options_for_select(@issue.assignable_users, @issue.assigned_to), :include_blank => true, :required => @issue.required_attribute?('assigned_to_id') %></p>
18
  <p>
19
    <%= f.select :assigned_to_id, principals_options_for_select(@issue.assignable_users, @issue.assigned_to), :include_blank => true, :required => @issue.required_attribute?('assigned_to_id') %>
20
    <% if @issue.assignable_users.include?(User.current) %>
21
      <a class="assign-to-me-link<%= ' hidden' if @issue.assigned_to_id == User.current.id %>" href="#" data-id="<%= User.current.id %>"><%= l(:label_assign_to_me) %></a>
22
    <% end %>
23
  </p>
19 24
<% end %>
20 25

  
21 26
<% if @issue.safe_attribute?('category_id') && @issue.project.issue_categories.any? %>
app/views/issues/_form.html.erb
54 54
  $("#issue_tracker_id, #issue_status_id").each(function(){
55 55
    $(this).val($(this).find("option[selected=selected]").val());
56 56
  });
57
  $(".assign-to-me-link").click(function(event){
58
    event.preventDefault();
59
    var element = $(event.target);
60
    $('#issue_assigned_to_id').val(element.data('id'));
61
    element.hide();
62
  });
63
  $('#issue_assigned_to_id').change(function(event){
64
    var assign_to_me_link = $(".assign-to-me-link");
65

  
66
    if (assign_to_me_link.length > 0) {
67
      var user_id = $(event.target).val();
68
      var current_user_id = assign_to_me_link.data('id');
69

  
70
      if (user_id == current_user_id) {
71
        assign_to_me_link.hide();
72
      } else {
73
        assign_to_me_link.show();
74
      }
75
    }
76
  });
57 77
});
58 78
<% end %>
config/locales/en.yml
1026 1026
  label_font_monospace: Monospaced font
1027 1027
  label_font_proportional: Proportional font
1028 1028
  label_last_notes: Last notes
1029
  label_assign_to_me: Assign to me
1029 1030

  
1030 1031
  button_login: Login
1031 1032
  button_submit: Submit
public/stylesheets/application.css
120 120
.clear:after{ content: "."; display: block; height: 0; clear: both; visibility: hidden; }
121 121

  
122 122
.mobile-show {display: none;}
123

  
123
.hidden {display: none;}
124 124
/***** Links *****/
125 125
a, a:link, a:visited{ color: #169; text-decoration: none; }
126 126
a:hover, a:active{ color: #c61a1a; text-decoration: underline;}
......
478 478
#issue_tree td.checkbox, #relations td.checkbox {display:none;}
479 479
#relations td.buttons, #issue_tree td.buttons {padding:0;}
480 480

  
481
#issue-form .assign-to-me-link { padding-left: 5px; }
482

  
481 483
fieldset.collapsible {border-width: 1px 0 0 0;}
482 484
fieldset.collapsible>legend { padding-left: 18px; background: url(../images/arrow_down.png) no-repeat 4px 40%; cursor:pointer; }
483 485
fieldset.collapsible.collapsed>legend { background-image: url(../images/arrow_right.png); }
test/functional/issues_controller_test.rb
1717 1717
    end
1718 1718
  end
1719 1719

  
1720
  def test_update_form_should_render_assign_to_me_link_when_issue_can_be_assigned_to_the_current_user
1721
    @request.session[:user_id] = 1
1722
    get :show, :params => {
1723
        :id => 10
1724
      }
1725

  
1726
    assert_select 'form#issue-form #attributes' do
1727
      assert_select 'a[class=?][data-id=?]', 'assign-to-me-link', '1', 1
1728
    end
1729
  end
1730

  
1731
  def test_update_form_should_not_render_assign_to_me_link_when_issue_cannot_be_assigned_to_the_current_user
1732
    @request.session[:user_id] = 1
1733
    get :show, :params => {
1734
        :id => 2
1735
      }
1736

  
1737
    assert_select 'form#issue-form #attributes' do
1738
      assert_select 'a[class=?]', 'assign-to-me-link', 0
1739
    end
1740
  end
1741

  
1742
  def test_update_form_should_not_show_assign_to_me_link_when_issue_is_assigned_to_the_current_user
1743
    issue = Issue.find(10)
1744
    issue.assigned_to_id = 1
1745
    issue.save!
1746

  
1747
    @request.session[:user_id] = 1
1748
    get :show, :params => {
1749
        :id => 10
1750
      }
1751

  
1752
    assert_select 'form#issue-form #attributes' do
1753
      assert_select 'a[class=?]', 'assign-to-me-link hidden', 1
1754
    end
1755
  end
1756

  
1720 1757
  def test_show_should_deny_anonymous_access_without_permission
1721 1758
    Role.anonymous.remove_permission!(:view_issues)
1722 1759
    get :show, :params => {
1723
-