Skip to content

Commit

Permalink
Merge branch 'main' into 4217-kit-various-refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyli97 committed Oct 18, 2024
2 parents 51f0585 + 64d20c1 commit 0cfc8de
Show file tree
Hide file tree
Showing 58 changed files with 1,759 additions and 234 deletions.
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ Make sure to install **Ubuntu** as your Linux distribution. (This should be defa
Waiting Approval Partner
Email: [email protected]
Password: password!
Another approved partner (with all groups):
Email: [email protected]
Pasword: password!
```
</details>

Expand Down
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,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 @@ -199,7 +199,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 All @@ -215,6 +215,6 @@ if %w(mingw mswin x64_mingw jruby).include?(RUBY_PLATFORM)
end

# Use Redis for Action Cable
gem "redis", "~> 5.2"
gem "redis", "~> 5.3"

gem "importmap-rails", "~> 2.0"
69 changes: 33 additions & 36 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,8 +481,8 @@ GEM
pry (~> 0.13)
psych (5.1.2)
stringio
public_suffix (5.1.0)
puma (6.4.2)
public_suffix (6.0.1)
puma (6.4.3)
nio4r (~> 2.0)
racc (1.8.1)
rack (2.2.9)
Expand Down Expand Up @@ -541,38 +541,37 @@ GEM
rdoc (6.7.0)
psych (>= 4.0.0)
recaptcha (5.17.0)
redis (5.2.0)
redis (5.3.0)
redis-client (>= 0.22.0)
redis-client (0.22.1)
redis-client (0.22.2)
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 @@ -781,9 +778,9 @@ DEPENDENCIES
rails-controller-testing
rails-erd
recaptcha
redis (~> 5.2)
redis (~> 5.3)
rolify (~> 6.0)
rspec-rails (~> 6.1.4)
rspec-rails (~> 7.0.1)
rubocop
rubocop-performance
rubocop-rails (~> 2.25.1)
Expand All @@ -798,7 +795,7 @@ DEPENDENCIES
terser
turbo-rails
web-console
webmock (~> 3.23)
webmock (~> 3.24)

BUNDLED WITH
2.5.19
2.5.21
11 changes: 9 additions & 2 deletions app/controllers/partner_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class PartnerGroupsController < ApplicationController

def new
@partner_group = current_organization.partner_groups.new
@item_categories = current_organization.item_categories
set_items_categories
end

def create
Expand All @@ -13,12 +13,14 @@ def create
redirect_to partners_path + "#nav-partner-groups", notice: "Partner group added!"
else
flash[:error] = "Something didn't work quite right -- try again?"
set_items_categories
render action: :new
end
end

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

def update
Expand All @@ -27,6 +29,7 @@ def update
redirect_to partners_path + "#nav-partner-groups", notice: "Partner group edited!"
else
flash[:error] = "Something didn't work quite right -- try again?"
set_items_categories
render action: :edit
end
end
Expand All @@ -51,4 +54,8 @@ def set_partner_group
def partner_group_params
params.require(:partner_group).permit(:name, :send_reminders, :deadline_day, :reminder_day, item_category_ids: [])
end

def set_items_categories
@item_categories = current_organization.item_categories
end
end
2 changes: 1 addition & 1 deletion app/controllers/partners/family_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def build_family_requests_attributes(params)
end
end

children = current_partner.children.active.where(id: children_ids).joins(:requested_items).select('children.*', :item_id)
children = current_partner.children.where(id: children_ids).joins(:requested_items).select('children.*', :item_id)

children_grouped_by_item_id = children.group_by(&:item_id)
children_grouped_by_item_id.map do |item_id, item_requested_children|
Expand Down
20 changes: 19 additions & 1 deletion app/controllers/requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def index
.undiscarded
.during(helpers.selected_range)
.class_filter(filter_params)

@unfulfilled_requests_count = current_organization.requests.where(status: [:pending, :started]).count
@paginated_requests = @requests.page(params[:page])
@calculate_product_totals = RequestsTotalItemsService.new(requests: @requests).calculate
@items = current_organization.items.alphabetized
Expand Down Expand Up @@ -40,6 +40,24 @@ def start
redirect_to new_distribution_path(request_id: request.id)
end

def print_unfulfilled
requests = current_organization
.requests
.includes(:item_requests, partner: [:profile])
.where(status: [:pending, :started])
.order(created_at: :desc)

respond_to do |format|
format.any do
pdf = PicklistsPdf.new(current_organization, requests)
send_data pdf.compute_and_render,
filename: format("Picklists_%s.pdf", Time.current.to_fs(:long)),
type: "application/pdf",
disposition: "inline"
end
end
end

private

def load_items
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
13 changes: 13 additions & 0 deletions app/javascript/controllers/password_visibility_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
static targets = ["password", "icon"];

toggle() {
const isPasswordVisible = this.passwordTarget.type === "text";

this.passwordTarget.type = isPasswordVisible ? "password" : "text";
this.iconTarget.classList.toggle("fa-eye", !isPasswordVisible);
this.iconTarget.classList.toggle("fa-eye-slash", isPasswordVisible);
}
}
3 changes: 0 additions & 3 deletions app/models/concerns/provideable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ module Provideable
included do
belongs_to :organization # Automatically validates presence as of Rails 5

validates :contact_name, presence: { message: "Must provide a name or a business name" }, if: proc { |ddp| ddp.business_name.blank? }
validates :business_name, presence: { message: "Must provide a name or a business name" }, if: proc { |ddp| ddp.contact_name.blank? }

scope :for_csv_export, ->(organization, *) {
where(organization: organization).order(:business_name)
}
Expand Down
2 changes: 2 additions & 0 deletions app/models/product_drive_participant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class ProductDriveParticipant < ApplicationRecord

validates :phone, presence: { message: "Must provide a phone or an e-mail" }, if: proc { |pdp| pdp.email.blank? }
validates :email, presence: { message: "Must provide a phone or an e-mail" }, if: proc { |pdp| pdp.phone.blank? }
validates :contact_name, presence: { message: "Must provide a name or a business name" }, if: proc { |pdp| pdp.business_name.blank? }
validates :business_name, presence: { message: "Must provide a name or a business name" }, if: proc { |pdp| pdp.contact_name.blank? }
validates :comment, length: { maximum: 500 }

scope :alphabetized, -> { order(:contact_name) }
Expand Down
2 changes: 2 additions & 0 deletions app/models/vendor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Vendor < ApplicationRecord

has_many :purchases, inverse_of: :vendor, dependent: :destroy

validates :business_name, presence: true

scope :alphabetized, -> { order(:business_name) }

def volume
Expand Down
Loading

0 comments on commit 0cfc8de

Please sign in to comment.