Skip to content
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

feat: change user permissions #39

Merged
merged 3 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/routers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from schemas import (
UserBalance,
UserModel,
HiddenUserModel,
UserTotalExpenses,
UserTotalReplenishments,
UserHistory,
Expand All @@ -39,8 +40,11 @@ def check_authentication(authenticated: bool = Depends(is_user_authenticated)):
return authenticated


@router.get("/", response_model=Page[UserModel])
def read_users(db: Session = Depends(get_db)) -> Page[UserModel]:
@router.get("/", response_model=Page[HiddenUserModel])
def read_users(
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user),
) -> Page[HiddenUserModel]:
return paginate(db, select(User))


Expand Down
1 change: 1 addition & 0 deletions src/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .user import (
BaseUser,
UserModel,
HiddenUserModel,
UserTotalExpenses,
UserTotalReplenishments,
UserHistory,
Expand Down
7 changes: 7 additions & 0 deletions src/schemas/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ class UserModel(BaseUser):
picture: Optional[str]


class HiddenUserModel(BaseModel):
id: int
first_name: str
last_name: str
picture: Optional[str]


class UserTotalExpenses(BaseModel):
amount: float
percentage_increase: float
Expand Down
9 changes: 4 additions & 5 deletions src/services/expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,10 @@ def validate_expense_update(
detail="You are not a user of the group specified to update expenses!",
)
if db_user_group.status == GroupStatusEnum.INACTIVE:
if group_id != expense.group_id:
raise HTTPException(
status_code=status.HTTP_405_METHOD_NOT_ALLOWED,
detail="The user is not active in group specified to update expenses!",
)
raise HTTPException(
status_code=status.HTTP_405_METHOD_NOT_ALLOWED,
detail="The user is not active in group specified to update expenses!",
)
try:
db.query(CategoryGroup).filter_by(
category_id=expense.category_id,
Expand Down
2 changes: 0 additions & 2 deletions tests/test_endpoints/test_user_e.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ def setUp(self) -> None:
self.users_data = [
{
"id": self.first_user.id,
"login": self.first_user.login,
"first_name": self.first_user.first_name,
"last_name": self.first_user.last_name,
"picture": self.first_user.picture,
},
{
"id": self.second_user.id,
"login": self.second_user.login,
"first_name": self.second_user.first_name,
"last_name": self.second_user.last_name,
"picture": self.second_user.picture,
Expand Down
Loading