-
-
Notifications
You must be signed in to change notification settings - Fork 194
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
allow accessing public project data #759
Merged
Merged
Changes from all commits
Commits
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
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -1,38 +1,58 @@ | ||
from typing import Optional | ||
from uuid import UUID | ||
|
||
from carbonserver.api.infra.repositories.repository_projects import ( | ||
SqlAlchemyRepository as ProjectRepository, | ||
) | ||
from carbonserver.api.infra.repositories.repository_projects_tokens import ( | ||
SqlAlchemyRepository as ProjectTokensRepository, | ||
) | ||
from carbonserver.api.infra.repositories.repository_users import ( | ||
SqlAlchemyRepository as UserRepository, | ||
) | ||
from carbonserver.api.schemas import User | ||
|
||
|
||
class AuthContext: | ||
|
||
def __init__( | ||
self, user_repository: UserRepository, token_repository: ProjectTokensRepository | ||
self, | ||
user_repository: UserRepository, | ||
token_repository: ProjectTokensRepository, | ||
project_repository: ProjectRepository, | ||
): | ||
self._user_repository = user_repository | ||
self._token_repository = token_repository | ||
self._project_repository = project_repository | ||
|
||
def isOperationAuthorizedOnOrg(self, organization_id, user): | ||
def isOperationAuthorizedOnOrg(self, organization_id, user: User): | ||
return self._user_repository.is_user_in_organization( | ||
organization_id=organization_id, user=user | ||
) | ||
|
||
def isOperationAuthorizedOnProject(self, project_id, user): | ||
def isOperationAuthorizedOnProject(self, project_id: UUID, user: User): | ||
return self._user_repository.is_user_authorized_on_project(project_id, user.id) | ||
|
||
def can_read_organization(self, organization_id, user): | ||
def can_read_project(self, project_id: UUID, user: Optional[User]): | ||
if self._project_repository.is_project_public(project_id): | ||
return True | ||
if user is None: | ||
raise Exception("Not authenticated") | ||
return self._user_repository.is_user_read_authorized_on_project( | ||
project_id, user.id | ||
) | ||
|
||
def can_read_organization(self, organization_id: UUID, user: User): | ||
return self._user_repository.is_user_in_organization( | ||
organization_id=organization_id, user=user | ||
) | ||
|
||
def can_write_organization(self, organization_id, user): | ||
def can_write_organization(self, organization_id: UUID, user: User): | ||
return self._user_repository.is_admin_in_organization( | ||
organization_id=organization_id, user=user | ||
) | ||
|
||
def can_create_run(self, experiment_id, user): | ||
def can_create_run(self, experiment_id: UUID, user: User): | ||
return self._user_repository.is_user_authorized_on_experiment( | ||
experiment_id, user.id | ||
) |
This file contains 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 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
30 changes: 30 additions & 0 deletions
30
...onserver/carbonserver/database/alembic/versions/202501_f3a10_add_public_tag_to_project.py
This file contains 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,30 @@ | ||
"""Add public tag to project | ||
|
||
Revision ID: f3a10c95079f | ||
Revises: 9d5ff5377b63 | ||
Create Date: 2025-01-14 22:01:12.694786 | ||
|
||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "f3a10c95079f" | ||
down_revision = "54d9cae546ad" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"projects", sa.Column("public", sa.Boolean(), server_default=sa.sql.False_()) | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("projects", "public") | ||
# ### end Alembic commands ### |
This file contains 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 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to know the full flow, why an exception instead of
return False
? It will be caught later somewhere?