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.
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.
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.
DearDiary.get_users — Function
get_users(client::Client)::Array{UserResponse,1}List every user via GET /user/. Admin-only route; the returned UserResponse values never include password hashes.
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,
nothingis returned. - An
UpsertResult.Createdif the record was successfully created,Duplicateif the record already exists,Unprocessableif the record violates a constraint, andErrorif an error occurred while creating the record.
create_user(client::Client, first_name, last_name, username, password)::StringCreate a User via POST /user/. Admin-only. Returns the new user id. Raises ClientError with code "CONFLICT" when username is already taken.
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.
update_user(client::Client, id::AbstractString; first_name=nothing, last_name=nothing, password=nothing, is_admin=nothing)::NothingPatch a User via PATCH /user/{id}. Any keyword left as nothing is left untouched server-side. The viewer must be id or an admin.
DearDiary.delete_user — Function
delete_user(id::AbstractString)::BoolDelete 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.
delete_user(client::Client, id::AbstractString)::NothingDelete 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".
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.
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.
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).
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).
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.
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.
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,
nothingis returned. - An
UpsertResult.Createdif the record was successfully created,Duplicateif the record already exists,Unprocessableif the record violates a constraint, andErrorif an error occurred while creating the record.
create_userpermission(client::Client, user_id, project_id, create, read, update, delete)::StringInsert a UserPermission row via POST /userpermission/user/{user_id}/project/{project_id}. Admin-only. Returns the new permission id.
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.
update_userpermission(client::Client, id::AbstractString; create_permission=nothing, read_permission=nothing, update_permission=nothing, delete_permission=nothing)::NothingPatch a UserPermission row via PATCH /userpermission/{id}. Any keyword left as nothing is left untouched server-side. Admin-only.
DearDiary.delete_userpermission — Function
delete_userpermission(id::AbstractString)::BoolDelete a UserPermission.
Arguments
id::AbstractString: The id of the user permission to delete.
Returns
true if the record was successfully deleted, false otherwise.
delete_userpermission(client::Client, id::AbstractString)::NothingDelete a UserPermission row via DELETE /userpermission/{id}. Admin-only. Raises ClientError on failure.
DearDiary.has_permission — Function
has_permission(permission::UserPermission, ::Type{<:PermissionAction})::BoolReturn 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.