Skip to content

Upgrade to Rails 8.1 - #798

Merged
briri merged 14 commits into
v5from
rails8
Aug 13, 2026
Merged

Upgrade to Rails 8.1#798
briri merged 14 commits into
v5from
rails8

Conversation

@briri

@briri briri commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator
  • Upgrade to Rails v8.1 - fixes #270
  • Patch API auth to validate that user is still active
  • Fix issue where deleting a contributor or related work was not automatically updating the DOI landing pages #277

@briri
briri requested a review from jupiter007 July 31, 2026 21:00
return Language.sorted_by_abbreviation if Rails.env.development?

Rails.cache.fetch('languages', expires_in: 1.hour) { Language.sorted_by_abbreviation }
Rails.cache.fetch('languages', expires_in: 1.hour) { Language.sorted_by_abbreviation.to_a }

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change in Rails 8 wants items for the cache to be in standard arrays instead of ActiveRecord collection of objects

Comment thread app/models/answer.rb
has_many :notes

after_save :notify_plan_subscribers
after_commit :notify_plan_subscribers

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the after_save hook only applies to insert and update. This after_commit includes delete as well

Comment thread app/models/language.rb

def self.many?
Rails.cache.fetch([model_name, 'many?'], expires_in: 1.hour) { all.many? }
Rails.cache.fetch([model_name, 'many?'], expires_in: 1.hour) { count > 1 }

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

store a true/false boolean in the cache instead of a call to the function

@api_client = User.where(email: token[:client_id]).first
# Valid if User is active, has permission to use the API and
# the :client_secret matches the token
usr = User.where(email: token[:client_id], active: true, api_token: @client_secret).first

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were previously just looking up the user by email and not verifying that their account was still active.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the@client_secret is nil or blank, could the user still authenticate without providing a secret?

Comment thread bin/dev
# exec "./bin/rails", "server", *ARGV

# ====================================================================================
# DMP Tool custom dev script below (commented out core Rails server command above).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rails upgrades sometimes overwrite these bin/ and config/ files so I had to splice our customizations back in. I decided to add comments to help indicate what's ours versus core rails

Comment thread bin/setup

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let the upgrade overwrite our old customization of this file since we don't really use it and run inside of Docker now when running locally

Comment thread config/routes.rb
# Question Formats controller, currently just the one action
get 'question_formats/rda_api_address' => 'question_formats#rda_api_address'

resources :notes, only: %i[create update archive] do

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rails 8 did not like the non-standard archive here. It was redudant anyway with the member definition below

@jupiter007 jupiter007 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Just had a question about what happens in authentication_service.rb if @client_secret is nil. Does the authentication still happen?

@api_client = User.where(email: token[:client_id]).first
# Valid if User is active, has permission to use the API and
# the :client_secret matches the token
usr = User.where(email: token[:client_id], active: true, api_token: @client_secret).first

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the@client_secret is nil or blank, could the user still authenticate without providing a secret?

Comment thread bin/bundler-audit
@@ -0,0 +1,6 @@
#!/usr/bin/env ruby

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I wonder if it catches the same vulnerabilities as dependabot?

@briri

briri commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

If the@client_secret is nil or blank, could the user still authenticate without providing a secret?

Good question. I'd assume we want to block that, so I've added a check for nil prior to the query.

@briri
briri merged commit 7e2c69f into v5 Aug 13, 2026
0 of 8 checks passed
@briri
briri deleted the rails8 branch August 13, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants