flexmeasures.api.v3_0.users

Functions

flexmeasures.api.v3_0.users.create_user_audit_log(audit_event: str, user: User)

Create audit log entry for changes on the user

Classes

class flexmeasures.api.v3_0.users.AuthRequestSchema(*, only: types.StrSequenceOrSet | None = None, exclude: types.StrSequenceOrSet = (), many: bool | None = None, context: dict | None = None, load_only: types.StrSequenceOrSet = (), dump_only: types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None)
class flexmeasures.api.v3_0.users.UserAPI
auditlog(id: int, user: UserModel, page: int | None = None, per_page: int | None = None, filter: list[str] | None = None, sort_by: str | None = None, sort_dir: str | None = None)

— get:

summary: Get history of user actions. description: |

The endpoint is paginated and supports search filters.
  • If the page parameter is not provided, all audit logs are returned paginated by per_page (default is 10).

  • If a page parameter is provided, the response will be paginated, showing a specific number of audit logs per page as defined by per_page (default is 10).

  • If sort_by (field name) and sort_dir (“asc” or “desc”) are provided, the list will be sorted.

  • If a search ‘filter’ is provided, the response will filter out audit logs where each search term is either present in the event or active user name. The response schema for pagination is inspired by https://datatables.net/manual/server-side

parameters:
  • in: path name: id required: true schema: UserId description: ID of the user to get the audit log for.

  • in: query name: kwargs schema: UserAuditlogSchema

security:
  • ApiKeyAuth: []

responses:
200:

description: PROCESSED content:

application/json:
examples:
paginated_response:
value:
data:
  • event: ‘User test user deleted’ event_datetime: ‘2021-01-01T00:00:00’ active_user_name: ‘Test user’

num-records: 1 filtered-records: 1

400:

description: INVALID_REQUEST, REQUIRED_INFO_MISSING, UNEXPECTED_PARAMS

401:

description: UNAUTHORIZED

403:

description: INVALID_SENDER

422:

description: UNPROCESSABLE_ENTITY

tags:
  • Users

get(id: int, user: User)

— get:

summary: Get a user description: |

This endpoint gets a user. Only admins or the members of the same account can use this endpoint.

security:
  • ApiKeyAuth: []

parameters:
  • in: path name: id schema: UserId description: ID of the user to get. required: true

responses:
200:

description: PROCESSED content:

application/json:

schema: UserSchema examples:

single_user:

summary: Single user response value:

data:

active: true email: test_prosumer@seita.nl account_id: 1 flexmeasures_roles: [1, 3] id: 1 timezone: Europe/Amsterdam username: Test Prosumer User last_login_at: “2022-05-09T10:47:13.410321” last_seen_at: “2022-05-09T10:47:13.410321”

400:

description: INVALID_REQUEST, REQUIRED_INFO_MISSING, UNEXPECTED_PARAMS

401:

description: UNAUTHORIZED

403:

description: INVALID_SENDER

422:

description: UNPROCESSABLE_ENTITY

tags:
  • Users

index(account: Account, include_inactive: bool = False, page: int | None = None, per_page: int | None = None, filter: list[str] | None = None, sort_by: str | None = None, sort_dir: str | None = None)

— get:

summary: List users. description: |

This endpoint returns all accessible users. By default, only active users are returned. The account_id query parameter can be used to filter the users of a given account. The include_inactive query parameter can be used to also fetch inactive users. Accessible users are users in the same account as the current user. Only admins can use this endpoint to fetch users from a different account (by using the account_id query parameter).

security:
  • ApiKeyAuth: []

parameters:
  • in: query schema: UserAPIQuerySchema

responses:
200:

description: PROCESSED content:

application/json:
examples:
single_user:
description:

An example of one user being returned

value:

data: - active: true

email: test_prosumer@seita.nl account_id: 13 account:

account_roles: [] consultancy_account_id: null id: 29 logo_url: null name: AutoZoomAccount primary_color: null secondary_color: null

flexmeasures_roles: [1, 3] id: 1 timezone: Europe/Amsterdam username: Test Prosumer User last_login_at: “2022-05-09T10:47:13.410321” last_seen_at: “2022-05-09T10:47:13.410321”

400:

description: INVALID_REQUEST

401:

description: UNAUTHORIZED

403:

description: INVALID_SENDER

422:

description: UNPROCESSABLE_ENTITY

tags:
  • Users

patch(id: int, user: User, **user_data)

— patch:

summary: Update a user. description: |

This endpoint sets data for an existing user. It has to be used by the user themselves, admins, consultant or account-admins (of the same account). Any subset of user fields can be sent. If the user is not an (account-)admin, they can only edit a few of their own fields. User roles cannot be updated by everyone - it requires certain access levels (roles, account), with the general rule that you need a higher access level than the role being updated.

The following fields are not allowed to be updated at all: - id - account_id

security:
  • ApiKeyAuth: []

parameters:
  • in: path name: id required: true description: ID of the user to update. schema: UserId

requestBody:
content:
application/json:

schema: UserSchema examples:

update_active:
value:

active: false

responses:
200:

description: UPDATED content:

application/json:

schema: UserSchema examples:

single_user:

description: An example of one user being returned value:

data: - active: true

email: test_prosumer@seita.nl account_id: 1 flexmeasures_roles: [1, 3] id: 1 timezone: Europe/Amsterdam username: Test Prosumer User last_login_at: “2022-05-09T10:47:13.410321” last_seen_at: “2022-05-09T10:47:13.410321”

400:

description: INVALID_REQUEST, REQUIRED_INFO_MISSING, UNEXPECTED_PARAMS

401:

description: UNAUTHORIZED

403:

description: INVALID_SENDER

422:

description: UNPROCESSABLE_ENTITY

tags:
  • Users

post(user_data)

— post:

summary: Create new user description: |

This endpoint creates a new user.

The following fields are required: - email - username - account_id

Other attributes/fields such as password and roles can be assigned or reset later.

security:
  • ApiKeyAuth: []

requestBody:
content:
application/json:
schema:

type: object properties:

email:

type: string example: “test_user@seita.nl

username:

type: string example: “Test User”

account_id:

type: integer example: 1

responses:
201:

description: CREATED content:

application/json:

schema: UserSchema examples:

single_user:
description:

An example of one user being returned

value:

data: - active: true

email: test_user@seita.nl account_id: 1 flexmeasures_roles: [1, 3] id: 1 timezone: Europe/Amsterdam username: Test User

400:

description: INVALID_REQUEST

401:

description: UNAUTHORIZED

403:

description: INVALID_SENDER

422:

description: UNPROCESSABLE_ENTITY

tags:
  • Users

reset_user_password(id: int, user: User)

— patch:

summary: Password reset description: |

Reset the user’s password, and send them instructions on how to reset the password. This endpoint is useful from a security standpoint, in case of worries the password might be compromised. It sets the current password to something random, invalidates cookies and auth tokens, and also sends an email for resetting the password to the user.

Users can reset their own passwords. Only admins can use this endpoint to reset passwords of other users.

parameters:
  • in: path name: id required: true schema: UserId description: ID of the user to reset the password for.

responses:
200:

description: PROCESSED

400:

description: INVALID_REQUEST, REQUIRED_INFO_MISSING, UNEXPECTED_PARAMS

401:

description: UNAUTHORIZED

403:

description: INVALID_SENDER

422:

description: UNPROCESSABLE_ENTITY

tags:
  • Users

class flexmeasures.api.v3_0.users.UserAPIQuerySchema(*, only: types.StrSequenceOrSet | None = None, exclude: types.StrSequenceOrSet = (), many: bool | None = None, context: dict | None = None, load_only: types.StrSequenceOrSet = (), dump_only: types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None)
class flexmeasures.api.v3_0.users.UserAuditlogSchema(*, only: types.StrSequenceOrSet | None = None, exclude: types.StrSequenceOrSet = (), many: bool | None = None, context: dict | None = None, load_only: types.StrSequenceOrSet = (), dump_only: types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None)
class flexmeasures.api.v3_0.users.UserId(*, only: types.StrSequenceOrSet | None = None, exclude: types.StrSequenceOrSet = (), many: bool | None = None, context: dict | None = None, load_only: types.StrSequenceOrSet = (), dump_only: types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None)