Skip to content

Commit

Permalink
Close #145
Browse files Browse the repository at this point in the history
  • Loading branch information
lmrodriguezr committed Jan 5, 2024
1 parent a432458 commit 3cdaf9e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/models/name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Name < ApplicationRecord
belongs_to(:register, optional: true)
belongs_to(:tutorial, optional: true)

before_save(:harmonize_register_and_status)
before_validation(:standardize_etymology)
before_validation(:prevent_self_parent)
before_validation(:monitor_name_changes)
Expand Down Expand Up @@ -870,4 +871,8 @@ def monitor_name_changes
self.name.strip!
self.name.gsub!(/\s+/, ' ')
end

def harmonize_register_and_status
self.status = 5 if !register && in_curation?
end
end
6 changes: 5 additions & 1 deletion app/models/name/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ def after_endorsement_or_notification?
end

def after_validation?
valid?
validated?
end

def after_register_publication?
register.try(:published?)
end

def in_curation?
after_submission? && !validated?
end

# ============ --- CHANGE STATUS --- ============

##
Expand Down
5 changes: 5 additions & 0 deletions app/models/register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Register < ApplicationRecord

before_create(:assign_accession)
before_validation(:propose_and_save_title, if: :submitted?)
before_destroy(:return_names_to_draft)

validates(:publication_id, presence: true, if: :validated?)
validates(:publication_pdf, presence: true, if: :validated?)
Expand Down Expand Up @@ -278,4 +279,8 @@ def title_different_from_effective_publication
def propose_and_save_title
self.title = propose_title unless title?
end

def return_names_to_draft
names.each { |name| name.update(status: 5) if name.in_curation? }
end
end

0 comments on commit 3cdaf9e

Please sign in to comment.