Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

refactor(ui): remove obsolete resource access routes

Max86818384743d
diff --git a/tests/test_instance_authorization.py b/tests/test_instance_authorization.py
index 697e6ee80..27fafb4a5 100644
--- a/tests/test_instance_authorization.py
+++ b/tests/test_instance_authorization.py
@@ -108,7 +108,6 @@ def test_http_policy_is_role_only_and_unknown_api_routes_fail_closed() -> None:
for method, path in (("GET", "/api/future-owner-capability"), ("POST", "/api/control")):
assert http_authorization_policy(method, path).minimum_role == "owner"
- assert http_authorization_policy("GET", "/api/org/context").minimum_role == "viewer"
assert http_authorization_policy("GET", "/show/ses-1/").minimum_role == "viewer"
diff --git a/tests/test_ui_resource_access_api.py b/tests/test_ui_resource_access_api.py
deleted file mode 100644
index 62bcce071..000000000
--- a/tests/test_ui_resource_access_api.py
+++ /dev/null
@@ -1,156 +0,0 @@
-from __future__ import annotations
-
-from config import paths
-from storage import resource_access_service
-from storage.db import get_cached_sqlite_engine
-from storage.migrations import run_migrations
-from tests.ui_server_test_helpers import _save_config
-from tests.ui_server_test_helpers import csrf_headers, remote_session_cookie
-from vibe import remote_access
-from vibe.ui_server import app
-
-
-def _organization_cookie(config, *, instance_role: str = "viewer") -> str:
- return remote_session_cookie(
- config,
- "member-1",
- session_claims={
- "vibe_instance_id": "inst_123",
- "vibe_instance_role": instance_role,
- "vibe_instance_access_source": "organization_group",
- "vibe_organization_id": "org-1",
- "vibe_organization_member_id": "organization-member-1",
- "vibe_organization_role": "admin",
- "vibe_group_ids": ["group-engineering"],
- "vibe_membership_version": "membership-v2",
- },
- )
-
-
-def _external_guest_cookie(config, *, instance_role: str = "viewer") -> str:
- return remote_session_cookie(
- config,
- "guest-1",
- session_claims={
- "vibe_instance_id": "inst_123",
- "vibe_instance_role": instance_role,
- "vibe_instance_access_source": "email",
- },
- )
-
-
-def _seed_organization_policy() -> None:
- paths.ensure_data_dirs()
- run_migrations()
- engine = get_cached_sqlite_engine()
- with engine.begin() as connection:
- resource_access_service.ensure_resource_policy(
- connection,
- resource_kind="agent",
- resource_id="agent-1",
- organization_id="org-1",
- owner_user_id="owner-1",
- access_level="scope",
- group_ids=["group-engineering"],
- policy_revision=2,
- last_applied_control_plane_revision=2,
- )
-
-
-def test_organization_context_and_policy_routes_use_signed_cookie_claims(monkeypatch, tmp_path) -> None:
- monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
- config = _save_config(tmp_path)
- _seed_organization_policy()
- client = app.test_client()
- client.set_cookie(
- remote_access.SESSION_COOKIE_NAME,
- _organization_cookie(config, instance_role="editor"),
- domain="alex.avibe.bot",
- )
-
- context = client.get("/api/org/context", base_url="https://alex.avibe.bot")
- groups = client.get("/api/org/groups", base_url="https://alex.avibe.bot")
- policies = client.get("/api/resource-policies?kind=agent", base_url="https://alex.avibe.bot")
-
- assert context.status_code == 200
- assert context.get_json()["instance_role"] == "editor"
- assert context.get_json()["organization"] == {
- "id": "org-1",
- "member_id": "organization-member-1",
- "role": "admin",
- "group_ids": ["group-engineering"],
- "membership_version": "membership-v2",
- }
- assert groups.get_json() == {"groups": [{"id": "group-engineering", "name": None, "archived_at": None}]}
- assert policies.status_code == 200
- assert policies.get_json()["policies"] == [
- {
- "resource_kind": "agent",
- "resource_id": "agent-1",
- "access_level": "scope",
- "owner_user_id": "owner-1",
- "organization_id": "org-1",
- "group_ids": ["group-engineering"],
- "policy_revision": 2,
- "last_applied_control_plane_revision": 2,
- "can_use": True,
- "can_manage": False,
- }
- ]
-
-
-def test_organization_policy_put_does_not_create_local_revision(monkeypatch, tmp_path) -> None:
- monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
- config = _save_config(tmp_path)
- _seed_organization_policy()
- client = app.test_client()
- client.set_cookie(
- remote_access.SESSION_COOKIE_NAME,
- _organization_cookie(config, instance_role="owner"),
- domain="alex.avibe.bot",
- )
- monkeypatch.setattr(
- remote_access,
- "sync_resource_acl_once",
- lambda *_args, **_kwargs: {"ok": True, "organizations": [{"organization_id": "org-1"}]},
- )
-
- response = client.put(
- "/api/resource-policies/agent/agent-1",
- json={"access_level": "public", "group_ids": []},
- headers=csrf_headers(client, "https://alex.avibe.bot"),
- base_url="https://alex.avibe.bot",
- )
-
- assert response.status_code == 409
- assert response.get_json()["error"] == "resource_acl_control_plane_required"
- engine = get_cached_sqlite_engine()
- with engine.connect() as connection:
- policy = resource_access_service.get_resource_policy("agent", "agent-1", connection=connection)
- assert policy is not None
- assert policy["access_level"] == "scope"
- assert policy["policy_revision"] == 2
-
-
-def test_external_guest_cannot_update_an_organization_policy(monkeypatch, tmp_path) -> None:
- monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
- config = _save_config(tmp_path)
- _seed_organization_policy()
- client = app.test_client()
- client.set_cookie(
- remote_access.SESSION_COOKIE_NAME,
- _external_guest_cookie(config, instance_role="owner"),
- domain="alex.avibe.bot",
- )
-
- response = client.put(
- "/api/resource-policies/agent/agent-1",
- json={"access_level": "public", "group_ids": []},
- headers=csrf_headers(client, "https://alex.avibe.bot"),
- base_url="https://alex.avibe.bot",
- )
-
- assert response.status_code == 404
- assert response.get_json()["error"] == "resource_not_found"
diff --git a/vibe/authorization.py b/vibe/authorization.py
index 69e455650..1ed264adb 100644
--- a/vibe/authorization.py
+++ b/vibe/authorization.py
@@ -343,8 +343,6 @@ _VIEWER_HTTP_RULES = tuple(
r"^/api/events$",
r"^/api/inbox$",
r"^/api/media/[^/]+(?:/meta)?$",
- r"^/api/org/(?:context|groups)$",
- r"^/api/resource-policies$",
r"^/api/permissions$",
r"^/api/permissions/resources/[^/]+/[^/]+/access$",
r"^/api/show-pages$",
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index b5f257662..5bcd7c631 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -6985,233 +6985,6 @@ def _remote_resource_access_context():
)
-def _resource_policy_api_payload(policy: dict[str, Any], user_context: Any, connection: Any) -> dict[str, Any]:
- from storage import resource_access_service
-
- can_manage = resource_access_service.can_manage_resource_acl(
- user_context,
- policy["resource_kind"],
- policy["resource_id"],
- connection=connection,
- )
- group_ids = policy.get("group_ids") or []
- if not can_manage:
- group_ids = sorted(set(group_ids).intersection(user_context.group_ids or set()))
- return {
- "resource_kind": policy["resource_kind"],
- "resource_id": policy["resource_id"],
- "access_level": policy["access_level"],
- "owner_user_id": policy.get("owner_user_id"),
- "organization_id": policy.get("organization_id"),
- "group_ids": group_ids,
- "policy_revision": policy.get("policy_revision"),
- "last_applied_control_plane_revision": policy.get("last_applied_control_plane_revision"),
- "can_use": resource_access_service.can_use_resource(
- user_context,
- policy["resource_kind"],
- policy["resource_id"],
- connection=connection,
- ),
- "can_manage": can_manage,
- }
-
-
[email protected]("/api/org/context", methods=["GET"])
-def organization_context_get():
- _config, _payload, user_context = _remote_resource_access_context()
- if user_context is None:
- return jsonify({"error": "remote_access_context_required"}), 401
- organization = None
- if user_context.is_active_organization_member:
- organization = {
- "id": user_context.organization_id,
- "member_id": user_context.organization_member_id,
- "role": user_context.organization_role,
- "group_ids": sorted(user_context.group_ids or []),
- "membership_version": user_context.membership_version,
- }
- response = jsonify(
- {
- "user": {"sub": user_context.subject, "email": user_context.email},
- "instance_id": _payload.get("vibe_instance_id", _payload.get("instance_id")),
- "organization": organization,
- "instance_role": user_context.instance_role,
- "instance_access_source": user_context.instance_access_source,
- }
- )
- response.headers["Cache-Control"] = "no-store, private"
- response.headers["Vary"] = "Cookie"
- return response
-
-
[email protected]("/api/org/groups", methods=["GET"])
-def organization_groups_get():
- _config, _payload, user_context = _remote_resource_access_context()
- if user_context is None:
- return jsonify({"error": "remote_access_context_required"}), 401
- if not user_context.is_active_organization_member:
- return jsonify({"error": "organization_context_required"}), 403
- # The frozen device protocol carries group IDs but no mutable group metadata.
- # These are signed current-member groups, not an authorization cache; a later
- # metadata endpoint can enrich names and archived state without affecting ACL
- # evaluation.
- response = jsonify(
- {
- "groups": [
- {"id": group_id, "name": None, "archived_at": None}
- for group_id in sorted(user_context.group_ids or [])
- ]
- }
- )
- response.headers["Cache-Control"] = "no-store, private"
- response.headers["Vary"] = "Cookie"
- return response
-
-
[email protected]("/api/resource-policies", methods=["GET"])
-def resource_policies_get():
- from storage import resource_access_service
-
- _config, _payload, user_context = _remote_resource_access_context()
- if user_context is None:
- return jsonify({"error": "remote_access_context_required"}), 401
- resource_kind = request.args.get("kind")
- if resource_kind and resource_kind not in resource_access_service.RESOURCE_KINDS:
- return jsonify({"error": "invalid_resource_kind"}), 422
- engine = _projects_engine()
- try:
- with engine.connect() as connection:
- if user_context.is_active_organization_member:
- policies = resource_access_service.list_resource_policies(
- resource_kind=resource_kind,
- organization_id=user_context.organization_id,
- connection=connection,
- )
- elif user_context.subject:
- policies = resource_access_service.list_resource_policies(
- resource_kind=resource_kind,
- owner_user_id=user_context.subject,
- connection=connection,
- )
- else:
- policies = []
- serialized = [
- _resource_policy_api_payload(policy, user_context, connection)
- for policy in policies
- if resource_access_service.can_use_resource(
- user_context,
- policy["resource_kind"],
- policy["resource_id"],
- connection=connection,
- )
- or resource_access_service.can_manage_resource_acl(
- user_context,
- policy["resource_kind"],
- policy["resource_id"],
- connection=connection,
- )
- ]
- finally:
- engine.dispose()
- response = jsonify({"policies": serialized})
- response.headers["Cache-Control"] = "no-store, private"
- response.headers["Vary"] = "Cookie"
- return response
-
-
[email protected]("/api/resource-policies/<resource_kind>/<resource_id>", methods=["PUT"])
-def resource_policy_put(resource_kind: str, resource_id: str):
- from storage import resource_access_service
- from vibe import remote_access
-
- config, _payload, user_context = _remote_resource_access_context()
- if user_context is None:
- return jsonify({"error": "remote_access_context_required"}), 401
- if resource_kind not in resource_access_service.RESOURCE_KINDS:
- return jsonify({"error": "invalid_resource_kind"}), 422
- body = request.json or {}
- if not isinstance(body, dict):
- return jsonify({"error": "invalid_request"}), 422
-
- engine = _projects_engine()
- try:
- with engine.connect() as connection:
- policy = resource_access_service.get_resource_policy(
- resource_kind,
- resource_id,
- connection=connection,
- )
- if policy is None:
- return jsonify({"error": "resource_not_found"}), 404
- if policy.get("organization_id"):
- # Resource existence is hidden from non-member callers and from
- # callers whose Organization membership does not match the
- # resource's owning Organization; surface not_found in either
- # case so the existence of an unrelated Organization's policy
- # is not leaked.
- if (
- not user_context.is_active_organization_member
- or user_context.organization_id != policy.get("organization_id")
- ):
- return jsonify({"error": "resource_not_found"}), 404
- if not resource_access_service.can_manage_resource_acl(
- user_context,
- resource_kind,
- resource_id,
- connection=connection,
- ):
- return jsonify({"error": "resource_acl_forbidden"}), 403
-
- try:
- access_level, group_ids = resource_access_service.normalize_policy_request(
- body.get("access_level"),
- body.get("group_ids", []),
- policy.get("organization_id"),
- )
- except resource_access_service.ResourceAccessError as exc:
- return jsonify({"error": exc.code}), 422
-
- if policy.get("organization_id"):
- # Desired organization ACLs are written by the hosted resource API.
- # This local route only reconciles an intent before returning state;
- # it never invents a local revision that could overwrite a newer one.
- sync = remote_access.sync_resource_acl_once(config, organization_id=str(policy["organization_id"]))
- if not sync.get("ok"):
- return jsonify({"error": sync.get("error") or "resource_acl_sync_failed", "sync": sync}), 503
- with engine.connect() as connection:
- refreshed = resource_access_service.get_resource_policy(
- resource_kind,
- resource_id,
- connection=connection,
- )
- if refreshed is None:
- return jsonify({"error": "resource_not_found"}), 404
- serialized = _resource_policy_api_payload(refreshed, user_context, connection)
- if refreshed["access_level"] == access_level and sorted(refreshed.get("group_ids") or []) == sorted(group_ids):
- return jsonify({"policy": serialized, "sync": sync})
- return jsonify(
- {
- "error": "resource_acl_control_plane_required",
- "policy": serialized,
- "sync": sync,
- }
- ), 409
-
- with engine.begin() as connection:
- updated = resource_access_service.update_local_non_organization_policy(
- connection,
- resource_kind=resource_kind,
- resource_id=resource_id,
- access_level=access_level,
- group_ids=group_ids,
- updated_by_user_id=user_context.subject,
- )
- serialized = _resource_policy_api_payload(updated, user_context, connection)
- return jsonify({"policy": serialized})
- finally:
- engine.dispose()
-
-
@app.route("/api/cloud/token", methods=["GET"])
def api_cloud_token():
"""Broker a short-lived avibe.bot user token for the workbench frontend so it