commit
ec12261bad
@ -1,57 +0,0 @@ |
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2020 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 RandomData |
||||
class ForumSeeder |
||||
def self.seed!(project) |
||||
user = User.admin.first |
||||
|
||||
puts '' |
||||
print_status ' ↳ Creating forum with posts' |
||||
|
||||
forum = Forum.create! project: project, |
||||
name: I18n.t("seeders.#{OpenProject::Configuration['edition']}.demo_data.board.name"), |
||||
description: I18n.t("seeders.#{OpenProject::Configuration['edition']}.demo_data.board.description") |
||||
|
||||
rand(30).times do |
||||
print_status '.' |
||||
message = Message.create forum: forum, |
||||
author: user, |
||||
subject: Faker::Lorem.words(5).join(' '), |
||||
content: Faker::Lorem.paragraph(5, true, 3) |
||||
|
||||
rand(5).times do |
||||
print_status '.' |
||||
Message.create forum:, |
||||
author: user, |
||||
subject: message.subject, |
||||
content: Faker::Lorem.paragraph(5, true, 3), |
||||
parent: message |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,56 +0,0 @@ |
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2020 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 RandomData |
||||
class NewsSeeder |
||||
def self.seed!(project) |
||||
user = User.admin.first |
||||
|
||||
puts '' |
||||
print_status ' ↳ Creating news' |
||||
|
||||
rand(30).times do |
||||
print_status '.' |
||||
news = News.create project: project, |
||||
author: user, |
||||
title: Faker::Lorem.characters(60), |
||||
summary: Faker::Lorem.paragraph(1, true, 3), |
||||
description: Faker::Lorem.paragraph(5, true, 3) |
||||
|
||||
## create some journal entries |
||||
rand(5).times do |
||||
news.reload |
||||
|
||||
news.title = Faker::Lorem.words(5).join(' ').slice(0, 60) if rand(99).even? |
||||
news.summary = Faker::Lorem.paragraph(1, true, 3) if rand(99).even? |
||||
news.description = Faker::Lorem.paragraph(5, true, 3) if rand(99).even? |
||||
|
||||
news.save! |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,61 +0,0 @@ |
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2020 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 RandomData |
||||
class WikiSeeder |
||||
def self.seed!(project) |
||||
user = User.admin.first |
||||
|
||||
puts '' |
||||
print_status ' ↳ Creating wikis' |
||||
|
||||
rand(5).times do |
||||
print_status '.' |
||||
wiki_page = WikiPage.create( |
||||
wiki: project.wiki, |
||||
title: Faker::Lorem.words(5).join(' ') |
||||
) |
||||
|
||||
## create some wiki contents |
||||
rand(5).times do |
||||
print_status '.' |
||||
wiki_content = WikiContent.create( |
||||
page: wiki_page, |
||||
author: user, |
||||
text: Faker::Lorem.paragraph(5, true, 3) |
||||
) |
||||
|
||||
## create some journal entries |
||||
rand(5).times do |
||||
wiki_content.reload |
||||
wiki_content.text = Faker::Lorem.paragraph(5, true, 3) if rand(99).even? |
||||
wiki_content.save! |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,188 +0,0 @@ |
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2020 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 RandomData |
||||
class WorkPackageSeeder |
||||
attr_accessor :project, :user, :statuses, :repository, :types |
||||
|
||||
def initialize(project) |
||||
self.project = project |
||||
self.user = User.admin.first |
||||
self.statuses = Status.all |
||||
self.repository = Repository.first |
||||
self.types = project.types.all.reject(&:is_milestone?) |
||||
end |
||||
|
||||
def seed!(random: true) |
||||
puts '' |
||||
print_status ' ↳ Creating work_packages' |
||||
|
||||
seed_random_work_packages |
||||
end |
||||
|
||||
private |
||||
|
||||
def seed_random_work_packages |
||||
rand(50).times do |
||||
print_status '.' |
||||
work_package = WorkPackage.create!( |
||||
project:, |
||||
author: user, |
||||
subject: Faker::Lorem.words(8).join(' '), |
||||
status: statuses.sample, |
||||
type: types.sample, |
||||
start_date: s = Date.today - rand(-24..25).days, |
||||
due_date: s + rand(1..120).days |
||||
) |
||||
work_package.priority = IssuePriority.all.sample |
||||
work_package.description = Faker::Lorem.paragraph(5, true, 3) |
||||
work_package.save! |
||||
end |
||||
|
||||
work_package = WorkPackage.first |
||||
|
||||
if repository |
||||
add_changeset(work_package) |
||||
end |
||||
|
||||
add_time_entries(work_package) |
||||
add_attachments(work_package) |
||||
add_custom_values(work_package) |
||||
make_changes(work_package) |
||||
end |
||||
|
||||
def add_changeset(work_package) |
||||
2.times do |changeset_count| |
||||
print_status '.' |
||||
changeset = Changeset.create( |
||||
repository:, |
||||
user:, |
||||
revision: (work_package.id * 10) + changeset_count, |
||||
scmid: (work_package.id * 10) + changeset_count, |
||||
work_packages: [work_package], |
||||
committer: Faker::Name.name, |
||||
committed_on: Date.today, |
||||
comments: Faker::Lorem.words(8).join(' ') |
||||
) |
||||
|
||||
5.times do |
||||
print_status '.' |
||||
change = Change.create( |
||||
action: Faker::Lorem.characters(1), |
||||
path: Faker::Internet.url |
||||
) |
||||
|
||||
changeset.file_changes << change |
||||
end |
||||
|
||||
repository.changesets << changeset |
||||
|
||||
changeset.save! |
||||
|
||||
rand(5).times do |
||||
print_status '.' |
||||
changeset.reload |
||||
|
||||
changeset.committer = Faker::Name.name if rand(99).even? |
||||
changeset.committed_on = Date.today + rand(999) if rand(99).even? |
||||
changeset.comments = Faker::Lorem.words(8).join(' ') if rand(99).even? |
||||
|
||||
changeset.save! |
||||
end |
||||
end |
||||
end |
||||
|
||||
def add_time_entries(work_package) |
||||
5.times do |time_entry_count| |
||||
time_entry = TimeEntry.create( |
||||
project:, |
||||
user:, |
||||
work_package:, |
||||
spent_on: Date.today + time_entry_count, |
||||
activity: time_entry_activities.sample, |
||||
hours: time_entry_count |
||||
) |
||||
work_package.time_entries << time_entry |
||||
end |
||||
end |
||||
|
||||
def add_attachments(work_package) |
||||
3.times do |_attachment_count| |
||||
file = OpenProject::Files.create_uploaded_file(name: Faker::Lorem.words(8).join(' ')) |
||||
attachment = Attachment.new( |
||||
container: work_package, |
||||
author: user, |
||||
file: |
||||
) |
||||
attachment.save! |
||||
|
||||
work_package.attachments << attachment |
||||
end |
||||
end |
||||
|
||||
def add_custom_values(work_package) |
||||
project.work_package_custom_fields.each do |custom_field| |
||||
work_package.type.custom_fields << custom_field if !work_package.type.custom_fields.include?(custom_field) |
||||
work_package.custom_values << CustomValue.new(custom_field:, |
||||
value: Faker::Lorem.words(8).join(' ')) |
||||
end |
||||
|
||||
work_package.type.save! |
||||
work_package.save! |
||||
end |
||||
|
||||
def make_changes(work_package) |
||||
20.times do |
||||
print_status '.' |
||||
work_package.reload |
||||
|
||||
work_package.status = statuses.sample if rand(99).even? |
||||
work_package.subject = Faker::Lorem.words(8).join(' ') if rand(99).even? |
||||
work_package.description = Faker::Lorem.paragraph(5, true, 3) if rand(99).even? |
||||
work_package.type = types.sample if rand(99).even? |
||||
|
||||
work_package.time_entries.each do |t| |
||||
t.spent_on = Date.today + rand(100) if rand(99).even? |
||||
t.activity = time_entry_activities.sample if rand(99).even? |
||||
t.hours = rand(10) if rand(99).even? |
||||
end |
||||
|
||||
work_package.reload |
||||
|
||||
attachments = work_package.attachments.select { |_a| rand(999) < 10 } |
||||
work_package.attachments = work_package.attachments - attachments |
||||
|
||||
work_package.reload |
||||
|
||||
work_package.custom_values.each do |cv| |
||||
cv.value = Faker::Code.isbn if rand(99).even? |
||||
end |
||||
|
||||
work_package.save! |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,55 +0,0 @@ |
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2020 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. |
||||
class RandomDataSeeder |
||||
def self.seed! |
||||
puts ' ########################################################' |
||||
puts ' # WARNING: THIS DELETES ANY DEMO DATA THAT WAS SEEDED #' |
||||
puts ' ########################################################' |
||||
|
||||
project = DemoData::ProjectSeeder.seed! |
||||
|
||||
DemoData::CustomFieldSeeder.seed!(project) |
||||
RandomData::ForumSeeder.seed!(project) |
||||
RandomData::NewsSeeder.seed!(project) |
||||
RandomData::WikiSeeder.seed!(project) |
||||
RandomData::WorkPackageSeeder.new(project).seed! |
||||
|
||||
puts "\n\n" |
||||
puts ' ################################' |
||||
puts ' # Random seeding....done #' |
||||
puts ' ################################' |
||||
puts " # %02d %-23s #" % [WorkPackage.where(project_id: project.id).count, 'issues created.'] |
||||
puts " # %02d %-23s #" % [Message.joins(:board).where(boards: { project_id: project.id }).count, 'messages created.'] |
||||
puts " # %02d %-23s #" % [News.where(project_id: project.id).count, 'news created.'] |
||||
puts " # %02d %-23s #" % [WikiContent.joins(page: [:wiki]).where('wikis.project_id = ?', project.id).count, |
||||
'wiki contents created.'] |
||||
puts " # %02d %-23s #" % [TimeEntry.where(project_id: project.id).count, 'time entries created.'] |
||||
puts " # %02d %-23s #" % [Changeset.joins(:repository).where(repositories: { project_id: project.id }).count, |
||||
'changesets created.'] |
||||
puts " ################################\n\n" |
||||
end |
||||
end |
@ -0,0 +1,57 @@ |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-2022 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 Projects::Copy |
||||
# Can be included in case the dependent service needs to be listed in the copy_dependency section for: |
||||
# * Being an option in the UI |
||||
# * Calculating the count |
||||
# but does not really need to do anything beyond that. |
||||
# |
||||
# This is currently employed to turn the attachment dependent services into NoCreate services as attachment |
||||
# handling has been moved into the create services e.g. of WorkPackage and WikiPage. |
||||
module AttachmentCopier |
||||
extend ActiveSupport::Concern |
||||
|
||||
class_methods do |
||||
def attachment_dependent_service(service_const = nil) |
||||
@attachment_dependent_service = service_const if service_const |
||||
|
||||
@attachment_dependent_service |
||||
end |
||||
|
||||
def copy_dependencies |
||||
super + [attachment_dependent_service] |
||||
end |
||||
end |
||||
|
||||
protected |
||||
|
||||
def copy_attachments? |
||||
(params.dig(:params, :only) || []) |
||||
.any? { |k| k.to_s == self.class.attachment_dependent_service.identifier } |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,42 @@ |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-2022 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 Projects::Copy |
||||
# Can be included in case the dependent service needs to be listed in the copy_dependency section for: |
||||
# * Being an option in the UI |
||||
# * Calculating the count |
||||
# but does not really need to do anything beyond that. |
||||
# |
||||
# This is currently employed to turn the attachment dependent services into NoCreate services as attachment |
||||
# handling has been moved into the create services e.g. of WorkPackage and WikiPage. |
||||
module NoCopier |
||||
protected |
||||
|
||||
def copy_dependency(params:) |
||||
# Not actually doing any copying. |
||||
end |
||||
end |
||||
end |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue