Users and permissions
Users
DearDiary.get_user — Function
get_user(username::AbstractString)::Optional{User}Get an User by username.
Arguments
username::AbstractString: The username of the user to query.
Returns
An User object. If the record does not exist, return nothing.
get_user(id::Integer)::Optional{User}Get an User by id.
Arguments
id::Integer: The id of the user to query.
Returns
An User object. If the record does not exist, return nothing.
get_user(client::Client, id::Integer)::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 overload (get_user(name)) has no REST counterpart; iterate get_users and filter when a username lookup is required.
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{<:Int64},status::DataType}Create an 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)::Int64Create 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::Integer, first_name::Optional{AbstractString}, last_name::Optional{AbstractString}, password::Optional{AbstractString}, is_admin::Optional{Bool})::Type{<:UpsertResult}Update an User.
Arguments
id::Integer: 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 record violates a constraint or if no fields were provided to update, and Error if an error occurred while updating the record.
update_user(client::Client, id::Integer; 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::Integer)::BoolDelete an User. Also deletes all associated UserPermission.
Arguments
id::Integer: The id of the user to delete.
Returns
true if the record was successfully deleted, false otherwise.
delete_user(client::Client, id::Integer)::NothingDelete a User via DELETE /user/{id}. The viewer must be id or an admin; the seeded default user cannot be removed (the server rejects the request).
Permissions
DearDiary.get_userpermission — Function
get_userpermission(user_id::Integer, project_id::Integer)::Optional{UserPermission}Get a UserPermission by User id and Project IDs.
Arguments
user_id::Integer: The id of the user.project_id::Integer: The id of the project.
Returns
A UserPermission object. If the record does not exist, return nothing.
get_userpermission(client::Client, user_id::Integer, project_id::Integer)::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::Integer)::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::Integer: The project whose members are being listed.
Returns
An array of UserPermission records (possibly empty).
get_userpermissions(::Type{<:User}, user_id::Integer)::Array{UserPermission,1}List every UserPermission record held by the given User.
Arguments
::Type{<:User}: Dispatch tag selecting the user-scoped listing.user_id::Integer: The user whose project memberships are being listed.
Returns
An array of UserPermission records (possibly empty).
get_userpermissions(client::Client, ::Type{User}, user_id::Integer)::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::Integer)::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::Integer, project_id::Integer, create_permission::Bool, read_permission::Bool, update_permission::Bool, delete_permission::Bool)::NamedTuple{id::Optional{<:Int64},status::DataType}Create a UserPermission.
Arguments
user_id::Integer: The id of the user.project_id::Integer: 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)::Int64Insert 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::Integer, create_permission::Optional{Bool}, read_permission::Optional{Bool}, update_permission::Optional{Bool}, delete_permission::Optional{Bool})::Type{<:UpsertResult}Update a UserPermission.
Arguments
id::Integer: 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 violates a constraint or if no fields were provided to update, and Error if an error occurred while updating the record.
update_userpermission(client::Client, id::Integer; 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::Integer)::BoolDelete a UserPermission.
Arguments
id::Integer: The id of the user permission to delete.
Returns
true if the record was successfully deleted, false otherwise.
delete_userpermission(client::Client, id::Integer)::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.