Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dummy works rake task #512

Merged
merged 13 commits into from
Feb 26, 2024
Merged

Dummy works rake task #512

merged 13 commits into from
Feb 26, 2024

Conversation

alepbloyd
Copy link
Contributor

Adds a rake task for generating dummy works for development convenience, and removes old dummy files used for testing - using Prawn gem to generate simple PDFs instead, which is more flexible.

Takes optional arguments of public_works, private_works, and authenticated_works with integers. For example:

bundle exec rails gwss:create_dummy_works public_works=4 private_works=2 authenticated_works=3 RAILS_ENV=production

This would run in the production environment, and the first admin user would create 4 public works, 2 works private to that admin, and 3 authenticated works visible to logged in users. You can also omit any of these arguments and it will be assumed that you mean 0.

@dolsysmith
Copy link
Contributor

dolsysmith commented Feb 23, 2024

I am getting an error when running the task:

Errno::ENOENT: No such file or directory @ rb_sysopen - /opt/scholarspace/scholarspace-hyrax/spec/fixtures/dummy_works/public/public_work_0.pdf

Note that I'm not running it with a clean database -- should that make a difference?

There is no dummy_works folder in spec/fixtures, FWIW.

@dolsysmith
Copy link
Contributor

Adding those missing folders seems to have resolved the issue, so I imagine you might just need to commit them with a .keep file so that they populate the repo.

@dolsysmith
Copy link
Contributor

dolsysmith commented Feb 23, 2024

Some interesting behavior here:

  • Some of the works have the work type of gw_etd, but they are in the Default Admin Set, not the ETDs admin set.
  • Although my admin user has ownership of the works, I can't seem to edit any of them -- the edit button is disabled.

I tested this with a clean database/Solr index/Fedora instance, and I'm still seeing this behavior. Here are the steps I used to set up the instance (while in the app container as the scholarspace user):

bundle exec rails db:migrate RAILS_ENV=production
bundle exec rails gwss:prep_new_prod RAILS_ENV=production [email protected] admin_password=password
mkdir -p spec/fixtures/dummy_works/public # Repeated this step for private and authenticated
bundle exec rails gwss:create_dummy_works public_works=4 private_works=2 authenticated_works=3 RAILS_ENV=production

I can still edit a work I create in the UI, and I can't immediately see anything in the metadata (as viewed in the Rails console) that would identify a difference in permissions between these two works. Also, I'm noting that in the default behavior -- even in production -- when creating an ETD is not to assign it to the ETDs admin set. It may be possible by passing admin_set_id as an attribute when creating the work in the Rake task (though I haven't tested this, and first it would be necessary to find the ID of the ETDs admin set).

@dolsysmith
Copy link
Contributor

Ah! It's not editable because the license field has not been populated. Adding a license value allows it to be saved.

For closing this PR, I'd recommend a) adding the empty directories and b) populating the license field in the method(s) that create the works.

The issue of ETDs not being added to the ETD admin set seems like a separate issue. I'll create a ticket for that.

Copy link
Contributor

@dolsysmith dolsysmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See suggestions in my previous comment.

@alepbloyd
Copy link
Contributor Author

Got it! Thanks for taking a look - will make these changes.

@alepbloyd
Copy link
Contributor Author

@dolsysmith

I'm making those adjustments to this now and have a question.

The way I had it set up, it just finds the first admin user in the database and has that user as the creator for the dummy works - admin_user = Role.find_by(name: "admin").users.first.

I think I could change it to also take an email address as an argument, check if that user is in the database and also an admin, and if so - set that to be the user used in the rake task for creating the works.

If that user isn't in the DB or isn't an admin, would just have it throw an error and exit the task with explanation.

Do you think that change makes sense?

@dolsysmith
Copy link
Contributor

@alepbloyd I think that change makes sense -- thanks!

@alepbloyd
Copy link
Contributor Author

Cool cool - made those changes:

  • Added admin_email argument, pass in the email of an admin user. Aborts if user doesn't exist or isn't an admin.
  • Added .keep files to the spec/fixtures/dummy_works folders, and corresponding .gitignore changes. Also added a .keep to the /tmp folder to keep it in the repo.
  • Added license to the work creation.

@alepbloyd alepbloyd requested a review from dolsysmith February 23, 2024 22:48
@alepbloyd alepbloyd merged commit 09325a8 into master Feb 26, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants