-
-
Notifications
You must be signed in to change notification settings - Fork 486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#1733] Add option to remove Court Mandates #1802
Merged
compwron
merged 5 commits into
rubyforgood:main
from
rhian-cs:1733-add-option-to-remove-court-mandates
Mar 3, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2c50c03
Added a way to delete court mandates
2a67a48
Added tests for removing court mandates
ffd6efb
Removed two unnecessary functions in casa_case.js
1b150dc
Fixed small spec issues regarding case court mandates
243f355
Corrected court mandate dialog box text title
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class CaseCourtMandatesController < ApplicationController | ||
before_action :set_case_court_mandate, only: %i[destroy] | ||
before_action :require_organization! | ||
after_action :verify_authorized | ||
|
||
def destroy | ||
authorize @case_court_mandate | ||
@case_court_mandate.destroy | ||
end | ||
|
||
private | ||
|
||
def set_case_court_mandate | ||
@case_court_mandate = CaseCourtMandate.find(params[:id]) | ||
rescue ActiveRecord::RecordNotFound | ||
head :not_found | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,57 @@ id="casa_case_case_court_mandates_attributes_1_mandate_text">\ | |
$(list).children(':last').trigger('focus') | ||
} | ||
|
||
function remove_mandate_with_confirmation () { | ||
Swal.fire({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Swal! |
||
icon: 'warning', | ||
title: 'Delete court mandate?', | ||
text: 'Are you sure you want to remove this court mandate? Doing so will \ | ||
delete all records of it unless it was included in a previous court report.', | ||
|
||
showCloseButton: true, | ||
showCancelButton: true, | ||
focusConfirm: false, | ||
|
||
confirmButtonColor: '#d33', | ||
cancelButtonColor: '#39c', | ||
|
||
confirmButtonText: 'Delete', | ||
cancelButtonText: 'Go back' | ||
}).then((result) => { | ||
if (result.isConfirmed) { | ||
remove_mandate_action($(this)) | ||
} | ||
}) | ||
} | ||
|
||
function remove_mandate_action (ctx) { | ||
id_element = ctx.parent().next('input[type="hidden"]') | ||
id = id_element.val() | ||
|
||
$.ajax({ | ||
url: `/case_court_mandates/${id}`, | ||
method: 'delete', | ||
success: () => { | ||
ctx.parent().remove() | ||
id_element.remove() // Remove form element since this mandate has been deleted | ||
|
||
Swal.fire({ | ||
icon: 'success', | ||
text: 'Court mandate has been removed.', | ||
showCloseButton: true | ||
}) | ||
}, | ||
error: () => { | ||
Swal.fire({ | ||
icon: 'error', | ||
text: 'Something went wrong when attempting to delete this court mandate.', | ||
showCloseButton: true | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
$('document').ready(() => { | ||
$('button#add-mandate-button').on('click', add_court_mandate_input) | ||
$('button.remove-mandate-button').on('click', remove_mandate_with_confirmation) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class CaseCourtMandatePolicy < ApplicationPolicy | ||
alias_method :destroy?, :admin_or_supervisor? | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "/case_court_mandates", type: :request do | ||
subject(:delete_request) { delete case_court_mandate_url(case_court_mandate) } | ||
let(:case_court_mandate) { build(:case_court_mandate) } | ||
|
||
before do | ||
sign_in user | ||
casa_case = create(:casa_case) | ||
casa_case.case_court_mandates << case_court_mandate | ||
end | ||
|
||
describe "as an admin" do | ||
let(:user) { create(:casa_admin) } | ||
|
||
describe "DELETE /destroy" do | ||
it "renders a successful response" do | ||
delete_request | ||
expect(response).to be_successful | ||
end | ||
|
||
it "deletes the court mandate" do | ||
expect { delete_request }.to change(CaseCourtMandate, :count).from(1).to(0) | ||
end | ||
end | ||
end | ||
|
||
describe "as a supervisor" do | ||
let(:user) { create(:supervisor) } | ||
|
||
describe "DELETE /destroy" do | ||
it "renders a successful response" do | ||
delete_request | ||
expect(response).to be_successful | ||
end | ||
|
||
it "deletes the court mandate" do | ||
expect { delete_request }.to change(CaseCourtMandate, :count).from(1).to(0) | ||
end | ||
end | ||
end | ||
|
||
describe "as a volunteer" do | ||
let(:user) { create(:volunteer) } | ||
|
||
describe "DELETE /destroy" do | ||
it "renders a successful response" do | ||
delete_request | ||
# CASA will attempt to redirect to another page | ||
expect(response.status).to be(302) | ||
end | ||
|
||
it "deletes the court mandate" do | ||
expect { delete_request }.to_not change(CaseCourtMandate, :count) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should be private