summaryrefslogtreecommitdiffstats
path: root/db/migrate/20130110122628_split_documents_permissions.rb
blob: f52b8e4cd1f74ee4496e06fccf84ea0be8b29b3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class SplitDocumentsPermissions < ActiveRecord::Migration[4.2]
  def up
    # :manage_documents permission split into 3 permissions:
    # :add_documents, :edit_documents and :delete_documents
    Role.all.each do |role|
      if role.has_permission?(:manage_documents)
        role.add_permission! :add_documents, :edit_documents, :delete_documents
        role.remove_permission! :manage_documents
      end
    end
  end

  def down
    Role.all.each do |role|
      if role.has_permission?(:add_documents) ||
          role.has_permission?(:edit_documents) ||
          role.has_permission?(:delete_documents)
        role.remove_permission! :add_documents, :edit_documents, :delete_documents
        role.add_permission! :manage_documents
      end
    end
  end
end