mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-20 03:25:17 +01:00
Change default role_id
to -99
This commit is contained in:
parent
a50c8e951f
commit
010c33db43
@ -36,7 +36,7 @@
|
|||||||
# sign_in_token_sent_at :datetime
|
# sign_in_token_sent_at :datetime
|
||||||
# webauthn_id :string
|
# webauthn_id :string
|
||||||
# sign_up_ip :inet
|
# sign_up_ip :inet
|
||||||
# role_id :bigint(8)
|
# role_id :bigint(8) default(-99)
|
||||||
# settings :text
|
# settings :text
|
||||||
# time_zone :string
|
# time_zone :string
|
||||||
# otp_secret :string
|
# otp_secret :string
|
||||||
@ -129,6 +129,7 @@ class User < ApplicationRecord
|
|||||||
before_validation :sanitize_role
|
before_validation :sanitize_role
|
||||||
before_create :set_approved
|
before_create :set_approved
|
||||||
after_commit :send_pending_devise_notifications
|
after_commit :send_pending_devise_notifications
|
||||||
|
after_find :set_role_id
|
||||||
after_create_commit :trigger_webhooks
|
after_create_commit :trigger_webhooks
|
||||||
|
|
||||||
normalizes :locale, with: ->(locale) { I18n.available_locales.exclude?(locale.to_sym) ? nil : locale }
|
normalizes :locale, with: ->(locale) { I18n.available_locales.exclude?(locale.to_sym) ? nil : locale }
|
||||||
@ -156,6 +157,10 @@ class User < ApplicationRecord
|
|||||||
Rails.env.local?
|
Rails.env.local?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_role_id
|
||||||
|
self.role_id ||= -99
|
||||||
|
end
|
||||||
|
|
||||||
def role
|
def role
|
||||||
if role_id.nil?
|
if role_id.nil?
|
||||||
UserRole.everyone
|
UserRole.everyone
|
||||||
|
21
db/migrate/20240801094244_populate_everyone_role.rb
Normal file
21
db/migrate/20240801094244_populate_everyone_role.rb
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class PopulateEveryoneRole < ActiveRecord::Migration[7.1]
|
||||||
|
disable_ddl_transaction!
|
||||||
|
|
||||||
|
class UserRole < ApplicationRecord
|
||||||
|
EVERYONE_ROLE_ID = -99
|
||||||
|
|
||||||
|
FLAGS = {
|
||||||
|
invite_users: (1 << 16),
|
||||||
|
}.freeze
|
||||||
|
end
|
||||||
|
|
||||||
|
def up
|
||||||
|
UserRole.create!(id: UserRole::EVERYONE_ROLE_ID, permissions: UserRole::FLAGS[:invite_users])
|
||||||
|
rescue ActiveRecord::RecordNotUnique
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def down; end
|
||||||
|
end
|
@ -0,0 +1,7 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class ChangeUsersDefaultRoleId < ActiveRecord::Migration[7.1]
|
||||||
|
def change
|
||||||
|
change_column_default :users, :role_id, from: nil, to: -99
|
||||||
|
end
|
||||||
|
end
|
@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.1].define(version: 2024_07_24_181224) do
|
ActiveRecord::Schema[7.1].define(version: 2024_08_01_100823) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
@ -1201,7 +1201,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_07_24_181224) do
|
|||||||
t.string "webauthn_id"
|
t.string "webauthn_id"
|
||||||
t.inet "sign_up_ip"
|
t.inet "sign_up_ip"
|
||||||
t.boolean "skip_sign_in_token"
|
t.boolean "skip_sign_in_token"
|
||||||
t.bigint "role_id"
|
t.bigint "role_id", default: -99
|
||||||
t.text "settings"
|
t.text "settings"
|
||||||
t.string "time_zone"
|
t.string "time_zone"
|
||||||
t.string "otp_secret"
|
t.string "otp_secret"
|
||||||
|
Loading…
Reference in New Issue
Block a user