Skip to main content

UserRegistry

Struct UserRegistry 

Source
pub struct UserRegistry { /* private fields */ }
Expand description

Daemon-level user registry with persistent storage.

Manages user lifecycle, token auth, room membership, and global status. All mutations auto-save to {data_dir}/users.json.

Implementations§

Source§

impl UserRegistry

Source

pub fn new(data_dir: PathBuf) -> UserRegistry

Create a new empty registry backed by the given directory.

Does not load from disk — use UserRegistry::load for that.

Source

pub fn load(data_dir: PathBuf) -> Result<UserRegistry, String>

Load an existing registry from {data_dir}/users.json.

Returns a fresh empty registry if the file does not exist. Returns an error only if the file exists but cannot be parsed.

Source

pub fn save(&self) -> Result<(), String>

Persist the registry to {data_dir}/users.json.

Source

pub fn register_user(&mut self, username: &str) -> Result<&User, String>

Register a new user. Fails if the username is already taken.

Source

pub fn remove_user(&mut self, username: &str) -> Result<bool, String>

Remove a user and all their tokens.

Returns true if the user existed.

Source

pub fn get_user(&self, username: &str) -> Option<&User>

Look up a user by username.

Source

pub fn list_users(&self) -> Vec<&User>

List all registered users.

Source

pub fn issue_token(&mut self, username: &str) -> Result<String, String>

Issue a new token for a registered user.

The user must already be registered via [register_user].

Source

pub fn validate_token(&self, token: &str) -> Option<&str>

Validate a token, returning the associated username.

Source

pub fn revoke_token(&mut self, token: &str) -> Result<bool, String>

Revoke a specific token. Returns true if it existed.

Source

pub fn revoke_user_tokens(&mut self, username: &str) -> Result<usize, String>

Revoke all tokens for a user. Returns the number revoked.

Source

pub fn join_room(&mut self, username: &str, room_id: &str) -> Result<(), String>

Record that a user has joined a room.

Source

pub fn leave_room( &mut self, username: &str, room_id: &str, ) -> Result<bool, String>

Record that a user has left a room.

Source

pub fn set_status( &mut self, username: &str, status: Option<String>, ) -> Result<(), String>

Set or clear a user’s global status.

Pass None to clear. Status applies across all rooms the user is in.

Source

pub fn data_path(&self) -> PathBuf

Return the path to the backing JSON file.

Source

pub fn join_team( &mut self, team_name: &str, username: &str, ) -> Result<bool, String>

Add a user to a team. Creates the team if it does not exist.

Returns true if the user was newly added (not already a member).

Source

pub fn leave_team( &mut self, team_name: &str, username: &str, ) -> Result<bool, String>

Remove a user from a team. Deletes the team if it becomes empty.

Returns true if the user was a member and was removed.

Source

pub fn get_team(&self, team_name: &str) -> Option<&Team>

Look up a team by name.

Source

pub fn list_teams(&self) -> Vec<&Team>

List all teams.

Source

pub fn team_names(&self) -> Vec<String>

Return all team names (sorted). Used for TUI autocomplete.

Source

pub fn expand_team_mention(&self, mention: &str) -> Option<Vec<String>>

Expand a mention to team members if it matches a team name.

Returns None if the mention is not a team. Returns Some(members) if it is — the caller can then treat each member as an individual mention.

Source

pub fn has_token_for_user(&self, username: &str) -> bool

Return true if any token is currently associated with username.

Used by daemon auth to detect username collisions without scanning the entire token map externally.

Source

pub fn register_user_idempotent(&mut self, username: &str) -> Result<(), String>

Register a user if not already registered; no-op if already present.

Unlike [register_user], this is idempotent — calling it for an existing user does not return an error. Used by daemon auth so that users from a previous session (loaded from users.json) can rejoin without triggering a registration error.

Source

pub fn token_snapshot(&self) -> HashMap<String, String>

Return a snapshot of all current token → username mappings.

Used at daemon startup to seed the in-memory TokenMap from persisted registry data so existing tokens remain valid without a fresh join.

Source

pub fn import_token( &mut self, username: &str, token: &str, ) -> Result<(), String>

Insert a pre-existing token UUID for a registered user.

Unlike [issue_token], which generates a fresh UUID, this method preserves the caller-supplied token string. It is intended for migration paths that read legacy token files (e.g. /tmp/room-*-*.token) and want existing clients to remain valid without a forced re-join.

Returns Ok(()) immediately if the token is already present in the registry (idempotent). Returns an error if username is not registered.

Trait Implementations§

Source§

impl Debug for UserRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,