Commit a723b559 authored by Toon Claes's avatar Toon Claes

Move Gitlab::Database.read_write? check to TokenAuthenticatable

Instead of checking it in the User model, move it as deep as possible
to avoid future mistakes.
parent 1f971686
......@@ -43,15 +43,17 @@ module TokenAuthenticatable
write_attribute(token_field, token) if token
end
# Returns a token, but only saves when the database is in read & write mode
define_method("ensure_#{token_field}!") do
send("reset_#{token_field}!") if read_attribute(token_field).blank? # rubocop:disable GitlabSecurity/PublicSend
read_attribute(token_field)
end
# Resets the token, but only saves when the database is in read & write mode
define_method("reset_#{token_field}!") do
write_new_token(token_field)
save!
save! if Gitlab::Database.read_write?
end
end
end
......
......@@ -1075,8 +1075,6 @@ class User < ActiveRecord::Base
# we do this on read since migrating all existing users is not a feasible
# solution.
def rss_token
return read_attribute(:rss_token) if Gitlab::Database.read_only?
ensure_rss_token!
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment