Skip to content

Commit

Permalink
Merge pull request #1181 from dradis/fix-qa-redirect
Browse files Browse the repository at this point in the history
Fix qa redirect
  • Loading branch information
aapomm authored Jan 26, 2024
2 parents b831c80 + 67c59af commit 5c02515
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 24 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
- Upgraded gems:
- [gem]
- Bugs fixes:
- [entity]:
- [future tense verb] [bug fix]
- Tylium: Fix redirection when updating an issue or content block
- Bug tracker items:
- [item]
- New integrations:
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/shared/datatable/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ DradisDatatable.prototype.updateRecordState = function (newState) {
data: {
ids: DradisDatatable.prototype.rowIds(selectedRows),
state: newState,
return_to: $('[data-behavior~=qa-viewer]').length > 0 ? 'qa' : null
},
success: function () {
DradisDatatable.prototype.toggleStateBtn.call(api, false);
Expand Down
6 changes: 0 additions & 6 deletions app/controllers/concerns/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ def redirect_to_target_or_default(default, *args)
session[:return_to] = nil
end

# Store the URI of the current request in the session.
# We can return to this location by calling #redirect_back_or_default.
def store_location
session[:return_to] = request.original_url
end

# The main accessor for the warden proxy instance
# :api: public
def warden
Expand Down
28 changes: 16 additions & 12 deletions app/controllers/issues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class IssuesController < AuthenticatedController
before_action :set_affected_nodes, only: [:show]
before_action :set_form_cancel_path, only: [:new, :edit]
before_action :set_tags, except: [:destroy]
before_action :store_location, only: [:index, :show]

def index
end
Expand Down Expand Up @@ -85,14 +84,7 @@ def update
@modified = true
check_for_edit_conflicts(@issue, updated_at_before_save)
track_updated(@issue)
format.html do
if session[:return_to] == project_qa_issue_url(current_project, @issue)
# State changed. No longer needs QA
session[:return_to] = project_qa_issues_path(current_project) unless @issue.ready_for_review?
end

redirect_to_target_or_default project_issue_path(current_project, @issue), notice: 'Issue updated.'
end
format.html { redirect_to_main_or_qa }
else
format.html do
flash.now[:alert] = 'Issue couldn\'t be updated.'
Expand Down Expand Up @@ -136,6 +128,20 @@ def liquid_resource_assigns
{ 'issue' => IssueDrop.new(@issue) }
end

def redirect_to_main_or_qa
notice = 'Issue updated.'

if params[:return_to] == 'qa'
if @issue.ready_for_review?
redirect_to project_qa_issue_path(current_project, @issue), notice: notice
else
redirect_to project_qa_issues_path(current_project), notice: notice
end
else
redirect_to project_issue_path(current_project, @issue), notice: notice
end
end

def set_affected_nodes
@affected_nodes = Node.joins(:evidence)
.select('nodes.id, label, type_id, count(evidence.id) as evidence_count, nodes.updated_at')
Expand All @@ -145,9 +151,7 @@ def set_affected_nodes
end

def set_form_cancel_path
path = @issue.new_record? ? project_issues_path(current_project) : [current_project, @issue]

@form_cancel_path = session[:return_to] ? session[:return_to] : path
@form_cancel_path = @issue.new_record? ? project_issues_path(current_project) : [current_project, @issue]
end

def set_columns
Expand Down
10 changes: 8 additions & 2 deletions app/controllers/qa/issues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class QA::IssuesController < AuthenticatedController

before_action :set_issues
before_action :set_issue, only: [:edit, :show, :preview, :update]
before_action :store_location, only: [:index, :show]
before_action :validate_state, only: [:multiple_update, :update]

def index
Expand Down Expand Up @@ -40,7 +39,14 @@ def multiple_update
track_state_change(issue)
end

format.html { redirect_to_target_or_default project_qa_issues_path(current_project), notice: 'State updated successfully.' }
format.html do
if params[:return_to] == 'qa'
redirect_to project_qa_issues_path(current_project), notice: 'State updated successfully.'
else
redirect_to project_issues_path(current_project), notice: 'State updated successfully.'
end
end

format.json { head :ok }
else
format.html { render :show, alert: @issues.errors.full_messages.join('; ') }
Expand Down
4 changes: 4 additions & 0 deletions app/views/issues/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
<%= hidden_field :issue, :original_updated_at, value: @issue.updated_at.to_i %>
<% end %>
<% if controller.class.name.deconstantize == 'QA' %>
<%= hidden_field nil, :return_to, value: :qa %>
<% end %>
<%= render 'issues/tag_input', f: f %>

<div class="form-actions">
Expand Down
4 changes: 2 additions & 2 deletions spec/support/qa_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
end
end

it 'redirects the user back to #index after updating the record' do
it 'redirects the user back to #show after updating the record' do
find('.dataTable tbody tr:first-of-type').hover
click_link 'Edit'

expect(current_path).to eq polymorphic_path([:edit, current_project, :qa, records.first])

click_button "Update #{item_type.to_s.titleize}"

expect(current_path).to eq polymorphic_path([current_project, :qa, item_type.to_s.pluralize.to_sym])
expect(current_path).to eq polymorphic_path([current_project, :qa, records.first])
expect(page).to have_selector('.alert-success', text: "#{item_type.to_s.humanize} updated.")
end

Expand Down

0 comments on commit 5c02515

Please sign in to comment.