imaging_api.services.users
Attributes
Functions
|
Gets all users from XNAT. |
Converts central hub user (mainly email) to an XNAT CreateUser object. |
|
|
Fetches a user profile from XNAT using the key and value. |
|
Checks if a user exists in XNAT. |
Convert central hub user to XNAT CreateUser request object, and create user on XNAT. |
|
|
Core logic to create an XNAT user. Returns the newly created user profile. |
|
Adds a user to a project in XNAT. |
Module Contents
- imaging_api.services.users.XNAT_URL
- imaging_api.services.users.get_xnat_users(headers: dict[str, str]) list[imaging_api.routers.schemas.User]
Gets all users from XNAT.
- Parameters:
headers (dict[str, str]) – XNAT authentication headers.
- Returns:
List of XNAT users.
- Return type:
- Raises:
Exception – If XNAT returns a non-200 response.
- imaging_api.services.users.to_create_imaging_user(user: imaging_api.routers.schemas.CentralHubUser, headers: dict[str, str]) imaging_api.routers.schemas.CreateUser
Converts central hub user (mainly email) to an XNAT CreateUser object.
XNAT usernames are unique, so we have to create a unique XNAT username from the email address. We first grab the part of the email before ‘@’. If the username already exists, we append a number suffix to make it unique.
- Parameters:
user (imaging_api.routers.schemas.CentralHubUser) – The user’s details on the Central Hub.
headers (dict[str, str]) – XNAT authentication headers.
- Returns:
XNAT user creation request object.
- Return type:
- Raises:
Exception – If fetching existing XNAT users fails.
- imaging_api.services.users.get_user_profile_by(key: str, value: str, headers: dict[str, str]) imaging_api.routers.schemas.User
Fetches a user profile from XNAT using the key and value.
- Parameters:
key (str) – The key to search by. Can be ‘username’ or ‘email’.
value (str) – The value to search for.
headers (dict[str, str]) – XNAT authentication headers.
- Returns:
The user profile.
- Return type:
- Raises:
AssertionError – If
keyis not"username"or"email".imaging_api.utils.exceptions.NotFoundError – If no XNAT user matches
valuefor the givenkey.Exception – If fetching XNAT users fails.
- imaging_api.services.users.user_exists(username: str, headers: dict[str, str]) bool
Checks if a user exists in XNAT.
In XNAT, username is unique, so it can be used to identify the user: “ERROR: The username {username} is already in use. Please enter a different username value and try again.”
- Parameters:
username (str) – The username to check.
headers (dict[str, str]) – XNAT authentication headers.
- Returns:
True if the user exists, False otherwise.
- Return type:
bool
- imaging_api.services.users.create_user_from_central_hub_user(central_hub_user: imaging_api.routers.schemas.CentralHubUser, headers: dict[str, str]) tuple[imaging_api.routers.schemas.CreatedUser, imaging_api.routers.schemas.User]
Convert central hub user to XNAT CreateUser request object, and create user on XNAT.
- Parameters:
central_hub_user (imaging_api.routers.schemas.CentralHubUser) – The user’s details on the Central Hub.
headers (dict[str, str]) – XNAT authentication headers.
- Returns:
The created user and the user profile.
- Return type:
tuple[imaging_api.routers.schemas.CreatedUser, imaging_api.routers.schemas.User]
- imaging_api.services.users.create_user(user: imaging_api.routers.schemas.CreateUser, headers: dict[str, str]) imaging_api.routers.schemas.User
Core logic to create an XNAT user. Returns the newly created user profile.
- Parameters:
user (imaging_api.routers.schemas.CreateUser) – The user to create.
headers (dict[str, str]) – XNAT authentication headers.
- Returns:
The created user profile.
- Return type:
- Raises:
AlreadyExistsError – If a user with the same username already exists on XNAT (HTTP 409).
Exception – If XNAT returns any other non-201 response.
- imaging_api.services.users.add_user_to_project(user: imaging_api.routers.schemas.User, project_id: str, headers: dict[str, str]) imaging_api.routers.schemas.User
Adds a user to a project in XNAT.
- Parameters:
user (imaging_api.routers.schemas.User) – The user to add.
project_id (str) – The project ID.
headers (dict[str, str]) – XNAT authentication headers.
- Returns:
The user profile.
- Return type:
- Raises:
HTTPException – If there is an error during the addition of the user to the project.
imaging_api.utils.exceptions.NotFoundError – If the user or project is not found.