PhoenixKitStaff.Staff.Memberships (PhoenixKitStaff v0.6.0)

Copy Markdown View Source

Team membership management — the person ↔ team join.

Extracted from PhoenixKitStaff.Staff, which keeps thin delegators (Staff.add_team_person/2, Staff.list_team_memberships/1, …) so the public API is unchanged. Rosters exclude trashed people — the membership row survives a trash, so restoring the person brings them back.

Summary

Functions

Adds a person to a team and broadcasts :team_person_added.

All memberships a given person belongs to, with team and department preloaded.

Memberships on a given team, preloaded with staff_person and user. Trashed people are excluded — the team roster shows the active members only (the membership row survives a trash, so restore brings them back).

People not already on this team (for the add-to-team picker).

Removes a team membership (by struct or by team/person uuids) and broadcasts :team_person_removed.

Functions

add_team_person(team_uuid, staff_person_uuid)

@spec add_team_person(UUIDv7.t() | String.t(), UUIDv7.t() | String.t()) ::
  {:ok, PhoenixKitStaff.Schemas.TeamMembership.t()}
  | {:error,
     :person_trashed
     | Ecto.Changeset.t(PhoenixKitStaff.Schemas.TeamMembership.t())}

Adds a person to a team and broadcasts :team_person_added.

Refuses a trashed person with {:error, :person_trashed} — the add-to-team picker (people_not_on_team/1) already excludes trashed people, so this guards the direct-API path (mirrors the rest of the soft-delete hardening).

list_memberships_for_person(person_uuid)

@spec list_memberships_for_person(UUIDv7.t() | String.t()) :: [
  PhoenixKitStaff.Schemas.TeamMembership.t()
]

All memberships a given person belongs to, with team and department preloaded.

list_team_memberships(team_uuid)

@spec list_team_memberships(UUIDv7.t() | String.t()) :: [
  PhoenixKitStaff.Schemas.TeamMembership.t()
]

Memberships on a given team, preloaded with staff_person and user. Trashed people are excluded — the team roster shows the active members only (the membership row survives a trash, so restore brings them back).

people_not_on_team(team_uuid)

@spec people_not_on_team(UUIDv7.t() | String.t()) :: [
  PhoenixKitStaff.Schemas.Person.t()
]

People not already on this team (for the add-to-team picker).

remove_team_person(tm)

Removes a team membership (by struct or by team/person uuids) and broadcasts :team_person_removed.

remove_team_person(team_uuid, staff_person_uuid)

@spec remove_team_person(UUIDv7.t() | String.t(), UUIDv7.t() | String.t()) ::
  {:ok, PhoenixKitStaff.Schemas.TeamMembership.t()}
  | {:error, Ecto.Changeset.t(PhoenixKitStaff.Schemas.TeamMembership.t())}
  | {:error, :not_found}