Repository navigation
Feat/super admin approval #15
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| from typing import Any | ||
|
|
||
| from redis.asyncio import Redis | ||
|
|
||
| from app.core.constant import RedisKey | ||
|
|
||
|
|
||
|
|
||
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,36 @@ | ||
| from fastapi import APIRouter, Depends | ||
|
|
||
| from app.container import Container, get_container | ||
| from app.deps.staff_auth import get_current_staff_user | ||
| from app.schema.request.staff.notifications import MarkStaffNotificationsReadRequest | ||
| from app.schema.response.staff.notifications import ( | ||
| StaffNotificationListResponse, | ||
| ) | ||
| from db.generated.models import StaffUser | ||
|
|
||
|
|
||
| router = APIRouter(prefix="/notifications", tags=["staff-notifications"]) | ||
|
|
||
|
|
||
| @router.get("", response_model=StaffNotificationListResponse) | ||
| async def list_staff_notifications( | ||
| current_staff_user: StaffUser = Depends(get_current_staff_user), | ||
| container: Container = Depends(get_container), | ||
| ) -> StaffNotificationListResponse: | ||
| notifications = await container.staff_notifications_service.list_notifications( | ||
| staff_user_id=current_staff_user.id | ||
| ) | ||
| return StaffNotificationListResponse.from_models(notifications) | ||
|
|
||
|
|
||
| @router.post("/read", response_model=StaffNotificationListResponse) | ||
| async def mark_staff_notifications_as_read( | ||
| req: MarkStaffNotificationsReadRequest, | ||
| current_staff_user: StaffUser = Depends(get_current_staff_user), | ||
| container: Container = Depends(get_container), | ||
| ) -> StaffNotificationListResponse: | ||
| notifications = await container.staff_notifications_service.mark_many_as_read( | ||
| notification_ids=req.notification_ids, | ||
| staff_user_id=current_staff_user.id, | ||
| ) | ||
| return StaffNotificationListResponse.from_models(notifications) |
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,81 @@ | ||
| from typing import Literal | ||
| from uuid import UUID | ||
|
|
||
| from fastapi import APIRouter, Depends, Query | ||
|
|
||
| from app.container import Container, get_container | ||
| from app.deps.staff_auth import ( | ||
| get_current_staff_user, | ||
| require_multi_team_lead_staff, | ||
| ) | ||
| from app.schema.request.staff.uploads import ( | ||
| CreateUploadRequestRequest, | ||
| RejectUploadRequestRequest, | ||
| ) | ||
| from app.schema.response.staff.uploads import ( | ||
| UploadRequestListResponse, | ||
| UploadRequestSchema, | ||
| ) | ||
| from db.generated.models import StaffUser, UploadRequestStatus | ||
|
|
||
|
|
||
| router = APIRouter(prefix="/uploads", tags=["staff-uploads"]) | ||
|
|
||
|
|
||
| @router.post("/request", response_model=UploadRequestSchema) | ||
| async def create_upload_request( | ||
| req: CreateUploadRequestRequest, | ||
| current_staff_user: StaffUser = Depends(get_current_staff_user), | ||
| container: Container = Depends(get_container), | ||
| ) -> UploadRequestSchema: | ||
| upload_request = await container.upload_requests_service.create_request( | ||
| event_id=req.event_id, | ||
| photos=req.to_inputs(), | ||
| requested_by=current_staff_user, | ||
| ) | ||
| return UploadRequestSchema.from_models(upload_request.request, upload_request.photos) | ||
|
|
||
|
|
||
| @router.get("", response_model=UploadRequestListResponse) | ||
| async def list_upload_requests( | ||
| scope: Literal["my", "all"] = Query(default="my"), | ||
| status: UploadRequestStatus | None = Query(default=None), | ||
| current_staff_user: StaffUser = Depends(get_current_staff_user), | ||
| container: Container = Depends(get_container), | ||
| ) -> UploadRequestListResponse: | ||
| requests = await container.upload_requests_service.list_requests( | ||
| current_staff_user=current_staff_user, | ||
| scope=scope, | ||
| status=status.value if status is not None else None, | ||
| ) | ||
| return UploadRequestListResponse.from_models( | ||
| [(item.request, item.photos) for item in requests] | ||
| ) | ||
|
|
||
|
|
||
| @router.post("/{request_id}/approve", response_model=UploadRequestSchema) | ||
| async def approve_upload_request( | ||
| request_id: UUID, | ||
| current_staff_user: StaffUser = Depends(require_multi_team_lead_staff), | ||
| container: Container = Depends(get_container), | ||
| ) -> UploadRequestSchema: | ||
| upload_request = await container.upload_requests_service.approve_request( | ||
| request_id=request_id, | ||
| approved_by=current_staff_user, | ||
| ) | ||
| return UploadRequestSchema.from_models(upload_request.request, upload_request.photos) | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. those three are the same endpoint with one filter approaved and rejected and pending |
||
|
|
||
| @router.post("/{request_id}/reject", response_model=UploadRequestSchema) | ||
| async def reject_upload_request( | ||
| request_id: UUID, | ||
| req: RejectUploadRequestRequest, | ||
| current_staff_user: StaffUser = Depends(require_multi_team_lead_staff), | ||
| container: Container = Depends(get_container), | ||
| ) -> UploadRequestSchema: | ||
| upload_request = await container.upload_requests_service.reject_request( | ||
| request_id=request_id, | ||
| approved_by=current_staff_user, | ||
| reason=req.reason, | ||
| ) | ||
| return UploadRequestSchema.from_models(upload_request.request, upload_request.photos) | ||
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,13 @@ | ||
| from dataclasses import dataclass | ||
| from datetime import datetime | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class UploadPhotoInput: | ||
| drive_file_id: str | ||
| file_name: str | ||
| mime_type: str | ||
| size_bytes: int | ||
| taken_at: datetime | None | ||
| day_number: int | None | ||
| visibility: str |
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,7 @@ | ||
| from uuid import UUID | ||
|
|
||
| from pydantic import BaseModel, Field | ||
|
|
||
|
|
||
| class MarkStaffNotificationsReadRequest(BaseModel): | ||
| notification_ids: list[UUID] = Field(min_length=1, max_length=100) |
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,86 @@ | ||
| from datetime import datetime | ||
| from pathlib import PurePath | ||
| from typing import ClassVar | ||
|
|
||
| from pydantic import BaseModel, Field, field_validator, model_validator | ||
| from uuid import UUID | ||
|
|
||
| from app.schema.dto.staff.uploads import UploadPhotoInput | ||
|
|
||
|
|
||
| MAX_UPLOAD_BATCH_SIZE = 20 | ||
| MAX_UPLOAD_PHOTO_SIZE_BYTES = 20 * 1024 * 1024 | ||
| ALLOWED_IMAGE_MIME_TYPES: dict[str, tuple[str, ...]] = { | ||
| "image/jpeg": (".jpg", ".jpeg"), | ||
| "image/png": (".png",), | ||
| "image/webp": (".webp",), | ||
| } | ||
|
|
||
|
|
||
| class CreateUploadRequestPhotoRequest(BaseModel): | ||
| drive_file_id: str = Field(min_length=1, max_length=255) | ||
| file_name: str = Field(min_length=1, max_length=255) | ||
| mime_type: str | ||
| size_bytes: int = Field(gt=0, le=MAX_UPLOAD_PHOTO_SIZE_BYTES) | ||
| taken_at: datetime | None = None | ||
| day_number: int | None = None | ||
| visibility: str = "private" | ||
|
|
||
| _allowed_mime_types: ClassVar[dict[str, tuple[str, ...]]] = ALLOWED_IMAGE_MIME_TYPES | ||
|
|
||
| @field_validator("drive_file_id", "file_name", mode="before") | ||
| @classmethod | ||
| def _strip_required_text(cls, value: object) -> object: | ||
| if isinstance(value, str): | ||
| return value.strip() | ||
| return value | ||
|
|
||
| @field_validator("mime_type") | ||
| @classmethod | ||
| def _validate_mime_type(cls, value: str) -> str: | ||
| normalized_value = value.strip().lower() | ||
| if normalized_value not in cls._allowed_mime_types: | ||
| raise ValueError("Unsupported image format") | ||
| return normalized_value | ||
|
|
||
| @field_validator("visibility") | ||
| @classmethod | ||
| def _validate_visibility(cls, value: str) -> str: | ||
| normalized_value = value.strip().lower() | ||
| if normalized_value not in {"private", "public"}: | ||
| raise ValueError("visibility must be either 'private' or 'public'") | ||
| return normalized_value | ||
|
|
||
| @model_validator(mode="after") | ||
| def _validate_file_extension(self) -> "CreateUploadRequestPhotoRequest": | ||
| extension = PurePath(self.file_name).suffix.lower() | ||
| allowed_extensions = self._allowed_mime_types[self.mime_type] | ||
| if extension not in allowed_extensions: | ||
| raise ValueError("file_name extension does not match mime_type") | ||
| return self | ||
|
|
||
| def to_input(self) -> UploadPhotoInput: | ||
| return UploadPhotoInput( | ||
| drive_file_id=self.drive_file_id, | ||
| file_name=self.file_name, | ||
| mime_type=self.mime_type, | ||
| size_bytes=self.size_bytes, | ||
| taken_at=self.taken_at, | ||
| day_number=self.day_number, | ||
| visibility=self.visibility, | ||
| ) | ||
|
|
||
|
|
||
| class CreateUploadRequestRequest(BaseModel): | ||
| event_id: UUID | ||
| photos: list[CreateUploadRequestPhotoRequest] = Field( | ||
| min_length=1, | ||
| max_length=MAX_UPLOAD_BATCH_SIZE, | ||
| ) | ||
|
|
||
| def to_inputs(self) -> list[UploadPhotoInput]: | ||
| return [photo.to_input() for photo in self.photos] | ||
|
|
||
|
|
||
| class RejectUploadRequestRequest(BaseModel): | ||
| reason: str | None = None |
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,36 @@ | ||
| from datetime import datetime | ||
| from typing import Any | ||
| from uuid import UUID | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
||
| from db.generated.models import StaffNotification | ||
|
|
||
|
|
||
| class StaffNotificationSchema(BaseModel): | ||
| id: UUID | ||
| type: str | ||
| payload: dict[str, Any] | ||
| read_at: datetime | None | ||
| created_at: datetime | ||
|
|
||
| @classmethod | ||
| def from_model(cls, notification: StaffNotification) -> "StaffNotificationSchema": | ||
| return cls( | ||
| id=notification.id, | ||
| type=notification.type, | ||
| payload=notification.payload, | ||
| read_at=notification.read_at, | ||
| created_at=notification.created_at, | ||
| ) | ||
|
|
||
|
|
||
| class StaffNotificationListResponse(BaseModel): | ||
| items: list[StaffNotificationSchema] | ||
|
|
||
| @classmethod | ||
| def from_models( | ||
| cls, | ||
| notifications: list[StaffNotification], | ||
| ) -> "StaffNotificationListResponse": | ||
| return cls(items=[StaffNotificationSchema.from_model(item) for item in notifications]) |
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.
validate the format and size for the pic