Skip to content

Commit

Permalink
fix: firstOrgAdmin being set to true even if invite was not for an ad…
Browse files Browse the repository at this point in the history
…min (#2110)

Non-admin users should not be given option to rename org when invited to
a new org:
- set firstOrgAdmin to true only when invite is for an admin
- default to false instead of null
- update tests to check
  • Loading branch information
ikreymer authored Oct 8, 2024
1 parent c33f749 commit 6032e28
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion backend/btrixcloud/invites.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ async def get_invite_out(
invite_out.orgName = org.name
invite_out.orgSlug = org.slug

if include_first_org_admin:
if include_first_org_admin and invite.role >= UserRole.OWNER:
invite_out.firstOrgAdmin = True
for role in org.users.values():
if role == UserRole.OWNER:
Expand Down
2 changes: 1 addition & 1 deletion backend/btrixcloud/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class InviteOut(BaseModel):
orgSlug: Optional[str] = None
role: UserRole = UserRole.VIEWER
email: Optional[EmailStr] = None
firstOrgAdmin: Optional[bool] = None
firstOrgAdmin: bool = False


# ============================================================================
Expand Down
1 change: 1 addition & 0 deletions backend/test/test_org.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def test_get_pending_org_invites(
assert invite["oid"] == non_default_org_id
assert invite["created"]
assert invite["role"]
assert invite["firstOrgAdmin"] == False

# Delete Invites
r = requests.post(
Expand Down
5 changes: 3 additions & 2 deletions backend/test/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def test_pending_invite_new_user(admin_auth_headers, default_org_id):
assert invite["oid"] == default_org_id
assert invite["created"]
assert invite["role"]
assert invite["firstOrgAdmin"] == None
assert invite["firstOrgAdmin"] == False


def test_new_user_token():
Expand Down Expand Up @@ -382,7 +382,7 @@ def test_pending_invite_existing_user(admin_auth_headers, non_default_org_id):
assert invite["oid"] == non_default_org_id
assert invite["created"]
assert invite["role"]
assert invite["firstOrgAdmin"] == None
assert invite["firstOrgAdmin"] == False


def test_pending_invites_crawler(crawler_auth_headers, default_org_id):
Expand Down Expand Up @@ -512,6 +512,7 @@ def test_non_superadmin_admin_can_invite(default_org_id):
assert not data["fromSuperuser"]
assert data["inviterEmail"] == VALID_USER_EMAIL
assert data["inviterName"] == "valid"
assert data["firstOrgAdmin"] == False


def test_forgot_password():
Expand Down

0 comments on commit 6032e28

Please sign in to comment.