Passed
Push — master ( 6bc43d...2da2ee )
by Ahmad
07:04
created

AddManageRoomRecordingsToPermissions   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 18
rs 10
c 1
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A change() 0 16 1
1
# frozen_string_literal: true
2
3
class MigrationProduct < ActiveRecord::Base
4
  self.table_name = :roles
5
end
6
7
class SubMigrationProduct < ActiveRecord::Base
8
  self.table_name = :role_permissions
9
end
10
11
class AddManageRoomRecordingsToPermissions < ActiveRecord::Migration[5.2]
12
  def change
13
    reversible do |dir|
14
      dir.up do
15
        MigrationProduct.all.each do |role|
16
          SubMigrationProduct.create(role_id: role.id, name: "can_manage_rooms_recordings",
17
            value: SubMigrationProduct.find_by(role_id: role.id, name: "can_manage_users").value, enabled: true)
18
        end
19
      end
20
21
      dir.down do
22
        MigrationProduct.all.each do |role|
23
          SubMigrationProduct.find_by(role_id: role.id, name: "can_manage_rooms_recordings").destroy
24
        end
25
      end
26
    end
27
  end
28
end
29