From 13c0404d79f5f513c229888147c32a3d898a3e3d Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Tue, 6 Feb 2018 12:11:45 +0800 Subject: [PATCH 01/17] removes uses of `raw` --- app/views/code_review/index.html.erb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/views/code_review/index.html.erb b/app/views/code_review/index.html.erb index c82a9c0..4c0a2e6 100644 --- a/app/views/code_review/index.html.erb +++ b/app/views/code_review/index.html.erb @@ -19,7 +19,7 @@ @@ -80,13 +80,13 @@ function change_option(flag) { codepath = review_path[0, 15] + '...' + review_path[review_path.length - 35, 35] end -%> - <%= link_to(raw(codepath), {:controller => 'code_review', :action => 'show', :id => @project, :review_id => review.id}, :title => review_path) -%> + <%= link_to(codepath, {:controller => 'code_review', :action => 'show', :id => @project, :review_id => review.id}, :title => review_path) -%> - <%=h review.line %> - <%=h review.revision %> - <%=h review.committer %> - <%=h review.user.name %> - <%=h format_time(review.created_at) %> + <%= review.line %> + <%= review.revision %> + <%= review.committer %> + <%= review.user.name %> + <%= format_time(review.created_at) %> <% end %> From 1031d88673888e1aff9e4c3b28db76817c3f45b1 Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Fri, 9 Mar 2018 19:21:08 +0800 Subject: [PATCH 02/17] removes unnecessary html escaping, it's always done automatically by Rails --- .../_change_revision_view.html.erb | 2 +- app/views/code_review/_new_form.html.erb | 16 ++++++------ app/views/code_review/_show.html.erb | 10 +++---- app/views/code_review/_show_error.html.erb | 10 +++---- app/views/code_review/index.html.erb | 10 +++---- .../code_review_settings/_filters.html.erb | 12 ++++----- app/views/code_review_settings/_show.html.erb | 26 +++++++++---------- 7 files changed, 43 insertions(+), 43 deletions(-) diff --git a/app/views/code_review/_change_revision_view.html.erb b/app/views/code_review/_change_revision_view.html.erb index 67eb805..29af964 100644 --- a/app/views/code_review/_change_revision_view.html.erb +++ b/app/views/code_review/_change_revision_view.html.erb @@ -24,7 +24,7 @@ if @changeset %> <%- if User.current.allowed_to?(:assign_code_review, @project) -%>
- <%=h l(:review_assignments)%> + <%= l(:review_assignments)%> <% @changeset.code_review_assignments.each do |assignment| issue = assignment.issue %> <%= link_to("##{issue.id} ", {:controller => 'issues', :action => 'show', :id => issue.id}, diff --git a/app/views/code_review/_new_form.html.erb b/app/views/code_review/_new_form.html.erb index a560d17..23d29a5 100644 --- a/app/views/code_review/_new_form.html.erb +++ b/app/views/code_review/_new_form.html.erb @@ -38,13 +38,13 @@ <%= hidden_field_tag(:repository_id, @repository_id) %> <%= hidden_field_tag(:diff_all, @review.diff_all) %>

- + <%= f.text_field :subject, :size => 70, :required => true %>

<% if @setting.tracker_in_review_dialog %>

- + <%= select :issue, :tracker_id, @project.trackers.collect {|t| [t.name, t.id]}, :required => true %> \ No newline at end of file + diff --git a/app/views/code_review/index.html.erb b/app/views/code_review/index.html.erb index 4c0a2e6..92537b5 100644 --- a/app/views/code_review/index.html.erb +++ b/app/views/code_review/index.html.erb @@ -25,13 +25,13 @@ function change_option(flag) {

- <%=h l(:code_reviews) %> + <%= l(:code_reviews) %>

<% if @all_review_count > 0 %>

<%= form_tag({:controller => 'code_review', :action=>'index', :id => @project}, :id => 'optionform') do %> - <%= check_box_tag 'show_closed', 'true', @show_closed, :onchange => "change_option($('#show_closed').is(':checked'));"%> <%=h l(:label_show_closed_reviews) %> + <%= check_box_tag 'show_closed', 'true', @show_closed, :onchange => "change_option($('#show_closed').is(':checked'));"%> <%= l(:label_show_closed_reviews) %> <% end %> <%# observe_field 'show_closed', :with => 'show_closed', :update => 'content' %>

@@ -50,7 +50,7 @@ function change_option(flag) { <%= sort_header_tag "#{Issue.table_name}.subject", :caption => l(:field_subject)%> <%= sort_header_tag 'path', :caption => l(:label_code_path)%> - <%=h l(:label_code_line)%> + <%= l(:label_code_line)%> <%= sort_header_tag "#{Changeset.table_name}.revision", :caption => l(:label_revision)%> <%= sort_header_tag "#{Changeset.table_name}.committer", :caption => l(:label_code_author)%> @@ -67,10 +67,10 @@ function change_option(flag) { - <%=h review.issue.status %> + <%= review.issue.status %> - <%=h review.issue.subject %> + <%= review.issue.subject %> <% diff --git a/app/views/code_review_settings/_filters.html.erb b/app/views/code_review_settings/_filters.html.erb index a5ebbf0..54d4741 100644 --- a/app/views/code_review_settings/_filters.html.erb +++ b/app/views/code_review_settings/_filters.html.erb @@ -24,8 +24,8 @@

- - <%= check_box_tag 'auto_assign[filter_enabled]', true, @auto_assign.filter_enabled?, :onchange => 'setAutoAssignSettingFiltersEnable();' %><%=h l(:button_activate)%> + + <%= check_box_tag 'auto_assign[filter_enabled]', true, @auto_assign.filter_enabled?, :onchange => 'setAutoAssignSettingFiltersEnable();' %><%= l(:button_activate)%>

@@ -37,9 +37,9 @@ # - <%=h l(:auto_assign_filter_assign)%>/<%=h l(:auto_assign_filter_drop) %> - <%=h l(:auto_assign_filter_expression)%> - <%=h l(:button_sort) %> + <%= l(:auto_assign_filter_assign)%>/<%= l(:auto_assign_filter_drop) %> + <%= l(:auto_assign_filter_expression)%> + <%= l(:button_sort) %> @@ -119,7 +119,7 @@

- + <%= select(:auto_assign, :accept_for_default, [[l(:auto_assign_filter_assign), true], [l(:auto_assign_filter_drop), false]]) %>

diff --git a/app/views/code_review_settings/_show.html.erb b/app/views/code_review_settings/_show.html.erb index 74454d4..c205121 100644 --- a/app/views/code_review_settings/_show.html.erb +++ b/app/views/code_review_settings/_show.html.erb @@ -91,10 +91,10 @@ <%= f.hidden_field :lock_version %>

<%= f.check_box :tracker_in_review_dialog %>

- <%=h l(:select_tracker_for_code_reviews)%>: + <%= l(:select_tracker_for_code_reviews)%>:

<%= f.select :tracker_id, @project.trackers.collect {|t| [t.name, t.id]}, :required => true %>

- <%=h l(:select_tracker_for_code_review_assignment)%>: + <%= l(:select_tracker_for_code_review_assignment)%>:

<%= f.select :assignment_tracker_id, @project.trackers.collect {|t| [t.name, t.id]}, :required => true %>

@@ -102,15 +102,15 @@

- + <%= f.radio_button(:auto_relation, CodeReviewProjectSetting::AUTORELATION_TYPE_RELATES) %> - <%=h l(:label_review_issue_relates) %> + <%= l(:label_review_issue_relates) %> <%= f.radio_button(:auto_relation, CodeReviewProjectSetting::AUTORELATION_TYPE_BLOCKS) %> - <%=h l(:label_review_issue_blocks) %> + <%= l(:label_review_issue_blocks) %> <%= f.radio_button(:auto_relation, CodeReviewProjectSetting::AUTORELATION_TYPE_NONE) %> - <%=h l(:label_review_issue_do_nothing) %> + <%= l(:label_review_issue_do_nothing) %>


@@ -120,29 +120,29 @@ @auto_assign = @code_review_setting.auto_assign_settings @auto_assign.subject = l(:code_review_requrest) if @auto_assign.subject.blank? -%> - - <%= check_box_tag "auto_assign[enabled]", true, @auto_assign.enabled?, :onchange => 'setAutoAssignSettingFormEnable();'%><%=h l(:button_activate)%> + + <%= check_box_tag "auto_assign[enabled]", true, @auto_assign.enabled?, :onchange => 'setAutoAssignSettingFormEnable();'%><%= l(:button_activate)%>

- + <%= select :auto_assign, :author_id, (@project.users.collect {|user| [user.name, user.id] }), :selected => @auto_assign.author_id, :required => true %>

- + <% @project.users.each do |user| %> - + <% end %>

- + <%= text_field(:auto_assign, :subject, :size => 70) %>

- + <%= text_area :auto_assign, :description, :cols => 30, :rows => 12, From e5a5b009b270b8d3bc747ef4a9573df5b7564ed3 Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Fri, 9 Mar 2018 19:29:25 +0800 Subject: [PATCH 03/17] remove unnecessary usage of raw --- app/views/code_review/_change_repository_view.html.erb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/views/code_review/_change_repository_view.html.erb b/app/views/code_review/_change_repository_view.html.erb index 6c7932b..df126df 100644 --- a/app/views/code_review/_change_repository_view.html.erb +++ b/app/views/code_review/_change_repository_view.html.erb @@ -19,11 +19,7 @@ <% if @changesets - changeset_ids = '' - @changesets.each { |changeset| - changeset_ids << changeset.revision - changeset_ids << ',' - } + changeset_ids = safe_join @changesets.map(&:revision), ',' repository_id = @repository.identifier_param if @repository.respond_to?("identifier_param") url = url_for :controller => 'code_review', :action => 'update_revisions_view', :id => project, :repository_id => repository_id @@ -34,8 +30,8 @@ if @changesets -<% end %> \ No newline at end of file +<% end %> From a51fa1523a019db9456ca9a1808ca2acc9d642ef Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Fri, 9 Mar 2018 19:32:57 +0800 Subject: [PATCH 04/17] extract helper method --- app/helpers/code_review_helper.rb | 24 +++++++++++++++++++ .../code_review/_update_revisions.html.erb | 20 ++-------------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/app/helpers/code_review_helper.rb b/app/helpers/code_review_helper.rb index 2086c33..4417f25 100644 --- a/app/helpers/code_review_helper.rb +++ b/app/helpers/code_review_helper.rb @@ -34,4 +34,28 @@ def show_assignments(assignments, project, options = {}) html end + + def progress_for_changeset(changeset) + if changeset.review_count > 0 + progress = '' + progress_bar([changeset.closed_review_pourcent, changeset.completed_review_pourcent], + :width => '60px', + :legend => "#{changeset.closed_review_count}/#{changeset.review_count} #{l(:label_closed_issues)}") + '' + elsif changeset.assignment_count > 0 + if (changeset.open_assignment_count > 0) + progress = '

' + l(:code_review_assigned) + '

' + else + progress = '

' + l(:code_review_reviewed) + '

' + end + + else + progress = '

' + + l(:lable_no_code_reviews) + + ':' + + link_to(l(:label_assign_review), {:controller => 'code_review', + :action => 'assign', :id=>@project, + :rev => changeset.revision, + :changeset_id => changeset.id}) + + '

' if User.current.allowed_to?(:assign_code_review, @project) + end + end end diff --git a/app/views/code_review/_update_revisions.html.erb b/app/views/code_review/_update_revisions.html.erb index cdaba30..910778a 100644 --- a/app/views/code_review/_update_revisions.html.erb +++ b/app/views/code_review/_update_revisions.html.erb @@ -20,26 +20,10 @@ From 29841bf6227f84ec723d8262c9410e38f348bab1 Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Mon, 12 Mar 2018 10:52:15 +0800 Subject: [PATCH 07/17] replaces raw with sanitize - which is totally sufficient in this case --- app/views/code_review/_new_form.html.erb | 2 +- config/locales/en.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/code_review/_new_form.html.erb b/app/views/code_review/_new_form.html.erb index 23d29a5..854b8b7 100644 --- a/app/views/code_review/_new_form.html.erb +++ b/app/views/code_review/_new_form.html.erb @@ -62,7 +62,7 @@ <%= f.text_field :parent_id, :size => 10 %> <% if @parent_candidate %> - <%= raw l(:label_parent_suggestion, {:issue_id => link_to_issue(@parent_candidate)}) %> + <%= sanitize l(:label_parent_suggestion, {:issue_id => link_to_issue(@parent_candidate)}) %> <% end %>

diff --git a/config/locales/en.yml b/config/locales/en.yml index ec82968..3e692e7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -58,7 +58,7 @@ en: auto_assign_filter_assign: Assign auto_assign_filter_drop: Drop - label_parent_suggestion: Maybe "%{issue_id}" ? + label_parent_suggestion: "Maybe %{issue_id} ?" label_assign_review: "Assign" From 7d3178ab1e199685147636099048e5afbf15c045 Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Mon, 12 Mar 2018 10:55:45 +0800 Subject: [PATCH 08/17] adds url argument to popupReview --- app/views/code_review/_update_diff_view.html.erb | 2 +- assets/javascripts/code_review.js | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/app/views/code_review/_update_diff_view.html.erb b/app/views/code_review/_update_diff_view.html.erb index 2e1e8c9..0e9d9af 100644 --- a/app/views/code_review/_update_diff_view.html.erb +++ b/app/views/code_review/_update_diff_view.html.erb @@ -67,7 +67,7 @@ <% end %> <% if @show_review_id -%> - popupReview(<%= @show_review_id.to_i %>); + popupReview(<%= @show_review_id.to_i %>, showReviewUrl); <% end -%> $('#content table.filecontent:first').before($('#code-review-assign-link')); diff --git a/assets/javascripts/code_review.js b/assets/javascripts/code_review.js index f2eef97..b9f6e59 100644 --- a/assets/javascripts/code_review.js +++ b/assets/javascripts/code_review.js @@ -206,16 +206,12 @@ function setShowReviewButton(line, review_id, is_closed, file_count) { }); } -function popupReview(review_id) { +function popupReview(review_id, url) { var span = $('#review_' + review_id); // span element of view review button var pos = span.offset(); $('html,body').animate({ scrollTop: pos.top }, {duration: 'fast', - complete: function(){showReview(showReviewUrl, review_id, pos.left + 10 + 5, pos.top)}}); - // position and show popup dialog - // create popup dialog - //var win = showReview(showReviewUrl, review_id, pos.left + 10 + 5, pos.top); -// win.toFront(); + complete: function(){showReview(url, review_id, pos.left + 10 + 5, pos.top)}}); } function showReview(url, review_id, x, y) { @@ -351,4 +347,4 @@ $.fn.serialize2json = function() } }); return o; -}; \ No newline at end of file +}; From e81074a40c19c0f1097b1a14cc3389f7ad7dc135 Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Mon, 12 Mar 2018 11:28:54 +0800 Subject: [PATCH 09/17] use j helper instead of manual gsub --- .../code_review/_change_revision_view.html.erb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/app/views/code_review/_change_revision_view.html.erb b/app/views/code_review/_change_revision_view.html.erb index 29af964..97a5f7f 100644 --- a/app/views/code_review/_change_revision_view.html.erb +++ b/app/views/code_review/_change_revision_view.html.erb @@ -40,7 +40,7 @@ if @changeset \ No newline at end of file + diff --git a/app/views/code_review/_change_entry_norevision_view.html.erb b/app/views/code_review/_change_entry_norevision_view.html.erb index 096a1a4..97b1d92 100644 --- a/app/views/code_review/_change_entry_norevision_view.html.erb +++ b/app/views/code_review/_change_entry_norevision_view.html.erb @@ -17,11 +17,10 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -%> <% -parameters = request.parameters -path = parameters['path'] -rev = parameters['rev'] +path = params[:path] +rev = params[:rev] repository_id = @repository.identifier_param if @repository.respond_to?("identifier_param") -unless path.blank? or path.empty? +unless path.blank? changesets = @repository.latest_changesets(path, rev, Setting.repository_log_display_limit.to_i) change = changesets[0] @@ -36,4 +35,4 @@ unless path.blank? or path.empty? <% end %> -<% end %> \ No newline at end of file +<% end %> From 157aed8b336d2b57f061010385a5fb2745c93a94 Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Mon, 12 Mar 2018 12:34:08 +0800 Subject: [PATCH 12/17] javascript escaping, parameters / params fix --- app/views/code_review/_body_bottom.html.erb | 21 +++++++++---------- .../_change_attachement_view.html.erb | 14 +++++++------ .../code_review/_update_diff_view.html.erb | 2 +- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/app/views/code_review/_body_bottom.html.erb b/app/views/code_review/_body_bottom.html.erb index 368c780..7b0bb3b 100644 --- a/app/views/code_review/_body_bottom.html.erb +++ b/app/views/code_review/_body_bottom.html.erb @@ -47,11 +47,10 @@ if project and controller and project.module_enabled?(:code_review) <% unless changeset %> <%= render :partial => 'code_review/change_entry_norevision_view', :locals => context %> <% else - parameters = request.parameters - rev_to = parameters['rev_to'] unless parameters['rev_to'].blank? - review_id = parameters['review_id'] - rev = parameters['rev'] - path = parameters['path'].blank? ? '.' : parameters['path'] + rev_to = params['rev_to'] unless params['rev_to'].blank? + review_id = params['review_id'] + rev = params['rev'] + path = params['path'].blank? ? '.' : params['path'] repository_id = @repository.identifier_param if @repository.respond_to?("identifier_param") @@ -61,12 +60,12 @@ if project and controller and project.module_enabled?(:code_review)
<% end %> diff --git a/app/views/code_review/_change_attachement_view.html.erb b/app/views/code_review/_change_attachement_view.html.erb index 6abaa4c..3abe30b 100644 --- a/app/views/code_review/_change_attachement_view.html.erb +++ b/app/views/code_review/_change_attachement_view.html.erb @@ -17,18 +17,20 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -%> <% -id = params[:id].to_i -attachment = Attachment.find(id) -return '' unless attachment.is_text? or attachment.is_diff? -review_id = parameters[:review_id] unless parameters[:review_id].blank? +attachment = Attachment.find(params[:id]) url = url_for :controller => 'code_review', :action => 'update_attachment_view', :id => project --%> +%> + +<% if attachment.is_text? or attachment.is_diff? %> +
+ +<% end %> diff --git a/app/views/code_review/_update_diff_view.html.erb b/app/views/code_review/_update_diff_view.html.erb index 0e9d9af..6a4d8a8 100644 --- a/app/views/code_review/_update_diff_view.html.erb +++ b/app/views/code_review/_update_diff_view.html.erb @@ -56,7 +56,7 @@ var rev_to = '<%= j @rev_to %>'; var path = '<%= j @path -%>'; - setAddReviewButton(addReviewUrl, '<%= change_id %>', '<%= j image_tag('edit.png', :alt => l(:label_add_review), :title => l(:label_add_review)) %>', is_readonly, is_diff, '<%= j @attachment_id %>' ); + setAddReviewButton(addReviewUrl, '<%= change_id %>', '<%= j image_tag('edit.png', :alt => l(:label_add_review), :title => l(:label_add_review)) %>', is_readonly, is_diff, '<%= attachment_id %>' ); var showReviewUrl = '<%= j url_for :controller => 'code_review', :action => 'show', :id=>@project %>'; var showReviewImageTag = '<%= j image_tag('review.png', :plugin => 'redmine_code_review', :alt => l(:label_show_review), :title => l(:label_show_review)) %>'; From 0459edfedb9c666cda1a4b1bdd488c68a439e761 Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Mon, 12 Mar 2018 13:05:17 +0800 Subject: [PATCH 13/17] extract partial for diff view changing --- app/views/code_review/_body_bottom.html.erb | 33 +++---------------- .../code_review/_change_diff_view.html.erb | 20 +++++++++++ 2 files changed, 25 insertions(+), 28 deletions(-) create mode 100644 app/views/code_review/_change_diff_view.html.erb diff --git a/app/views/code_review/_body_bottom.html.erb b/app/views/code_review/_body_bottom.html.erb index 7b0bb3b..f99a453 100644 --- a/app/views/code_review/_body_bottom.html.erb +++ b/app/views/code_review/_body_bottom.html.erb @@ -39,36 +39,13 @@ if project and controller and project.module_enabled?(:code_review) <% elsif (action_name == 'revision') %> <%= render :partial => 'code_review/change_revision_view', :locals => context %> <% elsif (action_name == 'diff' or action_name == 'entry' or action_name == 'annotate')%> - <%if (controller.params[:rev].blank? or controller.params[:rev] == 'master')%> + <%if (params[:rev].blank? or params[:rev] == 'master')%> <%= render :partial => 'code_review/change_entry_norevision_view', :locals => context %> - <% else - changeset = @repository.find_changeset_by_name(controller.params[:rev]) - %> - <% unless changeset %> - <%= render :partial => 'code_review/change_entry_norevision_view', :locals => context %> - <% else - rev_to = params['rev_to'] unless params['rev_to'].blank? - review_id = params['review_id'] - rev = params['rev'] - path = params['path'].blank? ? '.' : params['path'] + <% elsif @repository.find_changeset_by_name(params[:rev]) %> + <%= render partial: 'code_review/change_diff_view', locals: context %> - - repository_id = @repository.identifier_param if @repository.respond_to?("identifier_param") - url = url_for :controller => 'code_review', :action => 'update_diff_view', :id => project, :repository_id => repository_id - %> -
-
- - <% end %> + <% else %> + <%= render :partial => 'code_review/change_entry_norevision_view', :locals => context %> <% end %> <% end %> diff --git a/app/views/code_review/_change_diff_view.html.erb b/app/views/code_review/_change_diff_view.html.erb new file mode 100644 index 0000000..ef5fa07 --- /dev/null +++ b/app/views/code_review/_change_diff_view.html.erb @@ -0,0 +1,20 @@ +<% + rev_to = params['rev_to'] + review_id = params['review_id'] + rev = params['rev'] + path = params['path'].blank? ? '.' : Array(params['path']).join('/') + + url = url_for controller: 'code_review', action: 'update_diff_view', id: project, repository_id: @repository.identifier_param +%> +
+ +<%= javascript_tag do %> + $(document).ready(function(){ + $('#code_review').load('<%= j url %>', { + rev: '<%= j rev %>', + path:'<%= j path %>', + review_id: '<%= j review_id %>', + action_type:'<%= j action_name %>', + rev_to: '<%= j rev_to %>'}); + }); +<% end %> From 216a176d35db459c4a3ddabd72906aff9f0d8492 Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Mon, 12 Mar 2018 13:43:10 +0800 Subject: [PATCH 14/17] moves the big body_bottom conditional to ruby code. --- app/models/code_review_project_setting.rb | 7 ++- app/views/code_review/_body_bottom.html.erb | 58 ------------------- .../code_review/_change_diff_view.html.erb | 7 +++ lib/code_review_application_hooks.rb | 43 +++++++++++++- 4 files changed, 54 insertions(+), 61 deletions(-) delete mode 100644 app/views/code_review/_body_bottom.html.erb diff --git a/app/models/code_review_project_setting.rb b/app/models/code_review_project_setting.rb index f1a8d28..703b533 100644 --- a/app/models/code_review_project_setting.rb +++ b/app/models/code_review_project_setting.rb @@ -35,9 +35,12 @@ class CodeReviewProjectSetting < ActiveRecord::Base AUTORELATION_TYPE_RELATES = 1 AUTORELATION_TYPE_BLOCKS = 2 + def self.find_for(project) + where(project_id: project.id).first + end + def self.find_or_create(project) - setting = CodeReviewProjectSetting.find_by_project_id(project.id) - unless setting + unless setting = find_for(project) setting = CodeReviewProjectSetting.new setting.project_id = project.id return setting if project.trackers.length == 0 diff --git a/app/views/code_review/_body_bottom.html.erb b/app/views/code_review/_body_bottom.html.erb deleted file mode 100644 index f99a453..0000000 --- a/app/views/code_review/_body_bottom.html.erb +++ /dev/null @@ -1,58 +0,0 @@ -<% -# Code Review plugin for Redmine -# Copyright (C) 2010-2014 Haruyuki Iida -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. --%> - -<% -is_target = false - -if project and controller and project.module_enabled?(:code_review) - is_target = true - is_target = false unless User.current.allowed_to?({:controller => 'code_review', :action => 'update_diff_view'}, project) - setting = CodeReviewProjectSetting.where(:project_id => project.id) .first - is_target = false unless setting - is_target = false if(setting && setting.tracker_id == nil) - action_name = controller.action_name - is_target = false unless action_name - is_target = false unless (controller.class.name == 'RepositoriesController' or controller.class.name == 'AttachmentsController') - if (is_target == true) - context = {project: project} - %> - <% if (controller.class.name == 'AttachmentsController' && action_name == "show") %> - <%= render :partial => 'code_review/change_attachement_view', :locals => context %> - <% elsif (action_name == 'show' or action_name == 'revisions') %> - <%= render :partial => 'code_review/change_repository_view', :locals => context %> - <% elsif (action_name == 'revision') %> - <%= render :partial => 'code_review/change_revision_view', :locals => context %> - <% elsif (action_name == 'diff' or action_name == 'entry' or action_name == 'annotate')%> - <%if (params[:rev].blank? or params[:rev] == 'master')%> - <%= render :partial => 'code_review/change_entry_norevision_view', :locals => context %> - <% elsif @repository.find_changeset_by_name(params[:rev]) %> - <%= render partial: 'code_review/change_diff_view', locals: context %> - - <% else %> - <%= render :partial => 'code_review/change_entry_norevision_view', :locals => context %> - - <% end %> - <% end %> - <% - end -end --%> - - - diff --git a/app/views/code_review/_change_diff_view.html.erb b/app/views/code_review/_change_diff_view.html.erb index ef5fa07..9af9809 100644 --- a/app/views/code_review/_change_diff_view.html.erb +++ b/app/views/code_review/_change_diff_view.html.erb @@ -1,3 +1,5 @@ +<% if @repository.find_changeset_by_name(params[:rev]) %> + <% rev_to = params['rev_to'] review_id = params['review_id'] @@ -6,6 +8,7 @@ url = url_for controller: 'code_review', action: 'update_diff_view', id: project, repository_id: @repository.identifier_param %> +
<%= javascript_tag do %> @@ -18,3 +21,7 @@ rev_to: '<%= j rev_to %>'}); }); <% end %> + +<% else %> + <%= render partial: 'code_review/change_entry_norevision_view', locals: { project: project } %> +<% end %> diff --git a/lib/code_review_application_hooks.rb b/lib/code_review_application_hooks.rb index 5e7b0a4..c3a6316 100644 --- a/lib/code_review_application_hooks.rb +++ b/lib/code_review_application_hooks.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Code Review plugin for Redmine # Copyright (C) 2009-2010 Haruyuki Iida #rev @@ -15,8 +17,47 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require 'redmine/utils' class CodeReviewApplicationHooks < Redmine::Hook::ViewListener render_on :view_layouts_base_html_head, :partial => 'code_review/html_header' render_on :view_layouts_base_body_bottom, :partial => 'code_review/body_bottom' + + def view_layouts_base_body_bottom(context) + if project = context[:project] and + controller = context[:controller] and + (controller.is_a?(RepositoriesController) or + controller.is_a?(AttachmentsController)) and + project.module_enabled?(:code_review) and + User.current.allowed_to?(:view_code_review, project) and + setting = CodeReviewProjectSetting.find_for(project) and + setting.tracker.present? + + params = context[:request].parameters + + partial = case controller + when AttachmentsController + if params[:action] == "show" + 'code_review/change_attachement_view' + end + when RepositoriesController + case params[:action] + when 'show', 'revisions' + 'code_review/change_repository_view' + when 'revision' + 'code_review/change_revision_view' + when 'diff', 'entry', 'annotate' + if params[:rev].blank? or params[:rev] == 'master' + 'code_review/change_entry_norevision_view' + else + 'code_review/change_diff_view' + end + end + end + + if partial + controller.send :render_to_string, { partial: partial, + locals: { project: project } } + end + end + + end end From a030dd204ed2724c25255d34bdb88fde54c7986d Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Fri, 9 Mar 2018 20:10:30 +0800 Subject: [PATCH 15/17] if only interested in the first changeset, we only need to ask for 1 --- app/views/code_review/_change_entry_norevision_view.html.erb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/views/code_review/_change_entry_norevision_view.html.erb b/app/views/code_review/_change_entry_norevision_view.html.erb index 97b1d92..09d79b4 100644 --- a/app/views/code_review/_change_entry_norevision_view.html.erb +++ b/app/views/code_review/_change_entry_norevision_view.html.erb @@ -21,10 +21,7 @@ path = params[:path] rev = params[:rev] repository_id = @repository.identifier_param if @repository.respond_to?("identifier_param") unless path.blank? - changesets = @repository.latest_changesets(path, rev, Setting.repository_log_display_limit.to_i) - change = changesets[0] - - if change + if change = @repository.latest_changesets(path, rev, 1).first link = link_to(l(:label_add_review), {:controller => 'code_review', :action => 'forward_to_revision', :id => project, :path => path, :rev => rev, :repository_id => repository_id}, :class => 'icon icon-edit') From f387740551f63cb71477a444fb8cd4c6d2fff7c5 Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Mon, 12 Mar 2018 16:17:42 +0800 Subject: [PATCH 16/17] readability, reduce number of variables --- app/views/code_review/_update_diff_view.html.erb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/views/code_review/_update_diff_view.html.erb b/app/views/code_review/_update_diff_view.html.erb index 6a4d8a8..7aec273 100644 --- a/app/views/code_review/_update_diff_view.html.erb +++ b/app/views/code_review/_update_diff_view.html.erb @@ -31,16 +31,16 @@ @@ -56,7 +56,7 @@ var rev_to = '<%= j @rev_to %>'; var path = '<%= j @path -%>'; - setAddReviewButton(addReviewUrl, '<%= change_id %>', '<%= j image_tag('edit.png', :alt => l(:label_add_review), :title => l(:label_add_review)) %>', is_readonly, is_diff, '<%= attachment_id %>' ); + setAddReviewButton(addReviewUrl, '<%= change.try :id %>', '<%= j image_tag('edit.png', :alt => l(:label_add_review), :title => l(:label_add_review)) %>', is_readonly, is_diff, '<%= @attachment.try :id %>' ); var showReviewUrl = '<%= j url_for :controller => 'code_review', :action => 'show', :id=>@project %>'; var showReviewImageTag = '<%= j image_tag('review.png', :plugin => 'redmine_code_review', :alt => l(:label_show_review), :title => l(:label_show_review)) %>'; From 40143ef6ae6456fab65cfe80a1173f3594a608ce Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Mon, 12 Mar 2018 16:33:05 +0800 Subject: [PATCH 17/17] bugfixes --- app/views/code_review/_update_diff_view.html.erb | 2 +- init.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/code_review/_update_diff_view.html.erb b/app/views/code_review/_update_diff_view.html.erb index 7aec273..5e3b330 100644 --- a/app/views/code_review/_update_diff_view.html.erb +++ b/app/views/code_review/_update_diff_view.html.erb @@ -56,7 +56,7 @@ var rev_to = '<%= j @rev_to %>'; var path = '<%= j @path -%>'; - setAddReviewButton(addReviewUrl, '<%= change.try :id %>', '<%= j image_tag('edit.png', :alt => l(:label_add_review), :title => l(:label_add_review)) %>', is_readonly, is_diff, '<%= @attachment.try :id %>' ); + setAddReviewButton(addReviewUrl, '<%= @change.try :id %>', '<%= j image_tag('edit.png', :alt => l(:label_add_review), :title => l(:label_add_review)) %>', is_readonly, is_diff, '<%= @attachment.try :id %>' ); var showReviewUrl = '<%= j url_for :controller => 'code_review', :action => 'show', :id=>@project %>'; var showReviewImageTag = '<%= j image_tag('review.png', :plugin => 'redmine_code_review', :alt => l(:label_show_review), :title => l(:label_show_review)) %>'; diff --git a/init.rb b/init.rb index 1d35765..08bad93 100644 --- a/init.rb +++ b/init.rb @@ -49,6 +49,7 @@ Attachment.send(:include, CodeReviewAttachmentPatch) end + RepositoriesController.send :helper, :code_review end Redmine::Plugin.register :redmine_code_review do