Users and permissions

Users

DearDiary.get_user — Function
get_user(id::AbstractString)::Optional{User}

Get a User by id.

Arguments

  • id::AbstractString: The id of the user to query.

Returns

A User object. If the record does not exist, return nothing.

source
get_user(client::Client, id::AbstractString)::Optional{UserResponse}

Fetch a User (sanitized as UserResponse, no password hash) via GET /user/{id}. Returns nothing when the server replies 404 and raises ClientError for other failures. The viewer must be id or an admin.

The username-based local lookup (get_user_by_username) has no REST counterpart; iterate get_users and filter when a username lookup is required.

source
DearDiary.get_user_by_username — Function
get_user_by_username(username::AbstractString)::Optional{User}

Get a User by username. Distinct from get_user because ids and usernames are both strings, so the two lookups cannot share a method told apart by argument type.

Arguments

  • username::AbstractString: The username of the user to query.

Returns

A User object. If the record does not exist, return nothing.

source
DearDiary.get_users — Function
get_users()::Array{User, 1}

Get all User.

Returns

An array of User objects.

source
get_users(client::Client)::Array{UserResponse,1}

List every user via GET /user/. Admin-only route; the returned UserResponse values never include password hashes.

source
DearDiary.create_user — Function
create_user(first_name::AbstractString, last_name::AbstractString, username::AbstractString, password::AbstractString)::NamedTuple{id::Optional{String},status::DataType}

Create a User.

Arguments

  • first_name::AbstractString: The first name of the user.
  • last_name::AbstractString: The last name of the user.
  • username::AbstractString: The username of the user.
  • password::AbstractString: The password of the user.

Returns

  • The created user ID. If an error occurs, nothing is returned.
  • An UpsertResult. Created if the record was successfully created, Duplicate if the record already exists, Unprocessable if the record violates a constraint, and Error if an error occurred while creating the record.
source
create_user(client::Client, first_name, last_name, username, password)::String

Create a User via POST /user/. Admin-only. Returns the new user id. Raises ClientError with code "CONFLICT" when username is already taken.

source
DearDiary.update_user — Function
update_user(id::AbstractString, first_name::Optional{AbstractString}, last_name::Optional{AbstractString}, password::Optional{AbstractString}, is_admin::Optional{Bool})::Type{<:UpsertResult}

Update a User.

Arguments

  • id::AbstractString: The id of the user to update.
  • first_name::Optional{AbstractString}: The new first name of the user.
  • last_name::Optional{AbstractString}: The new last name of the user.
  • password::Optional{AbstractString}: The new password of the user.
  • is_admin::Optional{Bool}: The new admin status of the user.

Returns

An UpsertResult. Updated if the record was successfully updated (or no fields were changed), Unprocessable if the user does not exist, the update would demote the seeded default user, or a constraint is violated, and Error if an error occurred while updating the record.

source
update_user(client::Client, id::AbstractString; first_name=nothing, last_name=nothing, password=nothing, is_admin=nothing)::Nothing

Patch a User via PATCH /user/{id}. Any keyword left as nothing is left untouched server-side. The viewer must be id or an admin.

source
DearDiary.delete_user — Function
delete_user(id::AbstractString)::Bool

Delete a User. Also deletes all associated UserPermission. The seeded default user is never deleted; the call returns false instead.

Arguments

  • id::AbstractString: The id of the user to delete.

Returns

true if the record was successfully deleted, false otherwise.

source
delete_user(client::Client, id::AbstractString)::Nothing

Delete a User (and its UserPermission rows) via DELETE /user/{id}. The viewer must be id or an admin. The seeded default user cannot be removed; the server refuses with ClientError "SERVER_ERROR".

source

Permissions

DearDiary.get_userpermission — Function
get_userpermission(user_id::AbstractString, project_id::AbstractString)::Optional{UserPermission}

Get a UserPermission by User id and Project IDs.

Arguments

  • user_id::AbstractString: The id of the user.
  • project_id::AbstractString: The id of the project.

Returns

A UserPermission object. If the record does not exist, return nothing.

source
get_userpermission(client::Client, user_id::AbstractString, project_id::AbstractString)::Optional{UserPermission}

Fetch the UserPermission row tying user_id to project_id via GET /userpermission/user/{user_id}/project/{project_id}. Returns nothing when the server replies 404 and raises ClientError for other failures. Admin-only route.

source
DearDiary.get_userpermissions — Function
get_userpermissions(::Type{<:Project}, project_id::AbstractString)::Array{UserPermission,1}

List every UserPermission record granting access to the given Project.

Arguments

  • ::Type{<:Project}: Dispatch tag selecting the project-scoped listing.
  • project_id::AbstractString: The project whose members are being listed.

Returns

An array of UserPermission records (possibly empty).

source
get_userpermissions(::Type{<:User}, user_id::AbstractString)::Array{UserPermission,1}

List every UserPermission record held by the given User.

Arguments

  • ::Type{<:User}: Dispatch tag selecting the user-scoped listing.
  • user_id::AbstractString: The user whose project memberships are being listed.

Returns

An array of UserPermission records (possibly empty).

source
get_userpermissions(client::Client, ::Type{User}, user_id::AbstractString)::Array{UserPermission,1}

List every UserPermission that grants user_id access to some project, via GET /user/{user_id}/permissions. The viewer must be user_id or an admin.

source
get_userpermissions(client::Client, ::Type{Project}, project_id::AbstractString)::Array{UserPermission,1}

List every UserPermission row granting access to project_id, via GET /project/{project_id}/members. Requires ReadPermission on the project.

source
DearDiary.create_userpermission — Function
create_userpermission(user_id::AbstractString, project_id::AbstractString, create_permission::Bool, read_permission::Bool, update_permission::Bool, delete_permission::Bool)::NamedTuple{id::Optional{String},status::DataType}

Create a UserPermission.

Arguments

  • user_id::AbstractString: The id of the user.
  • project_id::AbstractString: The id of the project.
  • create_permission::Bool: Whether the user has create permission.
  • read_permission::Bool: Whether the user has read permission.
  • update_permission::Bool: Whether the user has update permission.
  • delete_permission::Bool: Whether the user has delete permission.

Returns

  • The created userpermission ID. If an error occurs, nothing is returned.
  • An UpsertResult. Created if the record was successfully created, Duplicate if the record already exists, Unprocessable if the record violates a constraint, and Error if an error occurred while creating the record.
source
create_userpermission(client::Client, user_id, project_id, create, read, update, delete)::String

Insert a UserPermission row via POST /userpermission/user/{user_id}/project/{project_id}. Admin-only. Returns the new permission id.

source
DearDiary.update_userpermission — Function
update_userpermission(id::AbstractString, create_permission::Optional{Bool}, read_permission::Optional{Bool}, update_permission::Optional{Bool}, delete_permission::Optional{Bool})::Type{<:UpsertResult}

Update a UserPermission.

Arguments

  • id::AbstractString: The id of the user permission to update.
  • create_permission::Optional{Bool}: The new create permission.
  • read_permission::Optional{Bool}: The new read permission.
  • update_permission::Optional{Bool}: The new update permission.
  • delete_permission::Optional{Bool}: The new delete permission.

Returns

An UpsertResult. Updated if the record was successfully updated (or no fields were changed), Unprocessable if the record does not exist or violates a constraint, and Error if an error occurred while updating the record.

source
update_userpermission(client::Client, id::AbstractString; create_permission=nothing, read_permission=nothing, update_permission=nothing, delete_permission=nothing)::Nothing

Patch a UserPermission row via PATCH /userpermission/{id}. Any keyword left as nothing is left untouched server-side. Admin-only.

source
DearDiary.delete_userpermission — Function
delete_userpermission(id::AbstractString)::Bool

Delete a UserPermission.

Arguments

  • id::AbstractString: The id of the user permission to delete.

Returns

true if the record was successfully deleted, false otherwise.

source
delete_userpermission(client::Client, id::AbstractString)::Nothing

Delete a UserPermission row via DELETE /userpermission/{id}. Admin-only. Raises ClientError on failure.

source
DearDiary.has_permission — Function
has_permission(permission::UserPermission, ::Type{<:PermissionAction})::Bool

Return whether permission grants the given PermissionAction on its Project.

Arguments

  • permission::UserPermission: The user permission record.
  • ::Type{<:PermissionAction}: The CRUD action being requested, passed as a type tag.

Returns

true if the action is allowed by the permission, false otherwise.

source