Skip to content

Commit

Permalink
Remove dependencies on procedures (#231)
Browse files Browse the repository at this point in the history
* Bump dependencies

Don't update `ransack` until activerecord-hackery/ransack#1039 is fixed

* Fix SMS tests when ESENDEX_USERNAME env variable is present.

* Remove dependent procedures feature.

* Rubocop issue

* Added missing test.
  • Loading branch information
leio10 authored Aug 26, 2019
1 parent 6c0c567 commit 0182f4f
Show file tree
Hide file tree
Showing 23 changed files with 85 additions and 284 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ gem "rack-attack"
gem "rack-cas", require: false
gem "rails", "~> 5.2"
gem "rails-i18n"
gem "ransack", "< 2.3"
gem "rectify"
gem "rotp"
gem "sassc-rails"
Expand Down
85 changes: 45 additions & 40 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ GEM
activejob (5.2.3)
activesupport (= 5.2.3)
globalid (>= 0.3.6)
activemerchant (1.95.0)
activemerchant (1.97.0)
activesupport (>= 4.2)
builder (>= 2.1.2, < 4.0.0)
i18n (>= 0.6.9)
Expand Down Expand Up @@ -109,7 +109,7 @@ GEM
airbrake (5.8.1)
airbrake-ruby (~> 1.8)
airbrake-ruby (1.8.0)
airbrussh (1.3.2)
airbrussh (1.3.3)
sshkit (>= 1.6.1, != 1.7.0)
amq-protocol (2.3.0)
arbre (1.2.1)
Expand Down Expand Up @@ -161,10 +161,13 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (>= 2.0, < 4.0)
carrierwave (1.3.1)
activemodel (>= 4.0.0)
activesupport (>= 4.0.0)
mime-types (>= 1.16)
carrierwave (2.0.0)
activemodel (>= 5.0.0)
activesupport (>= 5.0.0)
addressable (~> 2.6)
image_processing (~> 1.1)
mimemagic (>= 0.3.0)
mini_mime (>= 0.1.3)
carrot-top (0.0.7)
json
case_transform (0.2)
Expand All @@ -184,22 +187,22 @@ GEM
deep_merge (1.2.1)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
device_detector (1.0.1)
devise (4.6.2)
device_detector (1.0.2)
devise (4.7.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 6.0)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
devise-i18n (1.8.0)
devise-i18n (1.8.1)
devise (>= 4.6)
diff-lcs (1.3)
discard (1.1.0)
activerecord (>= 4.2, < 7)
docile (1.3.2)
dotenv (2.7.4)
dotenv-rails (2.7.4)
dotenv (= 2.7.4)
dotenv (2.7.5)
dotenv-rails (2.7.5)
dotenv (= 2.7.5)
railties (>= 3.2, < 6.1)
draper (3.1.0)
actionpack (>= 5.0)
Expand All @@ -213,24 +216,24 @@ GEM
dry-container (0.7.2)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1, >= 0.1.3)
dry-core (0.4.8)
dry-core (0.4.9)
concurrent-ruby (~> 1.0)
dry-equalizer (0.2.2)
dry-inflector (0.1.2)
dry-initializer (3.0.1)
dry-logic (1.0.2)
dry-logic (1.0.3)
concurrent-ruby (~> 1.0)
dry-core (~> 0.2)
dry-equalizer (~> 0.2)
dry-schema (1.3.1)
dry-schema (1.3.3)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.8, >= 0.8.3)
dry-core (~> 0.4)
dry-equalizer (~> 0.2)
dry-initializer (~> 3.0)
dry-logic (~> 1.0)
dry-types (~> 1.0)
dry-types (1.1.0)
dry-types (1.1.1)
concurrent-ruby (~> 1.0)
dry-container (~> 0.3)
dry-core (~> 0.4, >= 0.4.4)
Expand Down Expand Up @@ -292,11 +295,14 @@ GEM
rails (~> 5.1)
regexp-examples (~> 1.3)
ice_nine (0.11.2)
inherited_resources (1.10.0)
actionpack (>= 5.0, < 6.0)
image_processing (1.9.3)
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.13, < 3)
inherited_resources (1.11.0)
actionpack (>= 5.0, < 6.1)
has_scope (~> 0.6)
railties (>= 5.0, < 6.0)
responders (~> 2.0)
railties (>= 5.0, < 6.1)
responders (>= 2, < 4)
jaro_winkler (1.5.3)
jquery-rails (4.3.5)
rails-dom-testing (>= 1, < 3)
Expand Down Expand Up @@ -341,9 +347,6 @@ GEM
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (0.9.2)
mime-types (3.2.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2019.0331)
mimemagic (0.3.3)
mini_magick (4.9.5)
mini_mime (1.0.2)
Expand All @@ -358,12 +361,12 @@ GEM
net-ssh (>= 2.6.5, < 6.0.0)
net-ssh (5.2.0)
nio4r (2.4.0)
nokogiri (1.10.3)
nokogiri (1.10.4)
mini_portile2 (~> 2.4.0)
normalizr (0.3.1)
orm_adapter (0.5.0)
paper_trail (10.3.0)
activerecord (>= 4.2, < 6.1)
paper_trail (10.3.1)
activerecord (>= 4.2)
request_store (~> 1.1)
parallel (1.17.0)
parser (2.6.3.0)
Expand All @@ -378,7 +381,7 @@ GEM
pry-rails (0.3.9)
pry (>= 0.10.4)
public_suffix (3.1.1)
puma (4.0.1)
puma (4.1.0)
nio4r (~> 2.0)
pundit (1.1.0)
activesupport (>= 3.0.0)
Expand Down Expand Up @@ -414,7 +417,7 @@ GEM
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
rails-html-sanitizer (1.2.0)
loofah (~> 2.2, >= 2.2.2)
rails-i18n (5.1.3)
i18n (>= 0.7, < 2)
Expand Down Expand Up @@ -445,9 +448,9 @@ GEM
request_store (1.4.1)
rack (>= 1.4)
require_all (1.5.0)
responders (2.4.1)
actionpack (>= 4.2.0, < 6.0)
railties (>= 4.2.0, < 6.0)
responders (3.0.0)
actionpack (>= 5.0)
railties (>= 5.0)
rotp (5.1.0)
addressable (~> 2.5)
rspec-core (3.8.2)
Expand Down Expand Up @@ -477,22 +480,23 @@ GEM
rubocop-rails (2.0.1)
rack (>= 1.1)
rubocop (>= 0.70.0)
rubocop-rspec (1.34.0)
rubocop-rspec (1.35.0)
rubocop (>= 0.60.0)
ruby-graphviz (1.2.4)
ruby-progressbar (1.10.1)
ruby-vips (2.0.14)
ffi (~> 1.9)
ruby_dep (1.5.0)
safe_yaml (1.0.5)
safely_block (0.2.1)
errbase
safely_block (0.2.2)
errbase (>= 0.1.1)
sass (3.7.4)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
sassc (2.0.1)
sassc (2.1.0)
ffi (~> 1.9)
rake
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
Expand All @@ -502,7 +506,7 @@ GEM
secure_headers (6.1.1)
select2-rails (4.0.3)
thor (~> 0.14)
sepa_king (0.11.2)
sepa_king (0.12.0)
activemodel (>= 3.1)
iban-tools
nokogiri
Expand Down Expand Up @@ -537,7 +541,7 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sshkit (1.19.1)
sshkit (1.20.0)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
symmetric-encryption (4.3.0)
Expand All @@ -559,7 +563,7 @@ GEM
equalizer (~> 0.0, >= 0.0.9)
warden (1.2.8)
rack (>= 2.0.6)
webmock (3.6.0)
webmock (3.6.2)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
Expand Down Expand Up @@ -634,6 +638,7 @@ DEPENDENCIES
rails (~> 5.2)
rails-controller-testing
rails-i18n
ransack (< 2.3)
rectify
rotp
rspec-rails
Expand Down
6 changes: 1 addition & 5 deletions app/admin/procedure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
sidebar :person, partial: "procedures/person", only: [:show]

action_item :undo_procedure, only: :show do
if procedure.full_undoable_by? controller.current_admin
if procedure.undoable_by? controller.current_admin
link_to t("census.procedures.actions.undo"), undo_procedure_path(procedure), method: :patch,
data: { confirm: t("census.messages.sure_question") },
class: "member_link"
Expand Down Expand Up @@ -89,10 +89,6 @@
end

controller do
def scoped_collection
end_of_association_chain.independent
end

def update
set_resource_ivar resource.decorate
Procedures::ProcessProcedure.call(form: form_resource, admin: current_admin) do
Expand Down
4 changes: 0 additions & 4 deletions app/commands/procedures/process_procedure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ def process(current_procedure)
current_procedure.comment = form.comment
current_procedure.send(form.action)

current_procedure.dependent_procedures.each do |child_procedure|
process child_procedure
end

if current_procedure.invalid?
@result = :invalid
raise ActiveRecord::Rollback
Expand Down
6 changes: 1 addition & 5 deletions app/commands/procedures/undo_procedure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize(procedure:, admin:)
#
# Returns nothing.
def call
return broadcast(:invalid) unless admin && procedure&.full_undoable_by?(admin)
return broadcast(:invalid) unless admin && procedure&.undoable_by?(admin)

undo_procedure

Expand All @@ -40,10 +40,6 @@ def undo_procedure
end

def undo(current_procedure)
current_procedure.dependent_procedures.each do |child_procedure|
undo child_procedure
end

current_procedure.undo
current_procedure.processed_by = current_procedure.undo_version.processed_by
current_procedure.processed_at = current_procedure.undo_version.processed_at
Expand Down
8 changes: 4 additions & 4 deletions app/decorators/concerns/person_associations_decorations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ module PersonAssociationsDecorations
extend ActiveSupport::Concern

included do
def independent_procedures
@independent_procedures ||= PersonIndependentProcedures.for(object).decorate(context: context)
def procedures
@procedures ||= PersonProcedures.for(object).decorate(context: context)
end

def last_procedures
@last_procedures ||= PersonLastIndependentProcedures.for(object).decorate(context: context)
@last_procedures ||= PersonLastProcedures.for(object).decorate(context: context)
end

def count_procedures
@count_procedures ||= independent_procedures.count
@count_procedures ||= procedures.count
end

def last_orders
Expand Down
1 change: 0 additions & 1 deletion app/decorators/procedure_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class ProcedureDecorator < ApplicationDecorator
delegate_all

attr_accessor :event
decorates_association :dependent_procedures
decorates_association :issues
decorates_association :person
decorates_association :processed_by
Expand Down
20 changes: 4 additions & 16 deletions app/models/concerns/procedure_states.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,15 @@ def permitted_events(processor)

def permitted_event?(event, processor)
case event.to_s
when "accept" then full_acceptable_by?(processor)
when "undo" then full_undoable_by?(processor)
when "accept" then acceptable_by?(processor)
when "undo" then undoable_by?(processor)
else
true
end
end

def full_acceptable_by?(processor)
return false unless processor&.person_id != person_id && acceptable?

process_accept
ret = dependent_procedures.all? do |dependent_procedure|
dependent_procedure.person = person # synchronize child person status with parent person
dependent_procedure.full_acceptable_by? processor
end
undo_accept
ret
end

def full_undoable_by?(processor)
undoable_by?(processor) && dependent_procedures.all? { |dependent_procedure| dependent_procedure.full_undoable_by? processor }
def acceptable_by?(processor)
processor&.person_id != person_id && acceptable?
end
end
end
13 changes: 0 additions & 13 deletions app/models/procedure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,16 @@ class Procedure < ApplicationRecord

belongs_to :person
belongs_to :processed_by, class_name: "Admin", optional: true
belongs_to :depends_on, class_name: "Procedure", optional: true
belongs_to :person_location, optional: true

has_paper_trail versions: { class_name: "Version" }, skip: [:fast_filter]

has_many :versions, as: :item, dependent: :destroy, inverse_of: :item
has_many :dependent_procedures,
foreign_key: "depends_on_id",
class_name: "Procedure",
dependent: :restrict_with_exception,
inverse_of: :depends_on
has_many :attachments, dependent: :destroy

scope :independent, -> { where depends_on: nil }

validates :comment, presence: { message: I18n.t("errors.messages.procedure_denial_comment_required") }, if: :rejected?
validates :processed_at, presence: true, if: :processed?
validate :processed_by, :processed_by_different_from_person
validate :depends_on, :depends_on_person

def process_reject; end

Expand Down Expand Up @@ -71,8 +62,4 @@ def self.policy_class
def processed_by_different_from_person
errors.add(:processed_by_id, :processed_by_person) if processed_by&.person == person
end

def depends_on_person
errors.add(:depends_on_id, :depends_on_different_person) unless depends_on.nil? || depends_on.person == person
end
end
Loading

0 comments on commit 0182f4f

Please sign in to comment.