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.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(auth): separate binding from enabled access
cyh9985d6f1b6d5
diff --git a/config/v2_settings.py b/config/v2_settings.pyindex 7ebbffaa4..b21d2c220 100644--- a/config/v2_settings.py+++ b/config/v2_settings.py@@ -589,12 +589,15 @@ class SettingsStore:def is_bound_user(self, user_id: str, platform: Optional[str] = None) -> bool:if platform:- user = self.settings.users.get(self._user_key(user_id, platform))- return user is not None and user.enabled+ return self._user_key(user_id, platform) in self.settings.usersif user_id in self.settings.users:- return self.settings.users[user_id].enabled+ return Truesuffix = f"{SCOPED_KEY_SEP}{user_id}"- return any(key.endswith(suffix) and user.enabled for key, user in self.settings.users.items())+ return any(key.endswith(suffix) for key in self.settings.users.keys())++ def is_enabled_user(self, user_id: str, platform: Optional[str] = None) -> bool:+ user = self.get_user(user_id, platform=platform)+ return user is not None and user.enableddef is_admin(self, user_id: str, platform: Optional[str] = None) -> bool:if platform:@@ -610,14 +613,21 @@ class SettingsStore:return Falsedef has_any_admin(self, platform: Optional[str] = None) -> bool:- """Return True if at least one admin exists."""+ """Return True if at least one admin record exists."""+ if platform:+ prefix = f"{platform}{SCOPED_KEY_SEP}"+ return any(u.is_admin for key, u in self.settings.users.items() if key.startswith(prefix))+ return any(u.is_admin for u in self.settings.users.values())++ def has_enabled_admin(self, platform: Optional[str] = None) -> bool:+ """Return True if at least one enabled admin exists."""if platform:prefix = f"{platform}{SCOPED_KEY_SEP}"return any(u.enabled and u.is_admin for key, u in self.settings.users.items() if key.startswith(prefix))return any(u.enabled and u.is_admin for u in self.settings.users.values())def get_admins(self, platform: Optional[str] = None) -> Dict[str, UserSettings]:- """Return all admin users."""+ """Return enabled admin users."""if platform:prefix = f"{platform}{SCOPED_KEY_SEP}"return {@@ -664,7 +674,7 @@ class SettingsStore:return False, False# Auto-admin for first user- is_admin = not self.has_any_admin(platform=platform)+ is_admin = not self.has_enabled_admin(platform=platform)# Create useruser = UserSettings(diff --git a/core/auth.py b/core/auth.pyindex f7c89dd92..c60a1557c 100644--- a/core/auth.py+++ b/core/auth.py@@ -52,6 +52,18 @@ def _is_admin_protected(action: str) -> bool:return False+def _is_enabled_user(store: object, user_id: str, platform: str | None) -> bool:+ if hasattr(store, "is_enabled_user"):+ try:+ return store.is_enabled_user(user_id, platform=platform)+ except TypeError:+ return store.is_enabled_user(user_id)+ try:+ return store.is_bound_user(user_id, platform=platform)+ except TypeError:+ return store.is_bound_user(user_id)++@dataclassclass AuthResult:"""Result of an authorization check."""@@ -105,11 +117,7 @@ def check_auth(if is_dm:if action in BIND_EXEMPT_COMMANDS:return AuthResult(allowed=True, is_dm=True)- try:- is_bound = store.is_bound_user(user_id, platform=platform)- except TypeError:- is_bound = store.is_bound_user(user_id)- if not is_bound:+ if not _is_enabled_user(store, user_id, platform):return AuthResult(allowed=False, denial="unbound_dm", is_dm=True)# DM users skip channel authorizationelse:@@ -129,11 +137,7 @@ def check_auth(# with a denial type that maps to no message (silent ignore), so other# members' chatter does not trigger the bot or spam the channel.if getattr(ch, "require_bind", None):- try:- is_bound = store.is_bound_user(user_id, platform=platform)- except TypeError:- is_bound = store.is_bound_user(user_id)- if not is_bound:+ if not _is_enabled_user(store, user_id, platform):return AuthResult(allowed=False, denial="not_bound_channel", is_dm=False)# 3. Admin check for protected actionsdiff --git a/modules/settings_manager.py b/modules/settings_manager.pyindex 41bc6e9c9..d0511a80c 100644--- a/modules/settings_manager.py+++ b/modules/settings_manager.py@@ -141,6 +141,10 @@ class SettingsManager:"""Check whether a user is already bound."""return self.store.is_bound_user(str(user_id), platform=self.platform)+ def is_enabled_user(self, user_id: Union[int, str]) -> bool:+ """Check whether a bound user is enabled for access."""+ return self.store.is_enabled_user(str(user_id), platform=self.platform)+def bind_user_with_code(self,user_id: Union[int, str],@@ -562,6 +566,12 @@ class MultiSettingsManager:manager, raw = self._resolve(user_id)return manager.is_bound_user(raw)+ def is_enabled_user(self, user_id: Union[int, str], platform: Optional[str] = None) -> bool:+ if platform:+ return self.managers[platform].is_enabled_user(user_id)+ manager, raw = self._resolve(user_id)+ return manager.is_enabled_user(raw)+def bind_user_with_code(self,user_id: Union[int, str],diff --git a/tests/test_auth_pipeline.py b/tests/test_auth_pipeline.pyindex fc3286f7f..3316f9cc4 100644--- a/tests/test_auth_pipeline.py+++ b/tests/test_auth_pipeline.py@@ -20,13 +20,16 @@ class _Store:self.reload_calls += 1def is_bound_user(self, user_id: str) -> bool:+ return user_id in self._bound_users++ def is_enabled_user(self, user_id: str) -> bool:return user_id in self._bound_users and user_id not in self._disabled_usersdef has_any_admin(self) -> bool:return bool(self._admins)def is_admin(self, user_id: str) -> bool:- return user_id in self._admins+ return user_id in self._admins and user_id not in self._disabled_usersclass _SettingsManager:@@ -193,3 +196,21 @@ def test_admin_guard_denies_non_admin_for_auth_setup_callback():assert result.allowed is Falseassert result.denial == "not_admin"+++def test_admin_guard_stays_enabled_when_only_admin_is_disabled():+ store = _Store()+ store.settings.channels["C1"] = SimpleNamespace(enabled=True)+ store._admins.add("U-disabled-admin")+ store._disabled_users.add("U-disabled-admin")++ result = check_auth(+ user_id="U-anyone",+ channel_id="C1",+ is_dm=False,+ action="settings",+ store=store,+ )++ assert result.allowed is False+ assert result.denial == "not_admin"diff --git a/tests/test_sqlite_settings_store.py b/tests/test_sqlite_settings_store.pyindex 0abb752be..f0e53d75e 100644--- a/tests/test_sqlite_settings_store.py+++ b/tests/test_sqlite_settings_store.py@@ -59,7 +59,7 @@ def test_channel_require_bind_persists(tmp_path: Path) -> None:reloaded.close()-def test_is_bound_user_requires_enabled_user(tmp_path: Path) -> None:+def test_bound_and_enabled_user_checks_are_separate(tmp_path: Path) -> None:settings_path = tmp_path / "settings.json"store = SettingsStore(settings_path)store.set_users_for_platform(@@ -71,7 +71,9 @@ def test_is_bound_user_requires_enabled_user(tmp_path: Path) -> None:)assert store.is_bound_user("U-enabled", platform="slack") is True- assert store.is_bound_user("U-disabled", platform="slack") is False+ assert store.is_enabled_user("U-enabled", platform="slack") is True+ assert store.is_bound_user("U-disabled", platform="slack") is True+ assert store.is_enabled_user("U-disabled", platform="slack") is Falsestore.close()@@ -91,6 +93,7 @@ def test_admin_helpers_require_enabled_user(tmp_path: Path) -> None:assert store.is_admin("U-enabled-admin", platform="slack") is Trueassert store.is_admin("U-disabled-admin", platform="slack") is Falseassert store.has_any_admin(platform="slack") is True+ assert store.has_enabled_admin(platform="slack") is Trueassert set(store.get_admins(platform="slack")) == {"slack::U-enabled-admin"}store.update_user(@@ -99,7 +102,8 @@ def test_admin_helpers_require_enabled_user(tmp_path: Path) -> None:platform="slack",)- assert store.has_any_admin(platform="slack") is False+ assert store.has_any_admin(platform="slack") is True+ assert store.has_enabled_admin(platform="slack") is Falseassert store.get_admins(platform="slack") == {}finally:store.close()@@ -126,6 +130,27 @@ def test_bind_user_promotes_when_only_admin_is_disabled(tmp_path: Path) -> None:store.close()+def test_disabled_user_cannot_rebind_with_active_code(tmp_path: Path) -> None:+ settings_path = tmp_path / "settings.json"+ store = SettingsStore(settings_path)+ try:+ store.set_users_for_platform(+ "slack",+ {+ "U-disabled": UserSettings(display_name="Disabled", enabled=False),+ },+ )+ code = store.create_bind_code()++ success, is_admin = store.bind_user_with_code("U-disabled", "Rebound", code.code, platform="slack")++ assert success is False+ assert is_admin is False+ assert store.get_user("U-disabled", platform="slack").enabled is False+ finally:+ store.close()++def test_settings_manager_runtime_save_preserves_require_bind(tmp_path: Path, monkeypatch) -> None:settings_path = tmp_path / "settings.json"monkeypatch.setattr(paths, "ensure_data_dirs", lambda: None)diff --git a/ui/src/components/shared/RoutingConfigPanel.tsx b/ui/src/components/shared/RoutingConfigPanel.tsxindex 0ab5f68aa..dd6e73f27 100644--- a/ui/src/components/shared/RoutingConfigPanel.tsx+++ b/ui/src/components/shared/RoutingConfigPanel.tsx@@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';import clsx from 'clsx';import { Combobox } from '../ui/combobox';import { Input } from '@/components/ui/input';+import { Button } from '@/components/ui/button';import { BackendIcon } from '../visual';import { CompactSelect } from '../settings/SettingsPrimitives';import { modelOptionLabel } from '../../lib/backendModels';@@ -395,21 +396,23 @@ export const RoutingConfigPanel: React.FC<RoutingConfigPanelProps> = ({{segs.map((seg) => {const active = (seg.id === 'on') === on;return (- <button+ <Buttonkey={seg.id}type="button"+ variant="ghost"+ size="sm"role="radio"aria-checked={active}onClick={() => setBind(seg.id === 'on')}className={clsx(- 'flex-1 rounded-[4px] px-2.5 text-[12px] transition-colors',+ 'h-auto flex-1 rounded-[4px] px-2.5 text-[12px] shadow-none focus-visible:ring-1',active? 'border border-mint/30 bg-mint-soft font-bold text-mint': 'font-medium text-muted hover:text-foreground')}>{seg.label}- </button>+ </Button>);})}</div>diff --git a/vibe/api.py b/vibe/api.pyindex 817c41015..5ebbae0fd 100644--- a/vibe/api.py+++ b/vibe/api.py@@ -6793,7 +6793,7 @@ def auto_bind_wechat_user(user_id: str) -> dict:}config = load_config()- is_admin = not store.has_any_admin(platform=platform)+ is_admin = not store.has_enabled_admin(platform=platform)user = UserSettings(display_name=user_id,is_admin=is_admin,