-
Notifications
You must be signed in to change notification settings - Fork 874
chore: handle deleted organizations in idp sync #17405
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
Conversation
f1878af
to
9bdf31d
Compare
deleted := false | ||
q.data.organizationMembers = slices.DeleteFunc(q.data.organizationMembers, func(member database.OrganizationMember) bool { | ||
match := member.OrganizationID == arg.OrganizationID && member.UserID == arg.UserID | ||
deleted = deleted || match | ||
return match | ||
}) | ||
if len(deleted) == 0 { | ||
if !deleted { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A dbmem bug I found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh this is nasty, took me a minute to realize what the bug was. 💀
if you want, rather than track deleted
yourself, you could do something like
newMembers := slices.DeleteFunc(q.data.organizationMembers, func(member database.OrganizationMember) bool {
return member.OrganizationID == arg.OrganizationID && member.UserID == arg.UserID
})
if len(newMembers) == len(q.data.organizationMembers) {
return sql.ErrNoRows
}
q.data.organizationMembers = newMembers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had thought about that as well. That felt a bit less direct and less intuitive to me though, so I went with the crude and simple lol
-- Optionally provide a filter for deleted organizations. | ||
CASE WHEN | ||
sqlc.narg('deleted') :: boolean IS NULL THEN | ||
true | ||
ELSE | ||
deleted = sqlc.narg('deleted') | ||
END AND |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds the ability to query for all orgs, regardless of deletion
Deleted organizations are still attempting to sync members. This causes an error on inserting the member, and would likely cause issues later in the sync process even if that member is inserted. Deleted orgs should be skipped.
Idp sync should exclude deleted organizations and auto remove members. They should not be members in the first place.
7b0cb6c
to
909c895
Compare
// If you pass in an empty slice to the db arg, you get all orgs. So the slice | ||
// has to be non-empty to get the expected set. Logically it also does not make | ||
// sense to fetch an empty set from the db. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah but this turns it into our problem. wouldn't this usually be the result of a configuration error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow. You can configure it such that a user is in 0 orgs. Even if it's a configuration mistake on the admin, it is a valid configuration.
Co-authored-by: ケイラ <mckayla@hey.com>
/cherry-pick release/2.20 |
…17405) Deleted organizations are still attempting to sync members. This causes an error on inserting the member, and would likely cause issues later in the sync process even if that member is inserted. Deleted orgs should be skipped.
/cherry-pick release/2.21 |
…17405) Deleted organizations are still attempting to sync members. This causes an error on inserting the member, and would likely cause issues later in the sync process even if that member is inserted. Deleted orgs should be skipped.
Deleted organizations are still attempting to sync members. This causes an error on inserting the member, and would likely cause issues later in the sync process even if that member is inserted. Deleted orgs should be skipped.
The error that arises: