Skip to content

Mattw/lg 8058 default scope#7418

Closed
n1zyy wants to merge 6 commits intomainfrom
mattw/LG-8058_default_scope
Closed

Mattw/lg 8058 default scope#7418
n1zyy wants to merge 6 commits intomainfrom
mattw/LG-8058_default_scope

Conversation

@n1zyy
Copy link
Contributor

@n1zyy n1zyy commented Dec 1, 2022

DO NOT MERGE THIS until the IdentitiesBackfillJob has completed and we've ensured that there are no rows in prod where deleted_at IS NULL AND last_consented at IS NULL. (At the moment this is a crude WIP anyway, but the warning remains when this is finished.)

And also basic test / factory update

changelog: Internal, Attempts API, ServiceProviderIdentity has consented scope
This introduces linter error on too-long comments that won't stay, so ignore them for now.
)
end

# maw: come back and look at this some more.
Copy link
Contributor

Choose a reason for hiding this comment

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

now that we have backfilled the whole table, we can drop the last_estimated_consent || logic entirely

def find_identity_with_code
return if code.blank? || code.include?("\x00")

# mattw: I suspect we want to change this one
Copy link
Contributor

Choose a reason for hiding this comment

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

yes


def load_identity(access_token)
# mattw: Should we change this one?
identity = ServiceProviderIdentity.where(access_token: access_token).take
Copy link
Contributor

Choose a reason for hiding this comment

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

yes change this one

{ uuid: uuid, service_provider: service_provider }
end
# mattw: Same, but I think we should change htis one
ServiceProviderIdentity.where(criteria).take
Copy link
Contributor

Choose a reason for hiding this comment

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

yes yes change this

# mattw: This seems like a confusing use case. Used only in data_requests.rake FWIW.
User.find_by(uuid: uuid) ||
ServiceProviderIdentity.find_by(uuid: uuid)&.user
ServiceProviderIdentity.consented.find_by(uuid: uuid)&.user
Copy link
Contributor

Choose a reason for hiding this comment

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

im thinking maybe we take this out for better reporting, because the agency already has the UUID

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh! Good catch.

There's a certain myopia that seeps in when one hyperfocuses on this stuff, it seems.

@identity ||= find_or_create_identity_with_costing
end

# mattw: What does this have to do with costing?
Copy link
Contributor

Choose a reason for hiding this comment

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

it probably use to have a costing method but I bet we removed it, maybe we should rename this

Comment on lines +22 to 26
# mattw: I think we should change this but this breaks tests, possibly because
# the test calls user.identities and we need to change that still?
event.user.
service_providers.
merge(ServiceProviderIdentity.not_deleted).
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# mattw: I think we should change this but this breaks tests, possibly because
# the test calls user.identities and we need to change that still?
event.user.
service_providers.
merge(ServiceProviderIdentity.not_deleted).
event.user.
service_providers.
merge(ServiceProviderIdentity.not_deleted).
merge(ServiceProviderIdentity.consented).

yes definitely should be here, we need to fix the tests

# rubocop:enable Rails/InverseOf

scope :not_deleted, -> { where(deleted_at: nil) }
scope :consented, -> { where.not(last_consented_at: nil) }
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm generally against it since it can be kind of surprising, but is this a situation for default_scope that defaults to consented identities?

The risks involved are not small, and I don't think we should commit to using it long-term, but the column is a big shift in the assumptions we can make about an identity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was actually my first instinct, but a previous project I was on ran into a whole lot of trouble that ultimately convinced me it was evil.

The idea of a short-term default scope is a little tempting, though, especially with some urgency around this. What say ye, @zachmargolis?

Copy link
Contributor

Choose a reason for hiding this comment

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

I've been bitten by default_scope... I think our uses cases here are mixed enough that we don't want to use that here

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have any strong opinions on "short-term" but will say that I feel like saying something is short term doesn't guarantee we'll actually remove it quickly 😂

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I'm mostly looking for safeguards to not treat users that have not consented as though they have

)
end

# Not changing; this is inbound RISC calls
Copy link
Contributor

Choose a reason for hiding this comment

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

let's remove this comment? since it's useful in the scope of this PR, but as a permanent comment, not really

Suggested change
# Not changing; this is inbound RISC calls

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's useful in the scope of this PR, but as a permanent comment, not really

I was planning on leaving these comments in while I work, and then pulling them all out when I take this out of draft status. Right now it's a note-to-self as I go through these. Agree 💯 that it should come out before this lands, though.

Comment on lines 94 to 100
)&.uuid ||
ServiceProviderIdentity.find_by(
# This changes breaks nothing
ServiceProviderIdentity.consented.find_by(
user_id: event.user.id,
service_provider: service_provider.issuer,
)&.uuid
Copy link
Contributor

Choose a reason for hiding this comment

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

honestly this code could probably be refactored to use AgencyIdentity.for instead of redoing the logic here

Copy link
Contributor

@mitchellhenke mitchellhenke left a comment

Choose a reason for hiding this comment

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

Still taking a look into this, will revisit once we've exhausted other options!

# rubocop:enable Rails/InverseOf

scope :not_deleted, -> { where(deleted_at: nil) }
scope :consented, -> { where.not(last_consented_at: nil) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Dropping a "requested change" as something of a formality while we re-evaluate this set of changes internally

@zachmargolis
Copy link
Contributor

Closing this out since we're relying on session id/TID instead

@aduth aduth deleted the mattw/LG-8058_default_scope branch January 3, 2023 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants