-
Notifications
You must be signed in to change notification settings - Fork 136
feat: permission elevation foundation #1740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tomkis
wants to merge
8
commits into
main
Choose a base branch
from
feat/1734-permission-elevation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b1394ce
feat: permission elevation foundation
tomkis 40e7b96
docs: better docs
tomkis 9916c08
fix: code review comments
tomkis 352be38
feat: user listing
tomkis 2964ff2
feat: filter by email
tomkis 2e2a0bb
feat: CLI for permission elevation
tomkis 7dab197
docs: update CLI reference
tomkis 9472470
fix: code review comments
tomkis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
apps/agentstack-server/src/agentstack_server/api/routes/users.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # Copyright 2025 © BeeAI a Series of LF Projects, LLC | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import logging | ||
| from typing import Annotated | ||
| from uuid import UUID | ||
|
|
||
| from fastapi import APIRouter, Depends, HTTPException, status | ||
| from pydantic import BaseModel | ||
|
|
||
| from agentstack_server.api.dependencies import UserServiceDependency, authorized_user | ||
| from agentstack_server.domain.models.permissions import AuthorizedUser | ||
| from agentstack_server.domain.models.user import UserRole | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| router = APIRouter(tags=["users"]) | ||
|
|
||
|
|
||
| class ChangeRoleRequest(BaseModel): | ||
| new_role: UserRole | ||
|
|
||
|
|
||
| class ChangeRoleResponse(BaseModel): | ||
| user_id: UUID | ||
| new_role: UserRole | ||
| role_version: int | ||
|
|
||
|
|
||
| @router.put("/users/{user_id}/role", response_model=ChangeRoleResponse) | ||
| async def change_user_role( | ||
| user_id: UUID, | ||
| request: ChangeRoleRequest, | ||
| user: Annotated[AuthorizedUser, Depends(authorized_user)], | ||
| user_service: UserServiceDependency, | ||
| ) -> ChangeRoleResponse: | ||
| if not user.user.role == UserRole.ADMIN: | ||
| raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Admin permission required") | ||
|
|
||
| if user_id == user.user.id: | ||
| raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Cannot change own role") | ||
|
|
||
| updated_user = await user_service.change_role(user_id=user_id, new_role=request.new_role) | ||
tomkis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return ChangeRoleResponse( | ||
| user_id=updated_user.id, | ||
| new_role=updated_user.role, | ||
| role_version=updated_user.role_version, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...nfrastructure/persistence/migrations/alembic/versions/4jowyo7q9m66_add_role_versioning.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Copyright 2025 © BeeAI a Series of LF Projects, LLC | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """add role versioning to users | ||
|
|
||
| Revision ID: 4jowyo7q9m66 | ||
| Revises: ef8769062e65 | ||
| Create Date: 2025-12-18 14:00:00.000000 | ||
|
|
||
| """ | ||
|
|
||
| from collections.abc import Sequence | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| revision: str = "4jowyo7q9m66" | ||
| down_revision: str | None = "ef8769062e65" | ||
| branch_labels: str | Sequence[str] | None = None | ||
| depends_on: str | Sequence[str] | None = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| """Upgrade schema.""" | ||
| op.add_column("users", sa.Column("role_version", sa.Integer(), nullable=False, server_default="1")) | ||
| op.add_column("users", sa.Column("role_updated_at", sa.DateTime(timezone=True), nullable=True)) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| """Downgrade schema.""" | ||
| op.drop_column("users", "role_updated_at") | ||
| op.drop_column("users", "role_version") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.