1
0
mirror of https://github.com/funamitech/mastodon synced 2024-11-27 14:29:03 +09:00

Solve remaining db/*migrate* cops (#28579)

This commit is contained in:
Matt Jankowski 2024-01-04 11:40:28 -05:00 committed by GitHub
parent d0fd14f851
commit ae39bed95b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 41 deletions

View File

@ -165,7 +165,6 @@ Rails/WhereExists:
- 'app/validators/reaction_validator.rb' - 'app/validators/reaction_validator.rb'
- 'app/validators/vote_validator.rb' - 'app/validators/vote_validator.rb'
- 'app/workers/move_worker.rb' - 'app/workers/move_worker.rb'
- 'db/migrate/20190529143559_preserve_old_layout_for_existing_users.rb'
- 'lib/tasks/tests.rake' - 'lib/tasks/tests.rake'
- 'spec/models/account_spec.rb' - 'spec/models/account_spec.rb'
- 'spec/services/activitypub/process_collection_service_spec.rb' - 'spec/services/activitypub/process_collection_service_spec.rb'
@ -253,8 +252,6 @@ Style/GuardClause:
- 'app/workers/redownload_media_worker.rb' - 'app/workers/redownload_media_worker.rb'
- 'app/workers/remote_account_refresh_worker.rb' - 'app/workers/remote_account_refresh_worker.rb'
- 'config/initializers/devise.rb' - 'config/initializers/devise.rb'
- 'db/migrate/20170901141119_truncate_preview_cards.rb'
- 'db/post_migrate/20220704024901_migrate_settings_to_user_roles.rb'
- 'lib/devise/strategies/two_factor_ldap_authenticatable.rb' - 'lib/devise/strategies/two_factor_ldap_authenticatable.rb'
- 'lib/devise/strategies/two_factor_pam_authenticatable.rb' - 'lib/devise/strategies/two_factor_pam_authenticatable.rb'
- 'lib/mastodon/cli/accounts.rb' - 'lib/mastodon/cli/accounts.rb'
@ -275,7 +272,6 @@ Style/HashAsLastArrayItem:
- 'app/models/status.rb' - 'app/models/status.rb'
- 'app/services/batched_remove_status_service.rb' - 'app/services/batched_remove_status_service.rb'
- 'app/services/notify_service.rb' - 'app/services/notify_service.rb'
- 'db/migrate/20181024224956_migrate_account_conversations.rb'
# This cop supports unsafe autocorrection (--autocorrect-all). # This cop supports unsafe autocorrection (--autocorrect-all).
Style/HashTransformValues: Style/HashTransformValues:

View File

@ -22,11 +22,9 @@ class TruncatePreviewCards < ActiveRecord::Migration[5.1]
end end
def down def down
if ActiveRecord::Base.connection.table_exists? 'deprecated_preview_cards' raise ActiveRecord::IrreversibleMigration, 'Previous preview cards table has already been removed' unless ActiveRecord::Base.connection.table_exists? 'deprecated_preview_cards'
drop_table :preview_cards drop_table :preview_cards
rename_table :deprecated_preview_cards, :preview_cards rename_table :deprecated_preview_cards, :preview_cards
else
raise ActiveRecord::IrreversibleMigration, 'Previous preview cards table has already been removed'
end
end end
end end

View File

@ -105,7 +105,7 @@ class MigrateAccountConversations < ActiveRecord::Migration[5.2]
end end
end end
notifications_about_direct_statuses.includes(:account, mention: { status: [:account, mentions: :account] }).find_each do |notification| notifications_about_direct_statuses.includes(:account, mention: { status: [:account, { mentions: :account }] }).find_each do |notification|
MigrationAccountConversation.add_status(notification.account, notification.target_status) MigrationAccountConversation.add_status(notification.account, notification.target_status)
migrated += 1 migrated += 1

View File

@ -9,7 +9,7 @@ class PreserveOldLayoutForExistingUsers < ActiveRecord::Migration[5.2]
# on the to-be-changed default # on the to-be-changed default
User.where(User.arel_table[:current_sign_in_at].gteq(1.month.ago)).find_each do |user| User.where(User.arel_table[:current_sign_in_at].gteq(1.month.ago)).find_each do |user|
next if Setting.unscoped.where(thing_type: 'User', thing_id: user.id, var: 'advanced_layout').exists? next if Setting.unscoped.exists?(thing_type: 'User', thing_id: user.id, var: 'advanced_layout')
user.settings.advanced_layout = true user.settings.advanced_layout = true
end end

View File

@ -6,36 +6,55 @@ class MigrateSettingsToUserRoles < ActiveRecord::Migration[6.1]
class UserRole < ApplicationRecord; end class UserRole < ApplicationRecord; end
def up def up
owner_role = UserRole.find_by(name: 'Owner') process_role_everyone
admin_role = UserRole.find_by(name: 'Admin') process_role_owner
moderator_role = UserRole.find_by(name: 'Moderator') process_role_admin
process_role_moderator
end
def down; end
private
def process_role_everyone
everyone_role = UserRole.find_by(id: -99) everyone_role = UserRole.find_by(id: -99)
return unless everyone_role
min_invite_role = Setting.min_invite_role
show_staff_badge = Setting.show_staff_badge
if everyone_role
everyone_role.permissions &= ~::UserRole::FLAGS[:invite_users] unless min_invite_role == 'user' everyone_role.permissions &= ~::UserRole::FLAGS[:invite_users] unless min_invite_role == 'user'
everyone_role.save everyone_role.save
end end
if owner_role def process_role_owner
owner_role = UserRole.find_by(name: 'Owner')
return unless owner_role
owner_role.highlighted = show_staff_badge owner_role.highlighted = show_staff_badge
owner_role.save owner_role.save
end end
if admin_role def process_role_admin
admin_role = UserRole.find_by(name: 'Admin')
return unless admin_role
admin_role.permissions |= ::UserRole::FLAGS[:invite_users] if %w(admin moderator).include?(min_invite_role) admin_role.permissions |= ::UserRole::FLAGS[:invite_users] if %w(admin moderator).include?(min_invite_role)
admin_role.highlighted = show_staff_badge admin_role.highlighted = show_staff_badge
admin_role.save admin_role.save
end end
if moderator_role def process_role_moderator
moderator_role = UserRole.find_by(name: 'Moderator')
return unless moderator_role
moderator_role.permissions |= ::UserRole::FLAGS[:invite_users] if %w(moderator).include?(min_invite_role) moderator_role.permissions |= ::UserRole::FLAGS[:invite_users] if %w(moderator).include?(min_invite_role)
moderator_role.highlighted = show_staff_badge moderator_role.highlighted = show_staff_badge
moderator_role.save moderator_role.save
end end
def min_invite_role
Setting.min_invite_role
end end
def down; end def show_staff_badge
Setting.show_staff_badge
end
end end