Skip to content

Commit

Permalink
revert renaming of adopter applications to custom form submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
kasugaijin committed Jun 26, 2024
1 parent fb85ab0 commit 2ea43d9
Show file tree
Hide file tree
Showing 71 changed files with 777 additions and 792 deletions.
8 changes: 4 additions & 4 deletions app/controllers/organizations/adoptable_pets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Organizations::AdoptablePetsController < Organizations::BaseController
helper_method :get_animals

def index
@q = authorized_scope(Pet.includes(:submissions, images_attachments: :blob),
@q = authorized_scope(Pet.includes(:adopter_applications, images_attachments: :blob),
with: Organizations::AdoptablePetPolicy).ransack(params[:q])
@pagy, paginated_adoptable_pets = pagy(
@q.result,
Expand All @@ -20,12 +20,12 @@ def show
authorize! @pet, with: Organizations::AdoptablePetPolicy

if current_user&.adopter_foster_account
@submission =
CustomForm::Submission.find_by(
@adoption_application =
AdopterApplication.find_by(
pet_id: @pet.id,
adopter_foster_account_id: current_user.adopter_foster_account.id
) ||
@pet.submissions.build(
@pet.adopter_applications.build(
adopter_foster_account: current_user.adopter_foster_account
)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class Organizations::AdopterFosterer::AdopterApplicationsController < Organizations::BaseController
before_action :authenticate_user!
before_action :set_application, only: %i[update]
layout "adopter_foster_dashboard"

def index
authorize! with: AdopterApplicationPolicy

@applications = authorized_scope(AdopterApplication.where(profile_show: true), with: AdopterApplicationPolicy)
end

def create
@pet = Pet.find(application_params[:pet_id])
authorize! context: {pet: @pet}, with: AdopterApplicationPolicy

@application = AdopterApplication.new(application_params)

if @application.save
redirect_to adoptable_pet_path(@application.pet),
notice: t(".success", message: MessagesHelper.affirmations.sample)

# mailer
@org_staff = User.organization_staff(@pet.organization_id)
StaffApplicationNotificationMailer.with(pet: @pet,
organization_staff: @org_staff)
.new_adoption_application.deliver_now
else
redirect_to adoptable_pet_path(@pet),
alert: t(".error")
end
end

# update :status to 'withdrawn' or :profile_show to false
def update
if @application.update(application_params)
redirect_to adopter_fosterer_adopter_applications_path
else
redirect_to adopter_fosterer_profile_path, alert: t(".error")
end
end

private

def set_application
@application = AdopterApplication.find(params[:id])
authorize! @application, with: AdopterApplicationPolicy
end

def application_params
params.require(:adopter_application).permit(
:pet_id,
:adopter_foster_account_id,
:status,
:profile_show
)
end
end

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def index
@user = current_user
@organization = Current.organization
@hide_footer = true
@submission_count = @user.adopter_foster_account&.submissions&.count.to_i
@application_count = @user.adopter_foster_account&.adopter_applications&.count.to_i

authorize! :adopter_foster_dashboard, context: {organization: @organization}
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class Organizations::Staff::AdoptionApplicationReviewsController < Organizations::BaseController
before_action :set_adopter_application, only: %i[edit update]

include ::Pagy::Backend

layout "dashboard"

def index
authorize! AdopterApplication,
context: {organization: Current.organization}

@q = authorized_scope(
Pet.org_pets_with_apps(current_user.staff_account.organization_id)
).ransack(params[:q])
@pets_with_applications = @q.result.includes(:adopter_applications)

# Combining these into a single chained statement does not yield the same result due to how Ransack processes parameters.
if params[:q].present? && params[:q]["adopter_applications_status_eq"].present?
status_filter = params[:q]["adopter_applications_status_eq"]
@pets_with_applications = filter_by_application_status(@pets_with_applications, status_filter)
end

@pagy, @pets_with_applications = pagy(@pets_with_applications, items: 10)
end

def edit
end

def update
@applications_tab = request.referrer.include?("applications") # Change table display in pets/applications tab

respond_to do |format|
if @application.update(application_params)
format.html { redirect_to staff_dashboard_index_path }
format.turbo_stream { flash.now[:notice] = t(".success") }
else
format.html { render :edit, status: :unprocessable_entity }
format.turbo_stream { flash.now[:alert] = t(".error") }
end
end
end

private

def application_params
params.require(:adopter_application).permit(:status, :notes, :profile_show)
end

def set_adopter_application
@application = AdopterApplication.find(params[:id])
authorize! @application
end

def filter_by_application_status(pets_relation, status_filter)
pets_relation.joins(:adopter_applications).where(adopter_applications: {status: status_filter})
end
end
4 changes: 2 additions & 2 deletions app/controllers/organizations/staff/matches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def create

if @match.save
AdoptionMailer.reminder(@match).deliver_later
@match.retire_submissions
@match.retire_applications

redirect_back_or_to staff_dashboard_index_path, notice: t(".success")
else
Expand All @@ -21,7 +21,7 @@ def create

def destroy
if @match.destroy
@match.withdraw_submission
@match.withdraw_application

redirect_to staff_pets_path, notice: t(".success")
else
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/organizations/staff/pets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ def set_pet
end

def determine_active_tab
["tasks", "submissions", "fosters", "photos", "files"].include?(params[:active_tab]) ? params[:active_tab] : "overview"
["tasks", "applications", "fosters", "photos", "files"].include?(params[:active_tab]) ? params[:active_tab] : "overview"
end
end

This file was deleted.

4 changes: 2 additions & 2 deletions app/helpers/adoption_application_reviews_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module AdoptionApplicationReviewsHelper
def submission_status_classes(submission)
def application_status_classes(application)
status_classes = {awaiting_review: "text-white bg-dark-primary",
under_review: "text-white bg-dark-info",
adoption_pending: "text-black bg-light-warning",
withdrawn: "text-black bg-gray-200",
successful_applicant: "text-black bg-light-success",
adoption_made: "text-black bg-light-success"}

status_classes[submission.status.to_sym]
status_classes[application.status.to_sym]
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class StaffSubmissionNotificationMailer < ApplicationMailer
def new_adoption_submission
class StaffApplicationNotificationMailer < ApplicationMailer
def new_adoption_application
@organization_staff = params[:organization_staff]
@pet = params[:pet]

Expand Down
Loading

0 comments on commit 2ea43d9

Please sign in to comment.