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

[CPDLP-3484] User migrator find or initialise logic to deal with orphaned ecf user, but return error for all the other scenarios #1705

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mooktakim
Copy link
Contributor

@mooktakim mooktakim commented Sep 13, 2024

Context

Ticket: https://dfedigital.atlassian.net.mcas.ms/browse/CPDLP-3484

Changes proposed in this pull request

  • Added new find_or_initialize_user(ecf_user) method:
    • use ecf_user.id and ecf_user.get_an_identity_id to find users on NPQ
    • if users don't exist, initialize new user and return
    • if user exists with only ecf_user.id, return user
    • if both id's return users they are the same, return user
    • if both id's return users, but they are different, raise error
    • if only ecf_user.get_an_identity_id return a user, look into ECF with the ecf_id
      • if not found, update NPQ user's ecf_id
      • if ECF user exists, check if its an orphaned user (transferred etc)
        • if yes, update NPQ user's ecf_id
        • if no, raise an error

Copy link

@mooktakim mooktakim force-pushed the 3484-data-cleanup-update-npq-ecf_id-to-match-most-recent-user branch from 0ca8e00 to fc72bf2 Compare September 16, 2024 09:54
@mooktakim mooktakim force-pushed the 3484-data-cleanup-update-npq-ecf_id-to-match-most-recent-user branch 2 times, most recently from fdc3066 to 4d4e858 Compare September 16, 2024 15:41
@mooktakim mooktakim marked this pull request as ready for review September 16, 2024 15:44
@mooktakim mooktakim requested a review from a team as a code owner September 16, 2024 15:44
@mooktakim mooktakim force-pushed the 3484-data-cleanup-update-npq-ecf_id-to-match-most-recent-user branch from 4d4e858 to 53d78dc Compare September 16, 2024 16:50
@mooktakim mooktakim force-pushed the 3484-data-cleanup-update-npq-ecf_id-to-match-most-recent-user branch from 5df35b0 to 7be492d Compare September 16, 2024 21:12
@mooktakim mooktakim force-pushed the 3484-data-cleanup-update-npq-ecf_id-to-match-most-recent-user branch from 7be492d to 1086f53 Compare September 17, 2024 09:10
Copy link

sonarcloud bot commented Sep 17, 2024

raise ActiveRecord::RecordInvalid, ecf_user
end

ecf_user.errors.add(:base, "End of find_or_initialize_user logic, something weird happened")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we cover this with a test?

end

context "when linked ecf_user is not an orphan" do
let(:failure_manager) do
Copy link
Collaborator

Choose a reason for hiding this comment

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

We mock this already in the shared context, so you can test failures similar to this:

https://github.com/DFE-Digital/npq-registration/blob/main/spec/services/migration/migrators/application_state_spec.rb#L36

@@ -54,6 +54,72 @@ def call

private

def find_or_initialize_user(ecf_user)
# Find Users with `ecf_user.id`
users_with_ecf_id = ::User.where(ecf_id: ecf_user.id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of loading the whole user model into memory here and in the queries below can we just pluck the id attributes and compare on that? has this been ran on the migration env yet?

@@ -54,6 +54,72 @@ def call

private

def find_or_initialize_user(ecf_user)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a bit of a monster function; can we extract several methods to make it easier to follow?

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.

4 participants