2023-01-26 22:41:41 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class AddProtocolVersioningPermissions < ActiveRecord::Migration[6.1]
|
|
|
|
OWNER_PERMISSIONS = [
|
|
|
|
ProtocolPermissions::MANAGE_DRAFT
|
|
|
|
].freeze
|
|
|
|
|
|
|
|
NORMAL_USER_PERMISSIONS = [
|
|
|
|
ProtocolPermissions::MANAGE_DRAFT
|
|
|
|
].freeze
|
|
|
|
|
2023-03-14 16:12:54 +08:00
|
|
|
REMOVED_NORMAL_USER_PERMISSIONS = [
|
|
|
|
ProtocolPermissions::MANAGE
|
|
|
|
].freeze
|
|
|
|
|
2023-01-26 22:41:41 +08:00
|
|
|
def change
|
|
|
|
reversible do |dir|
|
|
|
|
dir.up do
|
|
|
|
@owner_role = UserRole.find_predefined_owner_role
|
|
|
|
@normal_user_role = UserRole.find_predefined_normal_user_role
|
|
|
|
@owner_role.permissions = @owner_role.permissions | OWNER_PERMISSIONS
|
|
|
|
@normal_user_role.permissions = @normal_user_role.permissions | NORMAL_USER_PERMISSIONS
|
2023-03-14 16:12:54 +08:00
|
|
|
@normal_user_role.permissions = @normal_user_role.permissions - REMOVED_NORMAL_USER_PERMISSIONS
|
2023-01-26 22:41:41 +08:00
|
|
|
@owner_role.save(validate: false)
|
|
|
|
@normal_user_role.save(validate: false)
|
2023-03-24 17:58:43 +08:00
|
|
|
|
|
|
|
# properly assign protocol owners, who must always be marked as assigned manually
|
|
|
|
UserAssignment.where(
|
|
|
|
assignable_type: 'Protocol',
|
|
|
|
user_role: UserRole.find_predefined_owner_role,
|
|
|
|
assigned: :automatically
|
|
|
|
).update_all(assigned: :manually)
|
2023-01-26 22:41:41 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
dir.down do
|
|
|
|
@owner_role = UserRole.find_predefined_owner_role
|
|
|
|
@normal_user_role = UserRole.find_predefined_normal_user_role
|
|
|
|
@owner_role.permissions = @owner_role.permissions - OWNER_PERMISSIONS
|
|
|
|
@normal_user_role.permissions = @normal_user_role.permissions - NORMAL_USER_PERMISSIONS
|
2023-03-14 16:12:54 +08:00
|
|
|
@normal_user_role.permissions = @normal_user_role.permissions | REMOVED_NORMAL_USER_PERMISSIONS
|
2023-01-26 22:41:41 +08:00
|
|
|
@owner_role.save(validate: false)
|
|
|
|
@normal_user_role.save(validate: false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|