phac-nml / irida-next

IRIDA Next
https://phac-nml.github.io/irida-next/
Apache License 2.0
8 stars 2 forks source link

Project automation bot migration #565

Closed deepsidhu85 closed 2 months ago

deepsidhu85 commented 2 months ago

What does this PR do and why?

Describe in detail what your merge request does and why.

This PR adds in the migration to add project automation bots to existing projects which don't have an automation bot. The namespace_bot model has also been updated to remove a circular dependency and to remove any memberships with the namespace and user as attributes. Also, a method was added to project_namespace to get the automation bot for the project

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other pull requests.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Verify migration works:

  1. On the main branch reset the db bin/rails db:drop db:create db:migrate and then seed the db bin/rails db:seed
  2. Open up rails console and verify that Project.first.namespace.users has a user with a user_type of project_automation_bot
  3. Get the user from step 2 with `user = Project.first.namespace.users.find_by(user_type: Users.user_types[:project_automation_bot])
  4. Run user.destroy. This should remove the user, any personal access tokens, any memberships, and any namespace bot records
  5. Switch over to this branch
  6. Run bin/rails db:migrate in the terminal
  7. Verify the migration is successful
  8. In the rails console run Project.first.namespace.users. Verify a automation bot was added with a user_type of project_automation_bot
  9. Verify a NamespaceBot entry was not made for the automation bot. Do this for any other projects as well and none of them should have a NamespaceBot entry
  10. Verify a Member entry exists for the Namespace and the User(automation bot from step 8)
  11. Verify tests pass

Verify deletion

If deleting a namespace bot, automation/regular bot(from the Users table)

1) Create a new project 2) Create an n number of new bot accounts 3) Verify in the terminal the project has n bot accounts with project.namespace.bots and only 1 namespace bot entry project.namespace.namespace_bots 4) In the terminal, delete the user from one of these bot accounts (non automation bot) 5) Verify the user, its personal access tokens, memberships, and namespace bot records are also destroyed 6) In the terminal, delete the NamespaceBot record for one of the bot accounts 7) Verify the namespace bot, and member records are deleted, and verify the user has not been deleted nor its personal access tokens

PR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

github-actions[bot] commented 2 months ago

Simplecov Report

Covered Threshold
92.18% 90%