Skip to content
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

Create AdopterFosterAccount #551

Merged
merged 21 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/controllers/adoptable_pets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ def show
@pet = Pet.find(params[:id])
authorize! @pet, with: AdoptablePetPolicy

if current_user&.adopter_account
if current_user&.adopter_foster_account
@adoption_application =
AdopterApplication.find_by(
pet_id: @pet.id,
adopter_account_id: current_user.adopter_account.id
adopter_foster_account_id: current_user.adopter_foster_account.id
) ||
@pet.adopter_applications.build(
adopter_account: current_user.adopter_account
adopter_foster_account: current_user.adopter_foster_account
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/adopter_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def update
def application_params
params.require(:adopter_application).permit(
:pet_id,
:adopter_account_id,
:adopter_foster_account_id,
:status,
:profile_show
)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/adopter_foster_profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def update
private

def set_profile
@adopter_foster_profile = current_user.adopter_account.adopter_foster_profile
@adopter_foster_profile = current_user.adopter_foster_account.adopter_foster_profile
authorize! @adopter_foster_profile
end

def adopter_foster_profile_params
params.require(:adopter_foster_profile).permit(:adopter_account_id,
params.require(:adopter_foster_profile).permit(:adopter_foster_account_id,
:phone_number,
:contact_method,
:ideal_pet,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/matches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def destroy
private

def match_params
params.require(:match).permit(:pet_id, :adopter_account_id)
params.require(:match).permit(:pet_id, :adopter_foster_account_id)
end

def set_pet
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class RegistrationsController < Devise::RegistrationsController
# no attributes need to be accepted, just create new account with user_id reference
def new
build_resource({})
resource.build_adopter_account
resource.build_adopter_foster_account
respond_with resource
end

Expand All @@ -30,7 +30,7 @@ def sign_up_params
:password,
:signup_role,
:tos_agreement,
adopter_account_attributes: [:user_id])
adopter_foster_account_attributes: [:user_id])
end

def account_update_params
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/match_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class MatchMailer < ApplicationMailer
def reminder(match)
@match = match

@adopter_account = match.adopter_account
@user = @adopter_account.user
@adopter_foster_account = match.adopter_foster_account
@user = @adopter_foster_account.user
@pet = match.pet

mail to: @user.email, subject: "#{@pet.name}'s Reminder"
Expand Down
34 changes: 17 additions & 17 deletions app/models/adopter_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
#
# Table name: adopter_applications
#
# id :bigint not null, primary key
# notes :text
# profile_show :boolean default(TRUE)
# status :integer default("awaiting_review")
# created_at :datetime not null
# updated_at :datetime not null
# adopter_account_id :bigint not null
# pet_id :bigint not null
# id :bigint not null, primary key
# notes :text
# profile_show :boolean default(TRUE)
# status :integer default("awaiting_review")
# created_at :datetime not null
# updated_at :datetime not null
# adopter_foster_account_id :bigint
# pet_id :bigint not null
#
# Indexes
#
# index_adopter_applications_on_adopter_account_id (adopter_account_id)
# index_adopter_applications_on_pet_id (pet_id)
# index_adopter_applications_on_adopter_foster_account_id (adopter_foster_account_id)
# index_adopter_applications_on_pet_id (pet_id)
#
# Foreign Keys
#
# fk_rails_... (adopter_account_id => adopter_accounts.id)
# fk_rails_... (adopter_foster_account_id => adopter_foster_accounts.id)
# fk_rails_... (pet_id => pets.id)
#
class AdopterApplication < ApplicationRecord
belongs_to :pet
belongs_to :adopter_account
belongs_to :adopter_foster_account

enum :status, [:awaiting_review,
:under_review,
Expand All @@ -42,14 +42,14 @@ def self.app_review_statuses
end

# check if an adopter has applied to adopt a pet
def self.adoption_exists?(adopter_account_id, pet_id)
AdopterApplication.where(adopter_account_id: adopter_account_id,
def self.adoption_exists?(adopter_foster_account_id, pet_id)
AdopterApplication.where(adopter_foster_account_id: adopter_foster_account_id,
pet_id: pet_id).exists?
end

# check if any applications are set to profile_show: true
def self.any_applications_profile_show_true?(adopter_account_id)
applications = AdopterApplication.where(adopter_account_id: adopter_account_id)
def self.any_applications_profile_show_true?(adopter_foster_account_id)
applications = AdopterApplication.where(adopter_foster_account_id: adopter_foster_account_id)
applications.any? { |app| app.profile_show == true }
end

Expand All @@ -60,7 +60,7 @@ def self.retire_applications(pet_id:)
end

def applicant_name
"#{adopter_account.user.last_name}, #{adopter_account.user.first_name}"
"#{adopter_foster_account.user.last_name}, #{adopter_foster_account.user.first_name}"
end

def withdraw
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# == Schema Information
#
# Table name: adopter_accounts
# Table name: adopter_foster_accounts
#
# id :bigint not null, primary key
# created_at :datetime not null
Expand All @@ -9,13 +9,13 @@
#
# Indexes
#
# index_adopter_accounts_on_user_id (user_id)
# index_adopter_foster_accounts_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
class AdopterAccount < ApplicationRecord
class AdopterFosterAccount < ApplicationRecord
belongs_to :user
has_one :adopter_foster_profile, dependent: :destroy
has_many :adopter_applications, dependent: :destroy
Expand Down
82 changes: 41 additions & 41 deletions app/models/adopter_foster_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,57 @@
#
# Table name: adopter_foster_profiles
#
# id :bigint not null, primary key
# activities :text
# adults_in_home :integer
# alone_weekday :integer
# alone_weekend :integer
# annual_cost :string
# checked_shelter :boolean
# city_town :string
# contact_method :string
# contingency_plan :text
# country :string
# describe_pets :text
# describe_surrender :text
# do_you_rent :boolean
# experience :text
# fenced_access :boolean
# fenced_alternative :text
# housing_type :string
# ideal_pet :text
# kids_in_home :integer
# lifestyle_fit :text
# location_day :text
# location_night :text
# other_pets :boolean
# pets_allowed :boolean
# phone_number :string
# province_state :string
# referral_source :text
# shared_owner :text
# shared_ownership :boolean
# surrendered_pet :boolean
# visit_dates :text
# visit_laventana :boolean
# created_at :datetime not null
# updated_at :datetime not null
# adopter_account_id :bigint not null
# location_id :bigint not null
# id :bigint not null, primary key
# activities :text
# adults_in_home :integer
# alone_weekday :integer
# alone_weekend :integer
# annual_cost :string
# checked_shelter :boolean
# city_town :string
# contact_method :string
# contingency_plan :text
# country :string
# describe_pets :text
# describe_surrender :text
# do_you_rent :boolean
# experience :text
# fenced_access :boolean
# fenced_alternative :text
# housing_type :string
# ideal_pet :text
# kids_in_home :integer
# lifestyle_fit :text
# location_day :text
# location_night :text
# other_pets :boolean
# pets_allowed :boolean
# phone_number :string
# province_state :string
# referral_source :text
# shared_owner :text
# shared_ownership :boolean
# surrendered_pet :boolean
# visit_dates :text
# visit_laventana :boolean
# created_at :datetime not null
# updated_at :datetime not null
# adopter_foster_account_id :bigint
# location_id :bigint not null
#
# Indexes
#
# index_adopter_foster_profiles_on_adopter_account_id (adopter_account_id)
# index_adopter_foster_profiles_on_location_id (location_id)
# index_adopter_foster_profiles_on_adopter_foster_account_id (adopter_foster_account_id)
# index_adopter_foster_profiles_on_location_id (location_id)
#
# Foreign Keys
#
# fk_rails_... (adopter_account_id => adopter_accounts.id)
# fk_rails_... (adopter_foster_account_id => adopter_foster_accounts.id)
# fk_rails_... (location_id => locations.id)
#
class AdopterFosterProfile < ApplicationRecord
belongs_to :location, dependent: :destroy
belongs_to :adopter_account
belongs_to :adopter_foster_account
accepts_nested_attributes_for :location
validates_associated :location

Expand Down
24 changes: 12 additions & 12 deletions app/models/match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
#
# Table name: matches
#
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# adopter_account_id :bigint not null
# organization_id :bigint not null
# pet_id :bigint not null
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# adopter_foster_account_id :bigint
# organization_id :bigint not null
# pet_id :bigint not null
#
# Indexes
#
# index_matches_on_adopter_account_id (adopter_account_id)
# index_matches_on_organization_id (organization_id)
# index_matches_on_pet_id (pet_id)
# index_matches_on_adopter_foster_account_id (adopter_foster_account_id)
# index_matches_on_organization_id (organization_id)
# index_matches_on_pet_id (pet_id)
#
# Foreign Keys
#
# fk_rails_... (adopter_account_id => adopter_accounts.id)
# fk_rails_... (adopter_foster_account_id => adopter_foster_accounts.id)
# fk_rails_... (pet_id => pets.id)
#
class Match < ApplicationRecord
acts_as_tenant(:organization)
belongs_to :pet
belongs_to :adopter_account
belongs_to :adopter_foster_account

validate :belongs_to_same_organization_as_pet, if: -> { pet.present? }

Expand All @@ -50,6 +50,6 @@ def belongs_to_same_organization_as_pet
end

def adopter_application
AdopterApplication.find_by(pet:, adopter_account:)
AdopterApplication.find_by(pet:, adopter_foster_account:)
end
end
2 changes: 1 addition & 1 deletion app/models/pet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def self.org_pets(staff_org_id)

# all pets under an organization with applications and no adoptions
def self.org_pets_with_apps(staff_org_id)
Pet.org_pets(staff_org_id).includes(adopter_applications: [adopter_account: [:user]]).where
Pet.org_pets(staff_org_id).includes(adopter_applications: [adopter_foster_account: [:user]]).where
.not(adopter_applications: {id: nil}).includes(:match)
.where(match: {id: nil})
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class User < ApplicationRecord
# allow_nil: false, on: :create

has_one :staff_account, dependent: :destroy
has_one :adopter_account, dependent: :destroy
has_one :adopter_foster_account, dependent: :destroy

accepts_nested_attributes_for :adopter_account
accepts_nested_attributes_for :adopter_foster_account

# get user accounts for staff in a given organization
def self.organization_staff(org_id)
Expand Down
10 changes: 5 additions & 5 deletions app/policies/adopter_application_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class AdopterApplicationPolicy < ApplicationPolicy
pre_check :verify_pet_appliable!, only: %i[create?]

relation_scope do |relation|
relation.where(adopter_account_id: user.adopter_account.id)
relation.where(adopter_foster_account_id: user.adopter_foster_account.id)
end

def update?
Expand All @@ -23,18 +23,18 @@ def create?
private

def applicant?
user.id == record.adopter_account.user_id
user.id == record.adopter_foster_account.user_id
end

def already_applied?
user.adopter_account.adopter_applications.any? do |application|
user.adopter_foster_account.adopter_applications.any? do |application|
application.pet_id == pet.id
end
end

def verify_profile!
deny! unless user.adopter_account.present?
deny! unless user.adopter_account.adopter_foster_profile.present?
deny! unless user.adopter_foster_account.present?
deny! unless user.adopter_foster_account.adopter_foster_profile.present?
end

def verify_pet_appliable!
Expand Down
4 changes: 2 additions & 2 deletions app/policies/adopter_foster_profile_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def manage?
private

def no_profile?
user&.adopter_account&.adopter_foster_profile.nil?
user&.adopter_foster_account&.adopter_foster_profile.nil?
end

def owner?
user.id == record.adopter_account.user_id
user.id == record.adopter_foster_account.user_id
end
end
2 changes: 1 addition & 1 deletion app/policies/profile_review_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ def show?
private

def organization
@organization || record.adopter_account.user.organization
@organization || record.adopter_foster_account.user.organization
end
end
Loading
Loading