# Extra demo data for pages the base seed does not cover: repository, wiki diff, description diff. # Loaded by seed.rb. Each block has its own guard, so rerunning the seed adds only what is missing. require 'fileutils' require 'open3' require 'tmpdir' apollo = Project.find_by!(identifier: 'apollo') admin = User.find_by!(login: 'admin') User.current = admin # Git repository: built in a work tree, then cloned bare into the files volume (persists restarts). unless apollo.repository bare = '/usr/src/redmine/files/demo-repo.git' work = Dir.mktmpdir git = lambda do |*args| out, status = Open3.capture2e('git', '-C', work, *args) raise "git #{args.join(' ')} failed: #{out}" unless status.success? end env = { 'user.name' => 'Jane Doe', 'user.email' => 'jdoe@example.com' }.flat_map { |k, v| ['-c', "#{k}=#{v}"] } git.('init', '-q', '-b', 'main') File.write(File.join(work, 'README.md'), "# Apollo\n\nCustomer portal.\n") FileUtils.mkdir_p(File.join(work, 'lib')) File.write(File.join(work, 'lib/portal.rb'), "class Portal\n def initialize(user)\n @user = user\n end\nend\n") git.(*env, 'add', '.') git.(*env, 'commit', '-q', '-m', 'Initial import') File.write(File.join(work, 'lib/portal.rb'), "class Portal\n def initialize(user, locale = :en)\n @user = user\n @locale = locale\n end\n\n def greeting\n \"Hello, \#{@user}\"\n end\nend\n") git.(*env, 'commit', '-q', '-am', 'Add locale and greeting (refs #13)') File.write(File.join(work, 'README.md'), "# Apollo\n\nCustomer portal.\n\n## Setup\n\nRun `bin/setup`.\n") git.(*env, 'commit', '-q', '-am', 'Document setup') FileUtils.rm_rf(bare) out, status = Open3.capture2e('git', 'clone', '-q', '--bare', work, bare) raise "git clone failed: #{out}" unless status.success? FileUtils.rm_rf(work) FileUtils.chown_R('redmine', 'redmine', bare) if Process.uid.zero? # the app runs as redmine apollo.enabled_module_names = apollo.enabled_module_names | ['repository'] repo = Repository::Git.create!(project: apollo, url: bare, identifier: 'portal', is_default: true) repo.fetch_changesets end # Second wiki version, so history and diff have something to compare start = apollo.wiki.find_page(apollo.wiki.start_page) if start && start.content.version == 1 start.content.text = start.content.text.sub('Keep this page short.', 'Keep this page short and current.') + "\n## Release\n\nVersion 2.0 ships at the end of the sprint.\n" start.content.author = User.find_by!(login: 'jdoe') start.content.comments = 'Add release section' start.content.save! end # Description change on the showcase issue, so the journal has a "diff" link showcase = Issue.find(13) # the issue the screenshot checklist shows unless showcase.journals.joins(:details).exists?(journal_details: { prop_key: 'description' }) showcase.init_journal(User.find_by!(login: 'msmith')) showcase.description = "#{showcase.description}\n\nAlso happens in the API search endpoint." showcase.save! end # Second forum, so the forum index lists boards instead of redirecting to the only one Board.create!(project: apollo, name: 'Support', description: 'Questions from customers') if apollo.boards.count < 2 puts "Extras: #{Repository.count} repositories, wiki v#{start&.content&.reload&.version}, " \ "#{JournalDetail.where(prop_key: 'description').count} description diffs, #{apollo.boards.count} forums."