-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
119 additions
and
39 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import os | ||
|
||
|
||
SESSION_SECRET_KEY: str = os.getenv("SESSION_SECRET_KEY") |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
|
||
REPORT_ADDITIONAL_INFO_MAX_LENGTH = 1024 |
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,10 @@ | ||
import enum | ||
|
||
|
||
@enum.unique | ||
class ReportReason(enum.StrEnum): | ||
INAPPROPRIATE_BEHAVIOR = "inappropriate_behavior" | ||
INAPPROPRIATE_CONTENT = "inappropriate_content" | ||
FRAUD_OR_AD = "fraud_or_ad" | ||
UNDERAGE = "underage" | ||
OTHER = "other" |
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,12 @@ | ||
from mongoengine import ReferenceField, StringField, EnumField, BooleanField | ||
|
||
from models import BaseDocument | ||
from reports.enums import ReportReason | ||
|
||
|
||
class Report(BaseDocument): | ||
initiator = ReferenceField('User') | ||
respondent = ReferenceField('User') | ||
reason = EnumField(ReportReason) # type: ReportReason | ||
additional_info = StringField(required=False) # type: str | ||
opened = BooleanField(default=True) # type: bool |
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,15 @@ | ||
from fastapi import APIRouter | ||
|
||
from reports import service | ||
from reports.schemas import ReportIn | ||
from users.dependencies import CurrentActiveUser, get_active_completed_user | ||
|
||
|
||
router = APIRouter() | ||
|
||
|
||
@router.post("") | ||
def create_report(data: ReportIn, current_user: CurrentActiveUser): | ||
respondent = get_active_completed_user(data.respondent) | ||
new_report = service.create_report(current_user, respondent, data) | ||
return new_report |
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,11 @@ | ||
from pydantic import BaseModel, constr | ||
|
||
from models import PydanticObjectId | ||
from reports.config import REPORT_ADDITIONAL_INFO_MAX_LENGTH | ||
from reports.enums import ReportReason | ||
|
||
|
||
class ReportIn(BaseModel): | ||
respondent: PydanticObjectId | ||
reason: ReportReason | ||
additional_info: constr(max_length=REPORT_ADDITIONAL_INFO_MAX_LENGTH) | None |
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,9 @@ | ||
from reports.models import Report | ||
from reports.schemas import ReportIn | ||
from users.models import User | ||
|
||
|
||
def create_report(initiator: User, respondent: User, report_data_in: ReportIn) -> Report: | ||
report = Report(initiator=initiator, respondent=respondent, **report_data_in.model_dump(exclude={'respondent'})) | ||
report.save() | ||
return report |
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
Empty file.
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,10 @@ | ||
from reports import service | ||
from reports.schemas import ReportIn | ||
|
||
|
||
def test_create_report(report_factory, user_factory): | ||
initiator, respondent = user_factory.create_batch(size=2, ) | ||
report = report_factory.build(initiator=initiator, respondent=respondent) | ||
report_in = ReportIn(respondent=respondent.id, reason=report.reason, additional_info=report.additional_info) | ||
|
||
assert service.create_report(initiator, respondent, report_in) |
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