Admin endpoint: POST /api/v1/admin/accounts for chart-of-accounts entries #29

Closed
opened 2026-06-06 13:15:08 +00:00 by padreug · 0 comments
Owner

Backend API stub for admin-driven chart-of-accounts editing from the LNbits UI. v1 scope: add only. Edit/rename/mark-closed are tracked separately.

Depends on fava_client.add_account gaining a target_file parameter (companion issue).

Work

  • Add to views_api.py near line 3601 (next to existing admin account-sync endpoint):
@libra_api_router.post("/api/v1/admin/accounts")
async def api_admin_add_chart_account(
    payload: dict,
    auth: AuthContext = Depends(require_super_user),
) -> dict:
    """Add a chart-of-accounts entry (super-user only)."""
    from .fava_client import get_fava_client
    name = payload["name"]
    currencies = payload.get("currencies") or ["EUR", "SATS", "USD"]
    fava = get_fava_client()
    await fava.add_account(
        account_name=name,
        currencies=currencies,
        target_file="accounts/chart.beancount",
        metadata={"added_by": auth.user_id[:8], "source": "admin-ui"},
    )
    from .account_sync import sync_single_account_from_beancount
    await sync_single_account_from_beancount(name)
    return {"success": True, "account_name": name}
  • Confirm require_super_user is the right guard (per ~/dev/shared/extensions/libra/CLAUDE.md: check_admin is wallet-key, check_super_user is instance super-user — this is the latter)
  • Validate name conforms to Beancount account naming (Assets:|Liabilities:|Equity:|Income:|Expenses: prefix, valid component chars)
  • Reject duplicate adds (the underlying fava write is idempotent but worth surfacing)

Acceptance

  • 403 for non-super-user
  • New open directive appears in /var/lib/fava/accounts/chart.beancount
  • Account becomes queryable in fava UI and via libra's get_all_accounts
  • Account is registered in libra DB via account_sync.sync_single_account_from_beancount

Plan reference: ~/.claude/plans/elegant-bubbling-frog.md section B.3.

Follow-up issue (not this one): admin UI frontend.

Backend API stub for admin-driven chart-of-accounts editing from the LNbits UI. v1 scope: **add only**. Edit/rename/mark-closed are tracked separately. Depends on `fava_client.add_account` gaining a `target_file` parameter (companion issue). ## Work - [ ] Add to `views_api.py` near line 3601 (next to existing admin account-sync endpoint): ```python @libra_api_router.post("/api/v1/admin/accounts") async def api_admin_add_chart_account( payload: dict, auth: AuthContext = Depends(require_super_user), ) -> dict: """Add a chart-of-accounts entry (super-user only).""" from .fava_client import get_fava_client name = payload["name"] currencies = payload.get("currencies") or ["EUR", "SATS", "USD"] fava = get_fava_client() await fava.add_account( account_name=name, currencies=currencies, target_file="accounts/chart.beancount", metadata={"added_by": auth.user_id[:8], "source": "admin-ui"}, ) from .account_sync import sync_single_account_from_beancount await sync_single_account_from_beancount(name) return {"success": True, "account_name": name} ``` - [ ] Confirm `require_super_user` is the right guard (per `~/dev/shared/extensions/libra/CLAUDE.md`: `check_admin` is wallet-key, `check_super_user` is instance super-user — this is the latter) - [ ] Validate name conforms to Beancount account naming (`Assets:|Liabilities:|Equity:|Income:|Expenses:` prefix, valid component chars) - [ ] Reject duplicate adds (the underlying fava write is idempotent but worth surfacing) ## Acceptance - 403 for non-super-user - New `open` directive appears in `/var/lib/fava/accounts/chart.beancount` - Account becomes queryable in fava UI and via libra's `get_all_accounts` - Account is registered in libra DB via `account_sync.sync_single_account_from_beancount` Plan reference: `~/.claude/plans/elegant-bubbling-frog.md` section B.3. Follow-up issue (not this one): admin UI frontend.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aiolabs/libra#29
No description provided.