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

feat(org member invite): OrganizationMemberInviteIndex endpoint #87642

Merged
merged 17 commits into from
Mar 31, 2025

Conversation

mifu67
Copy link
Contributor

@mifu67 mifu67 commented Mar 21, 2025

  • GET: Lists all invites (approved and requests). If org manager/admin, show all invites; otherwise, show only approved invites
  • POST: Create new invite, preserving member invite member functionality

Created endpoints/organization_member/utils.py to hold values accessible to both OrganizationMember* and OrganizationMemberInvite* endpoints (at least until the end of the API rollout period).

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 21, 2025
Copy link

codecov bot commented Mar 21, 2025

Codecov Report

Attention: Patch coverage is 98.80952% with 5 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
.../api/endpoints/organization_member_invite/index.py 94.62% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #87642       +/-   ##
===========================================
+ Coverage   42.12%   87.80%   +45.67%     
===========================================
  Files        9880     9982      +102     
  Lines      561201   565449     +4248     
  Branches    22137    22137               
===========================================
+ Hits       236421   496471   +260050     
+ Misses     324349    68547   -255802     
  Partials      431      431               

@mifu67 mifu67 changed the base branch from master to mifu67/member-invite/org-member-invite-serializer March 25, 2025 15:27
Base automatically changed from mifu67/member-invite/org-member-invite-serializer to master March 25, 2025 15:36
if invite_queryset.filter(invite_status=InviteStatus.APPROVED.value).exists():
raise MemberConflictValidationError("The user %s has already been invited" % email)

if not self.context.get("allow_existing_invite_request"):
Copy link
Member

Choose a reason for hiding this comment

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

is this necessary if we already have a unique constraint on organization+email?

unique_together = ("organization", "email")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Might be good to surface this to the user instead of a confusing FK error? The unique constraint exists on the organizationmember model as well, so I assume this is the reasoning behind the special error.

"""
List all organization member invites.
"""
queryset = OrganizationMemberInvite.objects.filter(organization=organization).order_by(
Copy link
Member

Choose a reason for hiding this comment

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

when this ordering happens, which invite objects are shown first? it would be nice to see the join requests first

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it goes APPROVED -> REQUESTED_TO_BE_INVITED -> REQUESTED_TO_JOIN according to the enum

@mifu67 mifu67 force-pushed the mifu67/member-invite/org-member-invite-index branch from b64ebec to f9f4618 Compare March 25, 2025 17:52
@mifu67 mifu67 marked this pull request as ready for review March 26, 2025 19:37
@mifu67 mifu67 requested review from a team as code owners March 26, 2025 19:37
@mifu67 mifu67 requested a review from cathteng March 26, 2025 19:37
Copy link
Member

@cathteng cathteng left a comment

Choose a reason for hiding this comment

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

overall looking good but i think this is such a monster endpoint that we should try to break down the logic into their own contained functions where possible

Copy link
Member

@cathteng cathteng left a comment

Choose a reason for hiding this comment

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

more thoughts on organization, i think the logic is good though

Copy link
Member

@cathteng cathteng left a comment

Choose a reason for hiding this comment

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

👩🏻‍💻

Copy link
Member

Choose a reason for hiding this comment

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

nice

context={
"organization": organization,
"allowed_roles": allowed_roles,
"allow_retired_roles": not features.has("organizations:team-roles", organization),
Copy link
Member

Choose a reason for hiding this comment

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

nit: could remove allow_retired_roles from context and simply do the feature flag check where this is used inside the validator since we're already passing organization (it's only used in validate_orgRole)

assert response.data[1]["inviteStatus"] == "requested_to_be_invited"

def test_org_owner(self):
user = self.create_user("[email protected]", username="powerful mifu")
Copy link
Member

Choose a reason for hiding this comment

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

👑

Comment on lines 187 to 188
if not request.access.has_scope("member:write"):
queryset = queryset.filter(invite_status=InviteStatus.APPROVED.value)
Copy link
Member

Choose a reason for hiding this comment

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

forgot to comment
it seems like everyone can see the requests

{inviteRequests.length > 0 && (
<Panel>
<PanelHeader>
<StyledPanelItem>
<div>{t('Pending Members')}</div>
<div>{t('Role')}</div>
<div>{t('Teams')}</div>
</StyledPanelItem>
</PanelHeader>
<PanelBody>
{inviteRequests.map(inviteRequest => (
<InviteRequestRow
key={inviteRequest.id}
organization={organization}
inviteRequest={inviteRequest}
inviteRequestBusy={{}}
allRoles={currentMember?.orgRoleList ?? currentMember?.roles ?? ORG_ROLES}
onApprove={handleInviteRequestApprove}
onDeny={handleInviteRequestDeny}
onUpdate={data => updateInviteRequest(inviteRequest.id, data)}
/>
))}
</PanelBody>
</Panel>
)}

@mifu67 mifu67 merged commit 9dae48a into master Mar 31, 2025
48 checks passed
@mifu67 mifu67 deleted the mifu67/member-invite/org-member-invite-index branch March 31, 2025 21:19
andrewshie-sentry pushed a commit that referenced this pull request Apr 8, 2025
- GET: Lists all invites (approved and requests). If org manager/admin,
show all invites; otherwise, show only approved invites
- POST: Create new invite, preserving member invite member functionality

Created `endpoints/organization_member/utils.py` to hold values
accessible to both `OrganizationMember*` and `OrganizationMemberInvite*`
endpoints (at least until the end of the API rollout period).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants