refactor: clean up code formatting and improve readability across multiple files
This commit is contained in:
@@ -229,9 +229,7 @@ async def _fetch_agent_events(
|
||||
return list(await session.exec(statement))
|
||||
|
||||
|
||||
async def _require_user_context(
|
||||
session: AsyncSession, user: User | None
|
||||
) -> OrganizationContext:
|
||||
async def _require_user_context(session: AsyncSession, user: User | None) -> OrganizationContext:
|
||||
if user is None:
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
|
||||
member = await get_active_membership(session, user)
|
||||
|
||||
@@ -33,6 +33,7 @@ from app.models.gateways import Gateway
|
||||
from app.models.users import User
|
||||
from app.schemas.board_group_memory import BoardGroupMemoryCreate, BoardGroupMemoryRead
|
||||
from app.schemas.pagination import DefaultLimitOffsetPage
|
||||
from app.services.mentions import extract_mentions, matches_agent_mention
|
||||
from app.services.organizations import (
|
||||
OrganizationContext,
|
||||
is_org_admin,
|
||||
@@ -40,7 +41,6 @@ from app.services.organizations import (
|
||||
member_all_boards_read,
|
||||
member_all_boards_write,
|
||||
)
|
||||
from app.services.mentions import extract_mentions, matches_agent_mention
|
||||
|
||||
router = APIRouter(tags=["board-group-memory"])
|
||||
|
||||
|
||||
@@ -83,9 +83,7 @@ async def list_board_groups(
|
||||
ctx=Depends(require_org_member),
|
||||
) -> DefaultLimitOffsetPage[BoardGroupRead]:
|
||||
if member_all_boards_read(ctx.member):
|
||||
statement = select(BoardGroup).where(
|
||||
col(BoardGroup.organization_id) == ctx.organization.id
|
||||
)
|
||||
statement = select(BoardGroup).where(col(BoardGroup.organization_id) == ctx.organization.id)
|
||||
else:
|
||||
accessible_boards = select(Board.board_group_id).where(
|
||||
board_access_filter(ctx.member, write=False)
|
||||
|
||||
@@ -129,7 +129,9 @@ async def _apply_board_update(
|
||||
) -> Board:
|
||||
updates = payload.model_dump(exclude_unset=True)
|
||||
if "gateway_id" in updates:
|
||||
await _require_gateway(session, updates["gateway_id"], organization_id=board.organization_id)
|
||||
await _require_gateway(
|
||||
session, updates["gateway_id"], organization_id=board.organization_id
|
||||
)
|
||||
if "board_group_id" in updates and updates["board_group_id"] is not None:
|
||||
await _require_board_group(
|
||||
session,
|
||||
|
||||
@@ -11,9 +11,10 @@ from app.core.auth import AuthContext, get_auth_context, get_auth_context_option
|
||||
from app.db.session import get_session
|
||||
from app.models.agents import Agent
|
||||
from app.models.boards import Board
|
||||
from app.models.organizations import Organization
|
||||
from app.models.tasks import Task
|
||||
from app.models.users import User
|
||||
from app.models.organizations import Organization
|
||||
from app.services.admin_access import require_admin
|
||||
from app.services.organizations import (
|
||||
OrganizationContext,
|
||||
ensure_member_for_user,
|
||||
@@ -21,7 +22,6 @@ from app.services.organizations import (
|
||||
is_org_admin,
|
||||
require_board_access,
|
||||
)
|
||||
from app.services.admin_access import require_admin
|
||||
|
||||
|
||||
def require_admin_auth(auth: AuthContext = Depends(get_auth_context)) -> AuthContext:
|
||||
|
||||
@@ -21,7 +21,6 @@ from app.integrations.openclaw_gateway_protocol import (
|
||||
)
|
||||
from app.models.boards import Board
|
||||
from app.models.gateways import Gateway
|
||||
from app.services.organizations import OrganizationContext, require_board_access
|
||||
from app.schemas.common import OkResponse
|
||||
from app.schemas.gateway_api import (
|
||||
GatewayCommandsResponse,
|
||||
@@ -32,6 +31,7 @@ from app.schemas.gateway_api import (
|
||||
GatewaySessionsResponse,
|
||||
GatewaysStatusResponse,
|
||||
)
|
||||
from app.services.organizations import OrganizationContext, require_board_access
|
||||
|
||||
router = APIRouter(prefix="/gateways", tags=["gateways"])
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ from app.models.organizations import Organization
|
||||
from app.models.users import User
|
||||
from app.schemas.organizations import (
|
||||
OrganizationActiveUpdate,
|
||||
OrganizationBoardAccessRead,
|
||||
OrganizationCreate,
|
||||
OrganizationInviteAccept,
|
||||
OrganizationInviteCreate,
|
||||
@@ -31,7 +32,6 @@ from app.schemas.organizations import (
|
||||
OrganizationMemberAccessUpdate,
|
||||
OrganizationMemberRead,
|
||||
OrganizationMemberUpdate,
|
||||
OrganizationBoardAccessRead,
|
||||
OrganizationRead,
|
||||
OrganizationUserRead,
|
||||
)
|
||||
@@ -39,8 +39,8 @@ from app.schemas.pagination import DefaultLimitOffsetPage
|
||||
from app.services.organizations import (
|
||||
OrganizationContext,
|
||||
accept_invite,
|
||||
apply_invite_to_member,
|
||||
apply_invite_board_access,
|
||||
apply_invite_to_member,
|
||||
apply_member_access_update,
|
||||
get_active_membership,
|
||||
get_member,
|
||||
@@ -298,9 +298,7 @@ async def create_org_invite(
|
||||
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY)
|
||||
|
||||
existing_user = (
|
||||
await session.exec(
|
||||
select(User).where(func.lower(col(User.email)) == email)
|
||||
)
|
||||
await session.exec(select(User).where(func.lower(col(User.email)) == email))
|
||||
).first()
|
||||
if existing_user is not None:
|
||||
existing_member = await get_member(
|
||||
@@ -380,7 +378,9 @@ async def accept_org_invite(
|
||||
if invite is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
||||
if invite.invited_email and auth.user.email:
|
||||
if normalize_invited_email(invite.invited_email) != normalize_invited_email(auth.user.email):
|
||||
if normalize_invited_email(invite.invited_email) != normalize_invited_email(
|
||||
auth.user.email
|
||||
):
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN)
|
||||
|
||||
existing = await get_member(
|
||||
|
||||
@@ -20,9 +20,7 @@ class OrganizationBoardAccess(SQLModel, table=True):
|
||||
)
|
||||
|
||||
id: UUID = Field(default_factory=uuid4, primary_key=True)
|
||||
organization_member_id: UUID = Field(
|
||||
foreign_key="organization_members.id", index=True
|
||||
)
|
||||
organization_member_id: UUID = Field(foreign_key="organization_members.id", index=True)
|
||||
board_id: UUID = Field(foreign_key="boards.id", index=True)
|
||||
can_read: bool = Field(default=True)
|
||||
can_write: bool = Field(default=False)
|
||||
|
||||
@@ -20,9 +20,7 @@ class OrganizationInviteBoardAccess(SQLModel, table=True):
|
||||
)
|
||||
|
||||
id: UUID = Field(default_factory=uuid4, primary_key=True)
|
||||
organization_invite_id: UUID = Field(
|
||||
foreign_key="organization_invites.id", index=True
|
||||
)
|
||||
organization_invite_id: UUID = Field(foreign_key="organization_invites.id", index=True)
|
||||
board_id: UUID = Field(foreign_key="boards.id", index=True)
|
||||
can_read: bool = Field(default=True)
|
||||
can_write: bool = Field(default=False)
|
||||
|
||||
@@ -79,9 +79,7 @@ async def set_active_organization(
|
||||
user: User,
|
||||
organization_id: UUID,
|
||||
) -> OrganizationMember:
|
||||
member = await get_member(
|
||||
session, user_id=user.id, organization_id=organization_id
|
||||
)
|
||||
member = await get_member(session, user_id=user.id, organization_id=organization_id)
|
||||
if member is None:
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="No org access")
|
||||
if user.active_organization_id != organization_id:
|
||||
@@ -199,8 +197,7 @@ async def ensure_member_for_user(session: AsyncSession, user: User) -> Organizat
|
||||
now = utcnow()
|
||||
member_count = (
|
||||
await session.exec(
|
||||
select(func.count())
|
||||
.where(col(OrganizationMember.organization_id) == org.id)
|
||||
select(func.count()).where(col(OrganizationMember.organization_id) == org.id)
|
||||
)
|
||||
).one()
|
||||
is_first = int(member_count or 0) == 0
|
||||
|
||||
Reference in New Issue
Block a user