Artifact d139c0b7d0708b4444480f4c9e1d80da365362ac8f83715262ccb07e0ef667c5:
- File
hub/users.go
— part of check-in
[a8e62ce82d]
at
2026-05-04 20:53:37
on branch feat/130-hub-setusercaps
— feat(hub): SetUserCaps + Config.NobodyCaps for unauth-clone hubs
Adds Repo.SetUserCaps(login, caps) and a Hub delegate, wrapping libfossil's Repo.SetCaps. Lets consumers grant or change caps on existing users without leaving the hub package — primarily for the common bones case where the libfossil-pre-populated 'nobody' user needs 'gio' to allow unauthenticated clone/pull/push.
Also adds Config.NobodyCaps so the typical setup is one declarative field instead of a manual SetUserCaps call after every NewHub. NobodyCaps is applied at bootstrap by calling SetUserCaps("nobody", v) internally — no method-body duplication. Empty NobodyCaps leaves nobody at whatever libfossil set it to (idempotent re-open path preserves prior caps, doesn't overwrite).
Tests: - TestRepo_SetUserCaps_RoundTrip — set + read back - TestRepo_SetUserCaps_RejectsEmptyLogin - TestNewHub_NobodyCaps_AppliedAtBootstrap — Config field works - TestNewHub_NobodyCaps_Idempotent — re-running with same caps OK - TestNewHub_NobodyCaps_EmptyDoesNotOverwrite — empty doesn't reset
Closes #130 (user: [email protected], size: 1001) [annotate] [blame] [check-ins using] [more...]
package hub // User describes a fossil user on the hub repo. type User struct { Login string Caps string } // AddUser creates a fossil user. Returns an error if Login is empty or the // user already exists. func (h *Hub) AddUser(u User) error { return h.repo.AddUser(u) } // GetUser returns the user with the given login. Returns an error if no // such user exists. func (h *Hub) GetUser(login string) (User, error) { return h.repo.GetUser(login) } // HasUser reports whether a user with the given login exists. func (h *Hub) HasUser(login string) bool { return h.repo.HasUser(login) } // ListUsers returns all users on the hub. func (h *Hub) ListUsers() ([]User, error) { return h.repo.ListUsers() } // RemoveUser deletes the user with the given login. func (h *Hub) RemoveUser(login string) error { return h.repo.RemoveUser(login) } // SetUserCaps replaces the caps string on an existing user. func (h *Hub) SetUserCaps(login, caps string) error { return h.repo.SetUserCaps(login, caps) }