Skip to content

Commit

Permalink
Merge pull request #13657 from opf/implementation/49923-add-user-to-d…
Browse files Browse the repository at this point in the history
…ev-seeds-with-work-package-roles

[#49923] Seed dev user with shared work packages
  • Loading branch information
aaron-contreras authored Sep 12, 2023
2 parents b074d85 + 5ee049e commit 8777035
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 45 deletions.
6 changes: 5 additions & 1 deletion app/seeders/development_data/projects_seeder.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2023 the OpenProject GmbH
Expand Down Expand Up @@ -49,7 +51,7 @@ def applicable?
end

def project_identifiers
%w(dev-empty dev-large dev-large-child dev-custom-fields)
%w(dev-empty dev-work-package-sharing dev-large dev-large-child dev-custom-fields)
end

def reset_projects
Expand All @@ -62,6 +64,8 @@ def reset_projects
end

project.save!
seed_data.store_reference(id.underscore.to_sym, project)

project
end
end
Expand Down
161 changes: 161 additions & 0 deletions app/seeders/development_data/shared_work_packages_seeder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# frozen_string_literal: true

# -- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2023 the OpenProject GmbH
#
# 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-2013 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 COPYRIGHT and LICENSE files for more details.
# ++

module DevelopmentData
class SharedWorkPackagesSeeder < Seeder
def seed_data!
print_status ' ↳ Creating development work packages...'

print_status ' -Creating/Resetting development work packages'
reset_work_packages

print_status ' -Sharing work packages'
share_work_packages
end

def applicable?
WorkPackage.where(subject: work_package_subjects).empty?
end

private

def work_package_subjects
['[dev] Save Gotham', '[dev] Defeat Bane', '[dev] Find Waldo', '[dev] Organize game night']
end

def reset_work_packages
WorkPackage.where(subject: work_package_subjects).destroy_all

work_package_attributes.map do |attributes|
identifier = attributes.delete(:reference)

work_package = WorkPackage.new attributes

if identifier == :defeat_bane
work_package.parent = seed_data.find_reference(:save_gotham)
end

work_package.save!
seed_data.store_reference(identifier, work_package)

work_package
end
end

# rubocop:disable Metrics/AbcSize
def work_package_attributes
[
{
project:,
author:,
subject: '[dev] Save Gotham',
reference: :save_gotham,
description: "Gotham is in trouble. It's your job to save it!",
status: seed_data.find_reference(:default_status_new),
type: seed_data.find_reference(:default_type_epic),
priority: seed_data.find_reference(:default_priority_immediate)
},
{
project:,
author:,
subject: '[dev] Defeat Bane',
reference: :defeat_bane,
description: 'Must be stopped before Gotham is doomed.',
status: seed_data.find_reference(:default_status_new),
type: seed_data.find_reference(:default_type_task),
priority: seed_data.find_reference(:default_priority_immediate)
},
{
project:,
author:,
subject: '[dev] Find Waldo',
reference: :find_waldo,
status: seed_data.find_reference(:default_status_new),
type: seed_data.find_reference(:default_type_task),
description: 'This one is tricky!',
priority: IssuePriority.default
},
{
project:,
author:,
subject: '[dev] Organize game night',
reference: :organize_game_night,
description: 'Find a time that suits everyone.',
status: seed_data.find_reference(:default_status_in_progress),
type: seed_data.find_reference(:default_type_task),
priority: IssuePriority.default
}
]
end
# rubocop:enable Metrics/AbcSize

def project
@project ||= seed_data.find_reference(:dev_work_package_sharing)
end

def author
@author ||= admin_user
end

def share_work_packages
work_package_sharing_attributes.each do |sharing_attributes|
share(**sharing_attributes)
end
end

def work_package_sharing_attributes
[
{
work_package: seed_data.find_reference(:defeat_bane),
role: seed_data.find_reference(:default_role_work_package_editor)
},
{
work_package: seed_data.find_reference(:organize_game_night),
role: seed_data.find_reference(:default_role_work_package_commenter)
},
{
work_package: seed_data.find_reference(:find_waldo),
role: seed_data.find_reference(:default_role_work_package_viewer)
}
]
end

def share(work_package:, role:)
Member.create!(project:,
principal:,
entity: work_package,
roles: Array(role))
end

def principal
@principal ||= seed_data.find_reference(:work_packager)
end
end
end
49 changes: 9 additions & 40 deletions app/seeders/development_data/users_seeder.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2023 the OpenProject GmbH
Expand Down Expand Up @@ -25,32 +27,7 @@
#
# See COPYRIGHT and LICENSE files for more details.
#++
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2023 the OpenProject GmbH
#
# 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-2013 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 COPYRIGHT and LICENSE files for more details.

module DevelopmentData
class UsersSeeder < Seeder
def seed_data!
Expand All @@ -69,6 +46,8 @@ def seed_data!
print_status " #{msg}"
end
end

seed_data.store_reference(login, user)
end
end

Expand All @@ -77,18 +56,18 @@ def applicable?
end

def seed_users_disabled?
off_values = ["off", "false", "no", "0"]
off_values = %w[off false no 0]

off_values.include? ENV.fetch('OP_DEV_USER_SEEDER_ENABLED', nil)
end

def user_names
%i(reader member project_admin admin_de)
%i(reader member work_packager project_admin admin_de)
end

def not_applicable_message
msg = 'Not seeding development users.'
msg << ' seed users disabled through ENV' if seed_users_disabled?
msg = "Not seeding development users."
msg = "#{msg} seed users disabled through ENV" if seed_users_disabled?

msg
end
Expand All @@ -106,15 +85,5 @@ def new_user(login)
user.notification_settings.build(assignee: true, responsible: true, mentioned: true, watched: true)
end
end

def force_password_change?
!Rails.env.development? && !force_password_change_disabled?
end

def force_password_change_disabled?
off_values = ["off", "false", "no", "0"]

off_values.include? ENV.fetch(force_password_change_env_switch_name, nil)
end
end
end
5 changes: 4 additions & 1 deletion app/seeders/development_data_seeder.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2023 the OpenProject GmbH
Expand Down Expand Up @@ -30,7 +32,8 @@ def data_seeder_classes
[
DevelopmentData::UsersSeeder,
DevelopmentData::CustomFieldsSeeder,
DevelopmentData::ProjectsSeeder
DevelopmentData::ProjectsSeeder,
DevelopmentData::SharedWorkPackagesSeeder
]
end

Expand Down
3 changes: 2 additions & 1 deletion app/seeders/standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ priorities:
- t_name: High
color_name: yellow-7
position: 3
- t_name: Immediate
- reference: :default_priority_immediate
t_name: Immediate
color_name: grape-5
position: 4

Expand Down
10 changes: 8 additions & 2 deletions spec/seeders/root_seeder_standard_edition_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2023 the OpenProject GmbH
Expand Down Expand Up @@ -226,8 +228,12 @@
expect(admins.pluck(:language)).to match_array(%w[en de])
end

it 'creates 4 additional projects for development' do
expect(Project.count).to eq 6
it 'creates 5 additional projects for development' do
expect(Project.count).to eq 7
end

it 'creates 4 additional work packages for development' do
expect(WorkPackage.count).to eq 40
end

it 'creates 1 project with custom fields' do
Expand Down

0 comments on commit 8777035

Please sign in to comment.