Skip to content

Commit

Permalink
Merge branch 'main' into add-new-pet-tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrigoriev8109 authored Dec 17, 2024
2 parents a5660c2 + e7169ff commit f85f185
Show file tree
Hide file tree
Showing 42 changed files with 607 additions and 220 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,15 @@
"contributions": [
"code"
]
},
{
"login": "mgrigoriev8109",
"name": "Mikhail Grigoriev",
"avatar_url": "https://avatars.githubusercontent.com/u/43343880?v=4",
"profile": "https://github.com/mgrigoriev8109",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ GEM
ast (~> 2.4.1)
racc
pg (1.5.9)
phonelib (0.10.1)
phonelib (0.10.2)
popper_js (2.11.8)
propshaft (1.1.0)
actionpack (>= 7.0.0)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Homeward Tails Adoption Application
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-69-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-70-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

The Homeward Tails app is derived from the [Baja Pet Rescue Dog Adoption Application](https://github.com/kasugaijin/baja-pet-rescue/tree/main) created by @kasugaijin who wanted to give back to the grassroots organization from where he adopted his dog in Mexico by building them a web application. Homeward Tails is an application that makes it easy to connect shelters with people who are looking to adopt or foster pets.
Expand Down Expand Up @@ -321,6 +321,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jrussell416"><img src="https://avatars.githubusercontent.com/u/58918229?v=4?s=100" width="100px;" alt="jrussell416"/><br /><sub><b>jrussell416</b></sub></a><br /><a href="https://github.com/rubyforgood/homeward-tails/commits?author=jrussell416" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/caitlynl22"><img src="https://avatars.githubusercontent.com/u/8726946?v=4?s=100" width="100px;" alt="Caitlyn Landry"/><br /><sub><b>Caitlyn Landry</b></sub></a><br /><a href="https://github.com/rubyforgood/homeward-tails/commits?author=caitlynl22" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/jasonwang7517/"><img src="https://avatars.githubusercontent.com/u/39580712?v=4?s=100" width="100px;" alt="Jason Wang"/><br /><sub><b>Jason Wang</b></sub></a><br /><a href="https://github.com/rubyforgood/homeward-tails/commits?author=jasonwang7517" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mgrigoriev8109"><img src="https://avatars.githubusercontent.com/u/43343880?v=4?s=100" width="100px;" alt="Mikhail Grigoriev"/><br /><sub><b>Mikhail Grigoriev</b></sub></a><br /><a href="https://github.com/rubyforgood/homeward-tails/commits?author=mgrigoriev8109" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
23 changes: 23 additions & 0 deletions app/controllers/organizations/activations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Organizations
class ActivationsController < Organizations::BaseController
def update
@user = User.find(params[:user_id])

authorize! @user, with: ActivationsPolicy

if @user.deactivated_at
@user.activate
else
@user.deactivate
end

respond_to do |format|
success = @user.deactivated_at.nil? ?
t(".activated", staff: @user.full_name) :
t(".deactivated", staff: @user.full_name)
format.html { redirect_to staff_staff_index_path, notice: success }
format.turbo_stream { flash.now[:notice] = success }
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Organizations
module AdopterFosterer
class FormAnswersController < Organizations::BaseController
layout "adopter_foster_dashboard"

before_action :context_authorize!
before_action :set_latest_form_submission

def index
@form_answers = authorized_scope(@latest_form_submission.form_answers)
end

private

def context_authorize!
authorize! with: Organizations::AdopterFosterer::FormAnswerPolicy
end

def set_latest_form_submission
@latest_form_submission = current_user.person.latest_form_submission
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,8 @@ def index

def create
authorize! :external_form_upload, context: {organization: Current.organization}

# Only processes single file upload
import = Organizations::Importers::CsvImportService.new(params[:files]).call

if import.success?
# do something
else
# import.errors
end
render turbo_stream: turbo_stream.replace("results", partial: "organizations/staff/external_form_upload/upload_results", locals: {import: import})
end
end
end
Expand Down
25 changes: 0 additions & 25 deletions app/controllers/organizations/staff/staff_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Organizations::Staff::StaffController < Organizations::BaseController
before_action :set_staff, only: [:update_activation]
include ::Pagy::Backend

layout "dashboard"
Expand All @@ -12,28 +11,4 @@ def index
limit: 10
)
end

def update_activation
if @staff.deactivated_at
@staff.activate
else
@staff.deactivate
end

respond_to do |format|
success = @staff.deactivated_at.nil? ?
t(".activated", staff: @staff.full_name) :
t(".deactivated", staff: @staff.full_name)
format.html { redirect_to staff_staff_index_path, notice: success }
format.turbo_stream { flash.now[:notice] = success }
end
end

private

def set_staff
@staff = User.find(params[:staff_id])

authorize! @staff
end
end
3 changes: 3 additions & 0 deletions app/models/concerns/authorizable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def staff?(organization)
view_adopted_pets
read_pet_tasks
view_external_form
view_form_answers
].freeze

FOSTERER_PERMISSIONS = %i[
Expand Down Expand Up @@ -56,6 +57,8 @@ def staff?(organization)
view_people
view_form_submissions
manage_faqs
activate_adopter
activate_foster
]
).freeze

Expand Down
1 change: 1 addition & 0 deletions app/models/form_answer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
class FormAnswer < ApplicationRecord
acts_as_tenant(:organization)
belongs_to :form_submission
has_one :person, through: :form_submission
end
18 changes: 18 additions & 0 deletions app/policies/organizations/activations_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Organizations
class ActivationsPolicy < ApplicationPolicy
pre_check :verify_organization!
pre_check :verify_active_staff!

def update?
return false if record.id == user.id

record_role = record.roles.first.name

if %w[super_admin admin].include?(record_role)
permission?(:activate_staff)
else
permission?(:activate_foster) && permission?(:activate_adopter)
end
end
end
end
13 changes: 13 additions & 0 deletions app/policies/organizations/adopter_fosterer/form_answer_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Organizations
module AdopterFosterer
class FormAnswerPolicy < ApplicationPolicy
relation_scope do |relation|
relation.joins(form_submission: :person).where(form_submissions: {person_id: user.person.id})
end

def index?
permission?(:view_form_answers)
end
end
end
end
4 changes: 0 additions & 4 deletions app/policies/organizations/user_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@ class Organizations::UserPolicy < ApplicationPolicy
def index?
permission?(:manage_staff)
end

def update_activation?
permission?(:activate_staff) && record.id != user.id
end
end
4 changes: 2 additions & 2 deletions app/services/organizations/importers/csv_import_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ def call
catch(:halt_import) do
validate_file

CSV.foreach(@file.to_path, headers: true, skip_blanks: true).with_index(1) do |row, index|
CSV.foreach(@file.to_path, headers: true, skip_blanks: true).with_index(2) do |row, index|
# Header may be different depending on which form applicaiton was used(e.g. google forms) or how it was created(User creates form with "Email Address")
email = row[@email_header].downcase
# Google forms uses "Timestamp", other services may use a different header
csv_timestamp = Time.parse(row["Timestamp"])
csv_timestamp = Time.parse(row["Timestamp"]) if row["Timestamp"].present?

person = Person.find_by(email:, organization: @organization)
previously_matched_form_submission = FormSubmission.where(person:, csv_timestamp:)
Expand Down
10 changes: 9 additions & 1 deletion app/views/layouts/adopter_foster_dashboard.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,15 @@
<% if Current.organization.external_form_url.present? %>
<li class="nav-item">
<%= active_link_to adopter_fosterer_external_form_index_path(dashboard: true), class: "nav-link" do %>
<i class="fe fe-help-circle nav-icon"></i> My Info
<i class="fe fe-clipboard nav-icon"></i> Form
<% end %>

<% if current_user.person.latest_form_submission.present? %>
<li class="nav-item">
<%= active_link_to adopter_fosterer_form_answers_path, class: "nav-link" do %>
<i class="fe fe-clipboard nav-icon"></i> Form Responses
<% end %>
</li>
<% end %>
</li>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/shared/_footer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<div class="col-lg-4 col-md-6 col-12">
<!-- about company -->
<div class="mb-4">
<h3> <%= t('.title') %> </h3>
<h3> <%= t('.organization_name', name: Current.tenant.name) %> </h3>
<div class="mt-4">
<p>
<%= t('.call') %>
<%= link_to t('.action'), new_organization_account_request_path %>
<%= link_to t('.action'), Rails.env.production? ? "https://www.homewardtails.org/organization_account_request/new" : "http://localhost:3000/organization_account_request/new" %>

</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= turbo_stream.replace "flash", partial: "layouts/shared/flash_messages" %>
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<div class="d-flex flex-column align-items-center mb-4">
<div class="my-4 mx-8">
<% if params[:dashboard] %>
<p><%= t("organizations.adopter_fosterer.form_instructions.dashboard") %></p>
<% else %>

<% if current_user.person.latest_form_submission.present? %>
<p class="fw-bold mb-0"><%= t('organizations.adopter_fosterer.form_instructions.previous_answers') %> <%= link_to t('general.here'), adopter_fosterer_form_answers_path %>.</p>
<p><%= t('organizations.adopter_fosterer.form_instructions.update_form_answers') %></p>
<% else %>
<p><%= t("organizations.adopter_fosterer.form_instructions.dashboard", user_email: current_user.email) %></p>
<% end %>

<% else %>
<p><%= t(
"organizations.adopter_fosterer.form_instructions.index",
organization_name: Current.tenant.name,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= render DashboardPageComponent.new do |c| %>
<% c.with_header_title { t('.header') } %>
<% c.with_body do %>

<p><%= t('.description') %> <%= link_to t("general.here"), adopter_fosterer_external_form_index_path(dashboard: true) %>.</p>

<div class="justify-content-md-between mb-4 mb-xl-0 gx-3">
<div class="row">
<% if @form_answers.present? %>
<h4><%= t(".submitted_on", date: @latest_form_submission.csv_timestamp.strftime("%Y-%m-%d"), time: @latest_form_submission.csv_timestamp.strftime("%H:%M")) %></h4>

<%= render partial: "organizations/shared/form_answers", collection: @form_answers, as: :form_answer %>
<% end %>
</div>
</div>
<% end %>
<% end %>
12 changes: 12 additions & 0 deletions app/views/organizations/shared/_form_answers.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="justify-content-md-between mb-2 gx-3">
<div class="card">
<div id="<%= dom_id form_answer %>"class="card-body d-flex flex-sm-row flex-column justify-content-between border-bottom">
<div class="d-flex align-items-center">
<div>
<strong class="fs-4" >Q: <%= form_answer.question_snapshot %></strong>
<p class="mb-0">A: <%= form_answer.value %> </p>
</div>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<span><%= t(:joined) %></span>
<span><%= adopter.created_at.strftime("%d %B, %Y") %></span>
</div>
<div class="d-flex justify-content-between pt-2">
<span><%= t(:deactivate) %></span>
<%= render "organizations/staff/shared/deactivate_toggle", user: adopter.user %>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<tr>
<th scope="col"><%= t(:name) %></th>
<th scope="col"><%= t(:joined_at) %></th>
<th class="text-center" scope="col"><%= t(:deactivate) %></th>
</tr>
</thead>
<tbody>
Expand All @@ -25,6 +26,9 @@
<td>
<%= adopter.created_at.strftime("%d %B, %Y") %>
</td>
<td>
<%= render "organizations/staff/shared/deactivate_toggle", user: adopter.user %>
</td>
</tr>
<% end %>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion app/views/organizations/staff/custom_pages/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
label: "Hero Image",
class: 'form-control'%>
</div>
<small class="form-text text-muted"> Images must be .png or .jpeg under 2MB </small>
<small class="form-text text-muted"> Image must be .png or .jpeg under 2MB </small>
<div class="form-group mt-4">
<%= form.text_area :about, label: "About Us", placeholder: "About Us text", class: 'form-control' %>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<turbo-frame id="results">
<% if import.success? %>
<div class="alert alert-success">
<h5 class="alert-heading" role="alert"><%= t('.success_heading') %></h5>
<p><%= t('.submissions_added', count: import.count) %></p>
</div>
<% else %>
<div class="alert alert-danger">
<h5 class="alert-heading" role="alert"><%= t('.error_heading', count: import.errors.count) %></h5>
<p><%= t('.submissions_added', count: import.count) %></p>
<%= t('.review_errors', count: import.count) %>
<ul>
<% import.errors.each do |error| %>
<li>
<%= t('.row', number: error[0], message: error[1].message) %>
</li>
<% end %>
</ul>
</div>
<% end %>
</turbo-frame>
15 changes: 1 addition & 14 deletions app/views/organizations/staff/form_answers/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
<%= turbo_frame_tag :form_answers do %>
<h4>Form Answers (<%= @form_submission.csv_timestamp.strftime("%Y-%m-%d") %> at <%= @form_submission.csv_timestamp.strftime("%H:%M") %>)</h4>

<% @form_answers.each do |form_answer| %>
<div class="justify-content-md-between mb-2 gx-3">
<div class="card">
<div id="<%= dom_id form_answer %>"class="card-body d-flex flex-sm-row flex-column justify-content-between border-bottom">
<div class="d-flex align-items-center">
<div>
<strong class="fs-4" >Q: <%= form_answer.question_snapshot %></strong>
<p class="mb-0">A: <%= form_answer.value %> </p>
</div>
</div>
</div>
</div>
</div>
<% end %>
<%= render partial: "organizations/shared/form_answers", collection: @form_answers, as: :form_answer %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<span><%= t(:joined) %></span>
<span><%= fosterer.created_at.strftime("%d %B, %Y") %></span>
</div>
<div class="d-flex justify-content-between pt-2">
<span><%= t(:deactivate) %></span>
<%= render "organizations/staff/shared/deactivate_toggle", user: fosterer.user %>
</div>
</div>
</div>
</div>
Loading

0 comments on commit f85f185

Please sign in to comment.