Skip to content

PB-2696: Publish UserRole and release new version - #88

Closed
eirinikouvara wants to merge 4 commits into
mainfrom
PB-2696-eirini-publish-user-role
Closed

PB-2696: Publish UserRole and release new version#88
eirinikouvara wants to merge 4 commits into
mainfrom
PB-2696-eirini-publish-user-role

Conversation

@eirinikouvara

@eirinikouvara eirinikouvara commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Adds a UserRole enum to define user roles for access control within the uncertainty engine types.

Changes

  • Added user_role.py: defines UserRole(str, Enum) with two roles:
    • MEMBER: the default role granted when a user is added to an org
    • ADMIN: elevated privileges; can manage members and roles
  • Added test_user_role.py tests covering:
    • Member values are correct
    • Each member is a str instance (validates str, Enum behaviour)
    • Construction from a string value via UserRole("member")
    • Invalid values raise ValueError, including wrong-case inputs
    • The enum contains exactly the expected set of members

Notes
UserRole inherits from both str and Enum, meaning members can be used directly as strings (e.g. in JSON serialisation and string comparisons) without needing to access .value (similar pattern to token.py).

Behaviour (str, Enum) (Enum)
isinstance(UserRole.ADMIN, str) True False
JSON serializable by default Yes ("admin") No (raises TypeError)
String comparison == "admin" True False
.upper(), .startswith(), etc. Works directly AttributeError
.value needed for string ops No Yes

Why include the UserRole in the types library?
The UserRole enum lives in the shared types package so both the accounts service and the public core API import one canonical definition: adding or renaming a role is a single source edit, with no risk of the two services drifting out of sync over duplicated copies. (Note: only the inert role identifiers are shared this way — the role→permission mapping stays private to the accounts service.)

@eirinikouvara

Copy link
Copy Markdown
Contributor Author

Closing as this will be moved to dev-types instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant