default permission for existing roles

pull/7338/head
ulferts 5 years ago
parent 50579b558c
commit f6700163f8
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 1
      app/seeders/basic_data/role_seeder.rb
  2. 13
      db/migrate/20190507132517_add_board_view_to_roles.rb
  3. 13
      db/migrate/20190527095959_set_manage_board_permission.rb
  4. 13
      db/migrate/20190603060951_set_assign_versions_permission.rb
  5. 45
      db/migrate/migration_utils/permission_adder.rb

@ -66,6 +66,7 @@ module BasicData
add_work_packages add_work_packages
move_work_packages move_work_packages
edit_work_packages edit_work_packages
assign_versions
add_work_package_notes add_work_package_notes
edit_own_work_package_notes edit_own_work_package_notes
manage_work_package_relations manage_work_package_relations

@ -1,13 +1,10 @@
require "#{Rails.root}/db/migrate/migration_utils/permission_adder"
class AddBoardViewToRoles < ActiveRecord::Migration[5.2] class AddBoardViewToRoles < ActiveRecord::Migration[5.2]
def up def up
Role ::Migration::MigrationUtils::PermissionAdder
.joins(:role_permissions) .add(:view_work_packages,
.where("role_permissions.permission = 'view_work_packages'") :show_board_views)
.references(:role_permissions)
.find_each do |role|
role.add_permission! :show_board_views
end
unless Setting.default_projects_modules.include?('board_view') unless Setting.default_projects_modules.include?('board_view')
Setting.default_projects_modules = Setting.default_projects_modules + ['board_view'] Setting.default_projects_modules = Setting.default_projects_modules + ['board_view']

@ -1,13 +1,10 @@
require "#{Rails.root}/db/migrate/migration_utils/permission_adder"
class SetManageBoardPermission < ActiveRecord::Migration[5.2] class SetManageBoardPermission < ActiveRecord::Migration[5.2]
def up def up
Role ::Migration::MigrationUtils::PermissionAdder
.joins(:role_permissions) .add(:manage_public_queries,
.where("role_permissions.permission = 'manage_public_queries'") :manage_board_views)
.references(:role_permissions)
.find_each do |role|
role.add_permission! :manage_board_views
end
end end
def down def down

@ -0,0 +1,13 @@
require "#{Rails.root}/db/migrate/migration_utils/permission_adder"
class SetAssignVersionsPermission < ActiveRecord::Migration[5.2]
def up
::Migration::MigrationUtils::PermissionAdder
.add(:edit_work_packages,
:assign_versions)
end
def down
# nothing to do
end
end

@ -0,0 +1,45 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See docs/COPYRIGHT.rdoc for more details.
#++
module Migration
module MigrationUtils
class PermissionAdder
def self.add(having, add)
Role
.joins(:role_permissions)
.where(role_permissions: { permission: having.to_s })
.references(:role_permissions)
.find_each do |role|
role.add_permission! add
end
end
end
end
end
Loading…
Cancel
Save