Skip to main content

Module groups

Module groups 

Source
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§

GroupMemberView
One member of a group with the user’s display fields denormalised in.
GroupView
Public view of a group, returned by listing/get endpoints.

Enums§

GroupRole
Role a user has within a group.
InvitationStatus
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 None if they are not a member.
rename_group
Rename a group, bumping updated_at.
require_exists
Verify that the given group exists. Returns Error::NotFound if 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 true if a row was deleted.
try_promote_member_to_owner
Atomically promote a member of a group to owner. Returns true if a row was updated, false if 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 true if 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 == 2 and both succeed. Returns true if a row was updated.