Add customizable user roles (#18641)
* Add customizable user roles * Various fixes and improvements * Add migration for old settings and fix tootctl role management
This commit is contained in:
parent
1b4054256f
commit
44b2ee3485
187 changed files with 1945 additions and 1032 deletions
26
db/post_migrate/20220617202502_migrate_roles.rb
Normal file
26
db/post_migrate/20220617202502_migrate_roles.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class MigrateRoles < ActiveRecord::Migration[5.2]
|
||||
disable_ddl_transaction!
|
||||
|
||||
class UserRole < ApplicationRecord; end
|
||||
class User < ApplicationRecord; end
|
||||
|
||||
def up
|
||||
load Rails.root.join('db', 'seeds', '03_roles.rb')
|
||||
|
||||
admin_role = UserRole.find_by(name: 'Admin')
|
||||
moderator_role = UserRole.find_by(name: 'Moderator')
|
||||
|
||||
User.where(admin: true).in_batches.update_all(role_id: admin_role.id)
|
||||
User.where(moderator: true).in_batches.update_all(role_id: moderator_role.id)
|
||||
end
|
||||
|
||||
def down
|
||||
admin_role = UserRole.find_by(name: 'Admin')
|
||||
moderator_role = UserRole.find_by(name: 'Moderator')
|
||||
|
||||
User.where(role_id: admin_role.id).in_batches.update_all(admin: true) if admin_role
|
||||
User.where(role_id: moderator_role.id).in_batches.update_all(moderator: true) if moderator_role
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue