Skip to content

Commit

Permalink
Merge branch 'main' into jose
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanxu committed Aug 18, 2023
2 parents 352c5cd + 1a49c24 commit 8a257ed
Show file tree
Hide file tree
Showing 17 changed files with 453 additions and 171 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ gem 'google_drive'
gem 'groupdate'
gem 'honeybadger', '~> 5.2.0'
gem 'html-pipeline', '~> 2.14.3'
gem 'commonmarker', '~> 0.23.8'
gem 'commonmarker', '~> 0.23.10'
gem 'net-sftp', '~> 4.0'
gem 'octicons_helper'
gem 'omniauth-orcid', '~> 2.1.1'
Expand All @@ -18,7 +18,7 @@ gem 'octokit', '~> 6.0'
gem 'pdf-reader', '~> 2.11.0'
gem 'pg', '~> 1.4.6'
gem 'pagy'
gem 'rails', '7.0.6'
gem 'rails', '7.0.7'
gem "importmap-rails"
gem "turbo-rails"
gem "stimulus-rails"
Expand Down
132 changes: 66 additions & 66 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,70 @@ GEM
Ascii85 (1.1.0)
aasm (5.5.0)
concurrent-ruby (~> 1.0)
actioncable (7.0.6)
actionpack (= 7.0.6)
activesupport (= 7.0.6)
actioncable (7.0.7)
actionpack (= 7.0.7)
activesupport (= 7.0.7)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (7.0.6)
actionpack (= 7.0.6)
activejob (= 7.0.6)
activerecord (= 7.0.6)
activestorage (= 7.0.6)
activesupport (= 7.0.6)
actionmailbox (7.0.7)
actionpack (= 7.0.7)
activejob (= 7.0.7)
activerecord (= 7.0.7)
activestorage (= 7.0.7)
activesupport (= 7.0.7)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.0.6)
actionpack (= 7.0.6)
actionview (= 7.0.6)
activejob (= 7.0.6)
activesupport (= 7.0.6)
actionmailer (7.0.7)
actionpack (= 7.0.7)
actionview (= 7.0.7)
activejob (= 7.0.7)
activesupport (= 7.0.7)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (7.0.6)
actionview (= 7.0.6)
activesupport (= 7.0.6)
actionpack (7.0.7)
actionview (= 7.0.7)
activesupport (= 7.0.7)
rack (~> 2.0, >= 2.2.4)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (7.0.6)
actionpack (= 7.0.6)
activerecord (= 7.0.6)
activestorage (= 7.0.6)
activesupport (= 7.0.6)
actiontext (7.0.7)
actionpack (= 7.0.7)
activerecord (= 7.0.7)
activestorage (= 7.0.7)
activesupport (= 7.0.7)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.0.6)
activesupport (= 7.0.6)
actionview (7.0.7)
activesupport (= 7.0.7)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
active_link_to (1.0.5)
actionpack
addressable
activejob (7.0.6)
activesupport (= 7.0.6)
activejob (7.0.7)
activesupport (= 7.0.7)
globalid (>= 0.3.6)
activemodel (7.0.6)
activesupport (= 7.0.6)
activerecord (7.0.6)
activemodel (= 7.0.6)
activesupport (= 7.0.6)
activestorage (7.0.6)
actionpack (= 7.0.6)
activejob (= 7.0.6)
activerecord (= 7.0.6)
activesupport (= 7.0.6)
activemodel (7.0.7)
activesupport (= 7.0.7)
activerecord (7.0.7)
activemodel (= 7.0.7)
activesupport (= 7.0.7)
activestorage (7.0.7)
actionpack (= 7.0.7)
activejob (= 7.0.7)
activerecord (= 7.0.7)
activesupport (= 7.0.7)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (7.0.6)
activesupport (7.0.7)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
Expand All @@ -91,7 +91,7 @@ GEM
xpath (~> 3.2)
chartkick (5.0.2)
coderay (1.1.3)
commonmarker (0.23.9)
commonmarker (0.23.10)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
crack (0.4.5)
Expand Down Expand Up @@ -204,16 +204,16 @@ GEM
matrix (0.4.2)
memoist (0.16.2)
method_source (1.0.0)
mini_mime (1.1.2)
mini_mime (1.1.5)
mini_portile2 (2.8.4)
mini_racer (0.8.0)
libv8-node (~> 18.16.0.0)
minitest (5.18.1)
minitest (5.19.0)
msgpack (1.7.2)
multi_json (1.15.0)
multi_xml (0.6.0)
multipart-post (2.3.0)
net-imap (0.3.6)
net-imap (0.3.7)
date
net-protocol
net-pop (0.1.2)
Expand All @@ -227,12 +227,12 @@ GEM
net-ssh (7.1.0)
newrelic_rpm (9.3.1)
nio4r (2.5.9)
nokogiri (1.15.3)
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.15.3-x86_64-darwin)
nokogiri (1.15.4-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.15.3-x86_64-linux)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
oauth2 (2.0.9)
faraday (>= 0.17.3, < 3.0)
Expand Down Expand Up @@ -282,39 +282,39 @@ GEM
puma (6.3.0)
nio4r (~> 2.0)
racc (1.7.1)
rack (2.2.7)
rack (2.2.8)
rack-protection (3.0.6)
rack
rack-test (2.1.0)
rack (>= 1.3)
rails (7.0.6)
actioncable (= 7.0.6)
actionmailbox (= 7.0.6)
actionmailer (= 7.0.6)
actionpack (= 7.0.6)
actiontext (= 7.0.6)
actionview (= 7.0.6)
activejob (= 7.0.6)
activemodel (= 7.0.6)
activerecord (= 7.0.6)
activestorage (= 7.0.6)
activesupport (= 7.0.6)
rails (7.0.7)
actioncable (= 7.0.7)
actionmailbox (= 7.0.7)
actionmailer (= 7.0.7)
actionpack (= 7.0.7)
actiontext (= 7.0.7)
actionview (= 7.0.7)
activejob (= 7.0.7)
activemodel (= 7.0.7)
activerecord (= 7.0.7)
activestorage (= 7.0.7)
activesupport (= 7.0.7)
bundler (>= 1.15.0)
railties (= 7.0.6)
railties (= 7.0.7)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
activesupport (>= 5.0.1.rc1)
rails-dom-testing (2.1.1)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.0.6)
actionpack (= 7.0.6)
activesupport (= 7.0.6)
railties (7.0.7)
actionpack (= 7.0.7)
activesupport (= 7.0.7)
method_source
rake (>= 12.2)
thor (~> 1.0)
Expand Down Expand Up @@ -423,12 +423,12 @@ GEM
hashdiff (>= 0.4.0, < 2.0.0)
webrick (1.8.1)
websocket (1.2.9)
websocket-driver (0.7.5)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.8)
zeitwerk (2.6.11)

PLATFORMS
ruby
Expand All @@ -441,7 +441,7 @@ DEPENDENCIES
bootsnap
capybara (~> 3.38)
chartkick
commonmarker (~> 0.23.8)
commonmarker (~> 0.23.10)
dotenv (~> 2.8.1)
elasticsearch (< 7.14)
factory_bot_rails (~> 6.2.0)
Expand All @@ -464,7 +464,7 @@ DEPENDENCIES
pg (~> 1.4.6)
pry-byebug
puma
rails (= 7.0.6)
rails (= 7.0.7)
rails-controller-testing (~> 1.0.5)
redis (~> 5.0)
responders
Expand Down
49 changes: 49 additions & 0 deletions app/controllers/dispatch_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,53 @@ def api_deposit
head :forbidden
end
end

def api_retract
if params[:secret] == ENV['BOT_SECRET']
paper = Paper.find_by_doi!(params[:doi])
return head :unprocessable_entity if paper.retracted?

if params[:metadata]
metadata = JSON.parse(Base64.decode64(params[:metadata]))
else
metadata = {}
end

retraction_paper = Paper.new
retraction_paper.doi = metadata[:doi] || "#{paper.doi}R"
retraction_paper.retraction_for_id = paper.id
retraction_paper.title = metadata[:title] || "Retraction notice for: #{paper.title}"
retraction_paper.body = "Retraction notice for: #{paper.title}"
retraction_paper.authors = "Editorial Board"
retraction_paper.repository_url = paper.repository_url
retraction_paper.software_version = paper.software_version
retraction_paper.track_id = paper.track_id
retraction_paper.citation_string = params[:citation_string]
retraction_paper.submission_kind = "new"
retraction_paper.state = "accepted"
retraction_paper.metadata = metadata
retraction_paper.accepted_at = Time.now
retraction_paper.review_issue_id = paper.review_issue_id

if paper.track.nil?
submitting_author = Editor.includes(:user).board.select {|e| e.user.present? }.first.user
else
submitting_author = paper.track.aeics.select {|e| e.user.present? }.first.user
end
submitting_author = User.where(admin: true).first if submitting_author.nil?

retraction_paper.submitting_author = submitting_author

if retraction_paper.save! && retraction_paper.accept!
paper.update(retraction_notice: params[:retraction_notice]) if params[:retraction_notice].present?
paper.retract!
render json: retraction_paper.to_json, status: '201'
else
head :unprocessable_entity
end
else
head :forbidden
end
end

end
32 changes: 27 additions & 5 deletions app/models/paper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ class Paper < ApplicationRecord
optional: true,
foreign_key: "eic_id"

belongs_to :retracted_paper,
class_name: 'Paper',
optional: true,
foreign_key: "retraction_for_id"

has_one :retraction_paper,
class_name: 'Paper',
foreign_key: "retraction_for_id",
inverse_of: :retracted_paper

has_many :invitations
has_many :notes
has_many :votes
Expand Down Expand Up @@ -62,6 +72,10 @@ class Paper < ApplicationRecord
event :withdraw do
transitions to: :withdrawn
end

event :retract do
transitions to: :retracted
end
end

VISIBLE_STATES = [
Expand Down Expand Up @@ -128,14 +142,14 @@ class Paper < ApplicationRecord
validates_presence_of :track_id, on: :create, message: "You must select a valid subject for the paper", if: Proc.new { JournalFeatures.tracks? }
validates :kind, inclusion: { in: Rails.application.settings["paper_types"] }, allow_nil: true
validates :submission_kind, inclusion: { in: SUBMISSION_KINDS, message: "You must select a submission type" }, allow_nil: false
validate :check_repository_address, on: :create
validate :check_repository_address, on: :create, unless: Proc.new {|paper| paper.is_a_retraction_notice?}

def notify_editors
Notifications.submission_email(self).deliver_now
Notifications.submission_email(self).deliver_now unless self.is_a_retraction_notice?
end

def notify_author
Notifications.author_submission_email(self).deliver_now
Notifications.author_submission_email(self).deliver_now unless self.is_a_retraction_notice?
end

# Only index papers that are visible
Expand Down Expand Up @@ -172,6 +186,10 @@ def published?
accepted? || retracted?
end

def is_a_retraction_notice?
retraction_for_id.present?
end

def invite_editor(editor_handle)
return false unless editor = Editor.find_by_login(editor_handle)
Notifications.editor_invite_email(self, editor).deliver_now
Expand Down Expand Up @@ -296,8 +314,12 @@ def archive_doi_url

# A 5-figure integer used to produce the JOSS DOI
def joss_id
id = "%05d" % review_issue_id
"#{setting(:abbreviation).downcase}.#{id}"
if self.is_a_retraction_notice?
return retracted_paper.joss_id + "R"
else
id = "%05d" % review_issue_id
return "#{setting(:abbreviation).downcase}.#{id}"
end
end

# This URL returns the 'DOI optimized' representation of a URL for a paper
Expand Down
Loading

0 comments on commit 8a257ed

Please sign in to comment.