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 ...@@ -43,15 +43,17 @@ module TokenAuthenticatable
write_attribute(token_field, token) if token write_attribute(token_field, token) if token
end end
# Returns a token, but only saves when the database is in read & write mode
define_method("ensure_#{token_field}!") do define_method("ensure_#{token_field}!") do
send("reset_#{token_field}!") if read_attribute(token_field).blank? # rubocop:disable GitlabSecurity/PublicSend send("reset_#{token_field}!") if read_attribute(token_field).blank? # rubocop:disable GitlabSecurity/PublicSend
read_attribute(token_field) read_attribute(token_field)
end end
# Resets the token, but only saves when the database is in read & write mode
define_method("reset_#{token_field}!") do define_method("reset_#{token_field}!") do
write_new_token(token_field) write_new_token(token_field)
save! save! if Gitlab::Database.read_write?
end end
end end
end end
......
...@@ -1075,8 +1075,6 @@ class User < ActiveRecord::Base ...@@ -1075,8 +1075,6 @@ class User < ActiveRecord::Base
# we do this on read since migrating all existing users is not a feasible # we do this on read since migrating all existing users is not a feasible
# solution. # solution.
def rss_token def rss_token
return read_attribute(:rss_token) if Gitlab::Database.read_only?
ensure_rss_token! ensure_rss_token!
end 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