Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into 4473-expand-reminder-date-possibilities
  • Loading branch information
jlandiseigsti committed Oct 2, 2024
2 parents a14719c + f0a9d72 commit bc9746d
Show file tree
Hide file tree
Showing 55 changed files with 906 additions and 76 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ group :development, :test do
# Debugger which supports rdbg and Shopify Ruby LSP VSCode extension
gem "debug", ">= 1.0.0"
# RSpec behavioral testing framework for Rails.
gem "rspec-rails", "~> 6.1.4"
gem "rspec-rails", "~> 7.0.1"
# Static analysis / linter.
gem "rubocop"
# Rails add-on for static analysis.
Expand Down Expand Up @@ -201,7 +201,7 @@ group :test do
# More concise test ("should") matchers
gem 'shoulda-matchers', '~> 6.2'
# Mock HTTP requests and ensure they are not called during tests.
gem "webmock", "~> 3.23"
gem "webmock", "~> 3.24"
# Interface capybara to chrome headless
gem "cuprite"
# Read PDF files for tests
Expand Down
61 changes: 29 additions & 32 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ GEM
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
afm (0.2.2)
annotate (3.2.0)
activerecord (>= 3.2, < 8.0)
Expand Down Expand Up @@ -185,9 +185,9 @@ GEM
discard (1.3.0)
activerecord (>= 4.2, < 8)
docile (1.4.0)
dotenv (3.1.2)
dotenv-rails (3.1.2)
dotenv (= 3.1.2)
dotenv (3.1.4)
dotenv-rails (3.1.4)
dotenv (= 3.1.4)
railties (>= 6.1)
drb (2.2.1)
dry-core (1.0.1)
Expand Down Expand Up @@ -225,7 +225,7 @@ GEM
railties (>= 5.0.0)
faker (3.4.2)
i18n (>= 1.8.11, < 2)
faraday (1.10.3)
faraday (1.10.4)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
Expand Down Expand Up @@ -294,14 +294,14 @@ GEM
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
hashdiff (1.1.0)
hashdiff (1.1.1)
hashery (2.1.2)
hashie (5.0.0)
httparty (0.22.0)
csv
mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2)
i18n (1.14.5)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
icalendar (2.10.2)
ice_cube (~> 0.16)
Expand All @@ -315,14 +315,14 @@ GEM
activesupport (>= 6.0.0)
railties (>= 6.0.0)
io-console (0.7.2)
irb (1.14.0)
irb (1.14.1)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
jbuilder (2.12.0)
jbuilder (2.13.0)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
json (2.7.2)
jwt (2.8.2)
jwt (2.9.1)
base64
kaminari (1.2.2)
activesupport (>= 4.1.0)
Expand Down Expand Up @@ -423,8 +423,8 @@ GEM
hashie (>= 3.4.6)
rack (>= 2.2.3)
rack-protection
omniauth-google-oauth2 (1.1.3)
jwt (>= 2.0)
omniauth-google-oauth2 (1.2.0)
jwt (>= 2.9)
oauth2 (~> 2.0)
omniauth (~> 2.0)
omniauth-oauth2 (~> 1.8)
Expand Down Expand Up @@ -481,7 +481,7 @@ GEM
pry (~> 0.13)
psych (5.1.2)
stringio
public_suffix (5.1.0)
public_suffix (6.0.1)
puma (6.4.2)
nio4r (~> 2.0)
racc (1.8.1)
Expand Down Expand Up @@ -546,33 +546,32 @@ GEM
redis-client (0.22.1)
connection_pool
regexp_parser (2.9.2)
reline (0.5.9)
reline (0.5.10)
io-console (~> 0.5)
request_store (1.5.1)
rack (>= 1.4)
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.3.6)
strscan
rexml (3.3.8)
rolify (6.0.1)
rouge (4.1.2)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.0)
rspec-core (3.13.1)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.2)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-rails (6.1.4)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
rspec-rails (7.0.1)
actionpack (>= 7.0)
activesupport (>= 7.0)
railties (>= 7.0)
rspec-core (~> 3.13)
rspec-expectations (~> 3.13)
rspec-mocks (~> 3.13)
Expand Down Expand Up @@ -666,16 +665,14 @@ GEM
stringio (3.1.1)
strong_migrations (1.8.0)
activerecord (>= 5.2)
strscan (3.1.0)
terser (1.2.3)
execjs (>= 0.3.0, < 3)
thor (1.3.2)
tilt (2.2.0)
timeout (0.4.1)
ttfunk (1.7.0)
turbo-rails (2.0.6)
turbo-rails (2.0.10)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
Expand All @@ -689,18 +686,18 @@ GEM
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
webmock (3.23.1)
webmock (3.24.0)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
webrick (1.8.1)
webrick (1.8.2)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
yard (0.9.34)
zeitwerk (2.6.17)
zeitwerk (2.6.18)

PLATFORMS
arm64-darwin-20
Expand Down Expand Up @@ -784,7 +781,7 @@ DEPENDENCIES
recaptcha
redis (~> 5.2)
rolify (~> 6.0)
rspec-rails (~> 6.1.4)
rspec-rails (~> 7.0.1)
rubocop
rubocop-performance
rubocop-rails (~> 2.25.1)
Expand All @@ -799,7 +796,7 @@ DEPENDENCIES
terser
turbo-rails
web-console
webmock (~> 3.23)
webmock (~> 3.24)

BUNDLED WITH
2.5.16
2.5.20
17 changes: 17 additions & 0 deletions app/controllers/partner_groups_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class PartnerGroupsController < ApplicationController
before_action :set_partner_group, only: %i[edit destroy]

def new
@partner_group = current_organization.partner_groups.new
@item_categories = current_organization.item_categories
Expand Down Expand Up @@ -31,8 +33,23 @@ def update
end
end

def destroy
if @partner_group.partners.any?
redirect_to partners_path + "#nav-partner-groups", alert: "Partner Group cannot be deleted."
else
@partner_group.destroy
respond_to do |format|
format.html { redirect_to partners_path + "#nav-partner-groups", notice: "Partner Group was successfully deleted." }
end
end
end

private

def set_partner_group
@partner_group = current_organization.partner_groups.find(params[:id])
end

def partner_group_params
params.require(:partner_group).permit(:name, :send_reminders, :reminder_schedule,
:deadline_day, :by_month_or_week, :day_of_month, :day_of_week, :every_nth_day, item_category_ids: [])
Expand Down
8 changes: 6 additions & 2 deletions app/events/inventory_aggregate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def on(*event_types, &block)
# @param event_time [DateTime]
# @param validate [Boolean]
# @return [EventTypes::Inventory]
# This method can take a block so that you can build up the history of a particular item over
# time, for instance
def inventory_for(organization_id, event_time: nil, validate: false)
last_snapshot = Event.most_recent_snapshot(organization_id)

Expand All @@ -35,11 +37,13 @@ def inventory_for(organization_id, event_time: nil, validate: false)
# don't do grouping for UpdateExistingEvents
if event_batch.any? { |e| e.is_a?(UpdateExistingEvent) }
handle(last_grouped_event, inventory, validate: validate)
yield last_grouped_event, inventory if block_given?
next
end
previous_event = event_hash[last_grouped_event.eventable]
event_hash[last_grouped_event.eventable] = last_grouped_event
previous_event = event_hash[[last_grouped_event.eventable_type, last_grouped_event.eventable_id]]
event_hash[[last_grouped_event.eventable_type, last_grouped_event.eventable_id]] = last_grouped_event
handle(last_grouped_event, inventory, validate: validate, previous_event: previous_event)
yield last_grouped_event, inventory if block_given?
end
inventory
end
Expand Down
3 changes: 3 additions & 0 deletions app/javascript/controllers/confirmation_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ export default class extends Controller {
}

submitForm() {
$(this.modalTarget).find('#modalClose').prop('disabled', true);
$(this.modalTarget).find('#modalYes').prop('disabled', true);
$(this.modalTarget).find('#modalNo').prop('disabled', true);
$(this.modalTarget).modal("hide");
this.formTarget.requestSubmit();
}
Expand Down
6 changes: 5 additions & 1 deletion app/mailers/distribution_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ def partner_mailer(current_organization, distribution, subject, distribution_cha
pdf = DistributionPdf.new(current_organization, @distribution).compute_and_render
attachments[format("%s %s.pdf", @partner.name, @distribution.created_at.strftime("%Y-%m-%d"))] = pdf
cc = [@partner.email]
cc.push(@partner.profile&.pick_up_email) if distribution.pick_up?
if distribution.pick_up? && @partner.profile&.pick_up_email
pick_up_emails = @partner.profile.split_pick_up_emails
cc.push(pick_up_emails)
end
cc.flatten!
cc.compact!
cc.uniq!

Expand Down
4 changes: 4 additions & 0 deletions app/models/donation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ def storage_view
storage_location.nil? ? "N/A" : storage_location.name
end

def in_kind_value_money
Money.new(value_per_itemizable)
end

private

def combine_duplicates
Expand Down
2 changes: 1 addition & 1 deletion app/models/partner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Partner < ApplicationRecord
validates :email, presence: true, uniqueness: { case_sensitive: false },
format: { with: URI::MailTo::EMAIL_REGEXP, on: :create }

validates :quota, numericality: true, allow_blank: true
validates :quota, numericality: { greater_than_or_equal_to: 0 }, allow_blank: true

validate :correct_document_mime_type

Expand Down
24 changes: 24 additions & 0 deletions app/models/partners/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class Profile < Base

validate :client_share_is_0_or_100
validate :has_at_least_one_request_setting
validate :pick_up_email_addresses

self.ignored_columns = %w[
evidence_based_description
Expand All @@ -118,6 +119,12 @@ def client_share_total
served_areas.map(&:client_share).compact.sum
end

def split_pick_up_emails
return nil if pick_up_email.nil?

pick_up_email.split(/,|\s+/).compact_blank
end

private

def check_social_media
Expand All @@ -144,5 +151,22 @@ def has_at_least_one_request_setting
errors.add(:base, "At least one request type must be set")
end
end

def pick_up_email_addresses
# pick_up_email is a string of comma-separated emails, check specs for details
return if pick_up_email.nil?

emails = split_pick_up_emails
if emails.size > 3
errors.add(:pick_up_email, "There can't be more than three pick up email addresses.")
nil
end
if emails.uniq.size != emails.size
errors.add(:pick_up_email, "There should not be repeated email addresses.")
end
emails.each do |e|
errors.add(:pick_up_email, "Invalid email address for '#{e}'.") unless e.match? URI::MailTo::EMAIL_REGEXP
end
end
end
end
3 changes: 3 additions & 0 deletions app/services/exports/export_donations_csv_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def base_table
"Variety of Items" => ->(donation) {
donation.line_items.map(&:name).uniq.size
},
"In-Kind Value" => ->(donation) {
donation.in_kind_value_money
},
"Comments" => ->(donation) {
donation.comment
}
Expand Down
6 changes: 3 additions & 3 deletions app/views/distributions/validate.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Distribution Confirmation</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
<button id="modalClose" type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" style="max-height: 60vh; overflow-y: auto;">
<p class="lead">You are about to create a distribution for
Expand Down Expand Up @@ -35,8 +35,8 @@
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" aria-label="No I need to make changes">No, I need to make changes</button>
<button type="button" class="btn btn-primary" data-action="confirmation#submitForm">Yes, it's correct</button>
<button id="modalNo" type="button" class="btn btn-secondary" data-bs-dismiss="modal" aria-label="No I need to make changes">No, I need to make changes</button>
<button id="modalYes" type="button" class="btn btn-success" data-action="confirmation#submitForm">Yes, it's correct</button>
</div>
</div>
</div>
3 changes: 2 additions & 1 deletion app/views/partners/_partner_groups_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@
<span class='text-gray-600 text-bold font-italic'>No</span>
<% end %>
</td>
<td class="text-right">
<td class="text-left">
<%= edit_button_to edit_partner_group_path(pg) %>
<%= delete_button_to(partner_group_path(pg),{confirm: confirm_delete_msg(pg.name)}) if pg.partners.none? %>
</td>
</tr>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/partners/profiles/edit/_pick_up_person.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="card-body">
<%= form.input :pick_up_name, label: "Pick Up Person Name", class: "form-control", wrapper: :input_group %>
<%= form.input :pick_up_phone, label: "Pick Up Person's Phone #", class: "form-control", wrapper: :input_group %>
<%= form.input :pick_up_email, label: "Pick Up Person's Email", class: "form-control", wrapper: :input_group %>
<%= form.input :pick_up_email, label: "Pick Up Person's Email (comma-separated if multiple addresses)", placeholder: "example1@org.com, example2@org.com", class: "form-control", wrapper: :input_group %>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit bc9746d

Please sign in to comment.