Skip to content

Commit

Permalink
Fix server CLI human_accesses command incorrectly displaying user p…
Browse files Browse the repository at this point in the history
…rofile updates
  • Loading branch information
touilleMan committed Feb 13, 2025
1 parent 81a7c7e commit d93eee7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion server/parsec/cli/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def _display_user(
print(base_indent + f"User {display_user} ({user_info})")
print(base_indent + f"\t{user.created_on}: Created with profile {user.initial_profile}")

for profile_update in user.profile_updates:
for profile_update in user.subsequent_profile_updates:
print(
base_indent + f"\t{profile_update[0]}: Updated to profile {profile_update[1]}"
)
Expand Down
2 changes: 1 addition & 1 deletion server/parsec/components/memory/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ async def test_dump_current_users(
devices=[
d.cooked.device_id for d in org.devices.values() if d.cooked.user_id == user_id
],
profile_updates=[
profile_history=[
# Initial profile
(user.cooked.timestamp, user.cooked.profile),
# Subsequent profile updates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async def user_test_dump_current_users(
created_on=row["created_on"],
revoked_on=row["revoked_on"],
devices=[],
profile_updates=[(row["created_on"], UserProfile.from_str(row["initial_profile"]))],
profile_history=[(row["created_on"], UserProfile.from_str(row["initial_profile"]))],
)

rows = await conn.fetch(*_q_get_organization_devices(organization_id=organization_id.str))
Expand All @@ -102,6 +102,6 @@ async def user_test_dump_current_users(
except KeyError:
# A concurrent operation may have created a new user we don't know about
continue
user.profile_updates.append((row["certified_on"], profile))
user.profile_history.append((row["certified_on"], profile))

return items
13 changes: 9 additions & 4 deletions server/parsec/components/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from dataclasses import dataclass
from enum import auto
from typing import Iterable

from parsec._parsec import (
DateTime,
Expand Down Expand Up @@ -46,17 +47,21 @@ class UserDump:
human_handle: HumanHandle
created_on: DateTime
revoked_on: DateTime | None
# Ordered oldest to newest
profile_updates: list[tuple[DateTime, UserProfile]]
# Initial profile + subsequent profile updates, ordered oldest to newest.
profile_history: list[tuple[DateTime, UserProfile]]
devices: list[DeviceID]

@property
def current_profile(self) -> UserProfile:
return self.profile_updates[-1][1]
return self.profile_history[-1][1]

@property
def initial_profile(self) -> UserProfile:
return self.profile_updates[0][1]
return self.profile_history[0][1]

@property
def subsequent_profile_updates(self) -> Iterable[tuple[DateTime, UserProfile]]:
yield from self.profile_history[1:]


@dataclass(slots=True)
Expand Down
2 changes: 1 addition & 1 deletion server/tests/api_v5/authenticated/test_user_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ async def test_authenticated_user_create_ok(
expected_dump[NEW_MIKE_USER_ID] = UserDump(
user_id=NEW_MIKE_USER_ID,
devices=[NEW_MIKE_DEVICE_ID],
profile_updates=[(t1, UserProfile.STANDARD)],
profile_history=[(t1, UserProfile.STANDARD)],
created_on=t1,
human_handle=NEW_MIKE_HUMAN_HANDLE,
revoked_on=None,
Expand Down
2 changes: 1 addition & 1 deletion server/tests/api_v5/authenticated/test_user_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def test_authenticated_user_update_ok(coolorg: CoolorgRpcClients, backend:
)

expected_dump = await backend.user.test_dump_current_users(coolorg.organization_id)
expected_dump[coolorg.bob.user_id].profile_updates.append((now, UserProfile.ADMIN))
expected_dump[coolorg.bob.user_id].profile_history.append((now, UserProfile.ADMIN))

expected_topics = await backend.organization.test_dump_topics(coolorg.organization_id)
expected_topics.common = certif.timestamp
Expand Down

0 comments on commit d93eee7

Please sign in to comment.