Expand description
Database-level helpers for groups, memberships, and invitations.
Higher-level permission checks live in crate::library; this module
exposes the typed DB primitives those checks (and the route handlers)
build on.
Structs§
- Group
Member View - One member of a group with the user’s display fields denormalised in.
- Group
View - Public view of a group, returned by listing/get endpoints.
Enums§
- Group
Role - Role a user has within a group.
- Invitation
Status - Status of a group invitation.
Functions§
- create_
group - Insert a new group plus the creator’s owner membership in one transaction.
Returns the newly assigned
group_id. - delete_
group - Delete a group. Cascades remove memberships, pending invitations and any group-owned saved notecards / renders.
- get_
for_ user - Fetch a single group view if the user is a member of it.
- list_
for_ user - List the groups the user belongs to, with their role in each.
- list_
members - List all members of a group, joined with the users table for display fields.
- lookup_
role - Look up the role a given user has in a given group, or
Noneif they are not a member. - rename_
group - Rename a group, bumping
updated_at. - require_
exists - Verify that the given group exists. Returns
Error::NotFoundif not. - try_
leave - Atomically remove the calling user from a group. If the caller is an
owner the delete only fires when at least one other owner exists, so
two concurrent leaves by the last two owners cannot both succeed.
Returns
trueif a row was deleted. - try_
promote_ member_ to_ owner - Atomically promote a member of a group to owner. Returns
trueif a row was updated,falseif the user is not a member or is already an owner. The role guard lives in the WHERE clause so concurrent role changes cannot turn this into a downgrade. - try_
remove_ non_ owner - Atomically remove a non-owner member from a group. The role guard is
folded into the WHERE clause so a member promoted to owner between an
upstream check and this call is never silently kicked. Returns
trueif a row was deleted. - try_
self_ demote_ owner - Atomically demote the calling user from owner to member, refusing the
demote if it would leave the group with zero owners. The owner-count
check is folded into the WHERE clause so two concurrent self-demotes
cannot both observe
owners == 2and both succeed. Returnstrueif a row was updated.