Skip to content

Commit

Permalink
Remove work creation from seed, add production check
Browse files Browse the repository at this point in the history
  • Loading branch information
alepbloyd committed Jan 9, 2024
1 parent 7dd0b3e commit 2dcf07b
Showing 1 changed file with 6 additions and 177 deletions.
183 changes: 6 additions & 177 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
abort("The Rails environment is running in production mode!") if Rails.env.production?

# reworking this to only create the necessary collections/roles/users for a minimally
# instance, and will move the seeding of works into a rake task

def create_admin_role
@admin_role = Role.find_or_create_by(name: 'admin')
end
Expand Down Expand Up @@ -98,9 +103,6 @@ def create_content_admin_user

# --------------

require 'active_fedora/cleaner'
ActiveFedora::Cleaner.clean!

# -- Creating admin role and user
create_admin_role
create_default_admin_user
Expand All @@ -115,177 +117,4 @@ def create_content_admin_user

# -- Creating a content-admin role and user
create_content_admin_role
create_content_admin_user

# -- Creating a "journal" collection type --
@journal_gid = create_collection_type('journal',
title: 'Journal',
description: 'This is a sample collection that can be found.',
discoverable: true).to_global_id

# -- Creating a journal collection (GW Undergraduate Review) --
@journal_collection = create_public_collection(@content_admin_user,
@journal_gid,
'gwur',
title: ['GW Undergraduate Review'],
description: ['Wow it is a discoverable journal.'])



# -- Setting the banner and logo of the journal collection
banner_file = File.open('spec/fixtures/branding/gwur/banner/banner_2_gwur.png')
logo_file = File.open('spec/fixtures/branding/gwur/logo/gwur_logo.png')

branding_uploads = [banner_file, logo_file].map {|file| Hyrax::UploadedFile.create(user: @content_admin, file: file)}

banner_uploaded = Hyrax::UploadedFile.first
banner_info = CollectionBrandingInfo.new(
collection_id: @journal_collection.id,
filename: "GWUR_banner.png",
role: "banner",
).save banner_uploaded.file_url

logo_uploaded = Hyrax::UploadedFile.last
logo_info = CollectionBrandingInfo.new(
collection_id: @journal_collection.id,
filename: "GWUR_logo.png",
role: "logo",
).save logo_uploaded.file_url

# -- Creating ETDs as @content-user, attaching files from /spec/fixtures/journal_collection, and adding
# -- the newly created ETDs to the "GW Undergraduate Review" collection

journal_uploads = []
journal_etds = []

Dir[File.join(Rails.root, 'spec', 'fixtures', 'journal_collection', '*')].each_with_index do |file_path, index|
file = File.open(file_path)
title = file_path.split('/').last.split('.').first.titleize
file_type = file_path.split('/').last.split('.').last.upcase

journal_uploads << Hyrax::UploadedFile.create(user: @content_admin,
file: file)

journal_etds << create_public_etd(@content_admin_user,
"journal_etd_#{index}",
title: [title],
description: ["This is a test public ETD"],
creator: ["William Shakespeare"],
keyword: ["Test", "Public", "#{file_type}"],
rights_statement: 'http://rightsstatements.org/vocab/InC/1.0/',
publisher: ["A Fake Publisher Inc"],
language: ["English"],
contributor: ["Batman"],
gw_affiliation: ["Student Organization"],
advisor: ["Batman"],
resource_type: ["Article"])

AttachFilesToWorkJob.perform_now(journal_etds[index], [journal_uploads[index]])
end

journal_etds.each do |j_etd|
j_etd.member_of_collections << @journal_collection
j_etd.save
end

# -- taking the last ETD created and featuring it
@featured_work = FeaturedWork.new(work_id: journal_etds.last.id).save

# -- creating public ETDs from files in spec/fixtures/public_etds --
# -- these should be visible on main page and search without logging in --

public_uploads = []
public_etds = []

Dir[File.join(Rails.root, 'spec', 'fixtures', 'public_etds', '*')].each_with_index do |file_path, index|
file = File.open(file_path)
title = file_path.split('/').last.split('.').first.titleize
file_type = file_path.split('/').last.split('.').last.upcase

public_uploads << Hyrax::UploadedFile.create(user: @admin_user,
file: file)

public_etds << create_public_etd(@admin_user,
"public_etd_#{index}",
title: [title],
description: ["This is a test public ETD"],
creator: ["William Shakespeare"],
keyword: ["Test", "Public", "#{file_type}"],
rights_statement: 'http://rightsstatements.org/vocab/InC/1.0/',
publisher: ["A Fake Publisher Inc"],
language: ["English"],
contributor: ["Batman"],
gw_affiliation: [""],
advisor: ["Batman"],
resource_type: ["Article"])

AttachFilesToWorkJob.perform_now(public_etds[index], [public_uploads[index]])
end

# -- creating private ETDs from files in spec/fixtures/private_etds --
# -- these should be visible only if you are logged in as the default admin user --

private_uploads = []
private_etds = []

Dir[File.join(Rails.root, 'spec', 'fixtures', 'private_etds', '*')].each_with_index do |file_path, index|
file = File.open(file_path)
title = file_path.split('/').last.split('.').first.titleize
file_type = file_path.split('/').last.split('.').last.upcase

private_uploads << Hyrax::UploadedFile.create(user: @admin_user,
file: file)

private_etds << create_private_etd(@admin_user,
"private_etd_#{index}",
title: [title],
description: ["This is a test private ETD"],
creator: ["William Shakespeare"],
keyword: ["Test", "Private", "#{file_type}"],
rights_statement: 'http://rightsstatements.org/vocab/InC/1.0/',
resource_type: ["Article"])

AttachFilesToWorkJob.perform_now(private_etds[index], [private_uploads[index]])
end

# -- creating authenticated ETDs from files in spec/fixtures/authenticated_etds --
# -- these should be visible only if you are logged in as a GW user --

authenticated_uploads = []
authenticated_etds = []

Dir[File.join(Rails.root, 'spec', 'fixtures', 'authenticated_etds', '*')].each_with_index do |file_path, index|
file = File.open(file_path)
title = file_path.split('/').last.split('.').first.titleize
file_type = file_path.split('/').last.split('.').last.upcase

authenticated_uploads << Hyrax::UploadedFile.create(user: @admin_user,
file: file)

authenticated_etds << create_authenticated_etd(@admin_user,
"authenticated_etd_#{index}",
title: [title],
description: ["This is a test authenticated GW user ETD"],
creator: ["John Milton"],
keyword: ["Test", "Authenticated", "#{file_type}"],
rights_statement: 'http://rightsstatements.org/vocab/InC/1.0/',
resource_type: ["Article"])

AttachFilesToWorkJob.perform_now(authenticated_etds[index], [authenticated_uploads[index]])
end

# -- Styling and content blocks

featured_researcher_html = File.open("#{Rails.root}/spec/fixtures/content_blocks/featured_researcher.html")
about_page_html = File.open("#{Rails.root}/spec/fixtures/content_blocks/about_page.html")
help_page_html = File.open("#{Rails.root}/spec/fixtures/content_blocks/help_page.html")

ContentBlock.find_or_create_by(name: "header_background_color").update!(value: "#FFFFFF")
ContentBlock.find_or_create_by(name: "header_text_color").update!(value: "#444444")
ContentBlock.find_or_create_by(name: "link_color").update!(value: "#28659A")
ContentBlock.find_or_create_by(name: "footer_link_color").update!(value: "#FFFFFF")
ContentBlock.find_or_create_by(name: "primary_buttom_background_color").update!(value: "#28659A")

ContentBlock.find_or_create_by(name: "featured_researcher").update!(value: featured_researcher_html.read)
ContentBlock.find_or_create_by(name: "about_page").update!(value: about_page_html.read)
ContentBlock.find_or_create_by(name: "help_page").update!(value: help_page_html.read)
create_content_admin_user

0 comments on commit 2dcf07b

Please sign in to comment.