From 43944a652cbd0f047fe53a1e111eef07e5b9ca7b Mon Sep 17 00:00:00 2001 From: Marius BALTEANU Date: Thu, 26 Jul 2018 23:03:10 +0000 Subject: [PATCH] Add "Assign to me" link to issue form --- app/views/issues/_attributes.html.erb | 7 +++++- app/views/issues/_form.html.erb | 20 +++++++++++++++++ config/locales/en.yml | 1 + public/stylesheets/application.css | 4 +++- test/functional/issues_controller_test.rb | 37 +++++++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 2 deletions(-) diff --git a/app/views/issues/_attributes.html.erb b/app/views/issues/_attributes.html.erb index 3a3b5ac..12002c0 100644 --- a/app/views/issues/_attributes.html.erb +++ b/app/views/issues/_attributes.html.erb @@ -15,7 +15,12 @@ <% end %> <% if @issue.safe_attribute? 'assigned_to_id' %> -

<%= 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') %>

+

+ <%= 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') %> + <% if @issue.assignable_users.include?(User.current) %> + <%= l(:label_assign_to_me) %> + <% end %> +

<% end %> <% if @issue.safe_attribute?('category_id') && @issue.project.issue_categories.any? %> diff --git a/app/views/issues/_form.html.erb b/app/views/issues/_form.html.erb index f25cb3b..f60eee5 100644 --- a/app/views/issues/_form.html.erb +++ b/app/views/issues/_form.html.erb @@ -54,5 +54,25 @@ $(document).ready(function(){ $("#issue_tracker_id, #issue_status_id").each(function(){ $(this).val($(this).find("option[selected=selected]").val()); }); + $(".assign-to-me-link").click(function(event){ + event.preventDefault(); + var element = $(event.target); + $('#issue_assigned_to_id').val(element.data('id')); + element.hide(); + }); + $('#issue_assigned_to_id').change(function(event){ + var assign_to_me_link = $(".assign-to-me-link"); + + if (assign_to_me_link.length > 0) { + var user_id = $(event.target).val(); + var current_user_id = assign_to_me_link.data('id'); + + if (user_id == current_user_id) { + assign_to_me_link.hide(); + } else { + assign_to_me_link.show(); + } + } + }); }); <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index d8f0943..f8c34c0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1026,6 +1026,7 @@ en: label_font_monospace: Monospaced font label_font_proportional: Proportional font label_last_notes: Last notes + label_assign_to_me: Assign to me button_login: Login button_submit: Submit diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 6abf778..30f2571 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -120,7 +120,7 @@ div.modal .box p {margin: 0.3em 0;} .clear:after{ content: "."; display: block; height: 0; clear: both; visibility: hidden; } .mobile-show {display: none;} - +.hidden {display: none;} /***** Links *****/ a, a:link, a:visited{ color: #169; text-decoration: none; } a:hover, a:active{ color: #c61a1a; text-decoration: underline;} @@ -478,6 +478,8 @@ div.issue.overdue .due-date .value { color: #c22; } #issue_tree td.checkbox, #relations td.checkbox {display:none;} #relations td.buttons, #issue_tree td.buttons {padding:0;} +#issue-form .assign-to-me-link { padding-left: 5px; } + fieldset.collapsible {border-width: 1px 0 0 0;} fieldset.collapsible>legend { padding-left: 18px; background: url(../images/arrow_down.png) no-repeat 4px 40%; cursor:pointer; } fieldset.collapsible.collapsed>legend { background-image: url(../images/arrow_right.png); } diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 35c5053..e278d8f 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -1717,6 +1717,43 @@ class IssuesControllerTest < Redmine::ControllerTest end end + def test_update_form_should_render_assign_to_me_link_when_issue_can_be_assigned_to_the_current_user + @request.session[:user_id] = 1 + get :show, :params => { + :id => 10 + } + + assert_select 'form#issue-form #attributes' do + assert_select 'a[class=?][data-id=?]', 'assign-to-me-link', '1', 1 + end + end + + def test_update_form_should_not_render_assign_to_me_link_when_issue_cannot_be_assigned_to_the_current_user + @request.session[:user_id] = 1 + get :show, :params => { + :id => 2 + } + + assert_select 'form#issue-form #attributes' do + assert_select 'a[class=?]', 'assign-to-me-link', 0 + end + end + + def test_update_form_should_not_show_assign_to_me_link_when_issue_is_assigned_to_the_current_user + issue = Issue.find(10) + issue.assigned_to_id = 1 + issue.save! + + @request.session[:user_id] = 1 + get :show, :params => { + :id => 10 + } + + assert_select 'form#issue-form #attributes' do + assert_select 'a[class=?]', 'assign-to-me-link hidden', 1 + end + end + def test_show_should_deny_anonymous_access_without_permission Role.anonymous.remove_permission!(:view_issues) get :show, :params => { -- 2.1.4