Skip to content

Commit 6711dc4

Browse files
committed
stable
1 parent 2e69902 commit 6711dc4

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

fastapi-postgres/common/db_model/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ async def add_or_find_update(
8686

8787
if add_or_id != "add" and not isinstance(body, list):
8888
db_obj = await cls.get_by_id(_id=add_or_id, **kwargs)
89-
if db_obj and (not user_auth or user_auth.id == db_obj.teacher_id):
89+
90+
if db_obj and (not user_auth or user_auth.id == getattr(db_obj, conf.AUTH_PARENT_FIELD)):
9091
set_elements_by_dict(db_obj, body, exclude_items=["id"], **kwargs)
9192
else:
9293
ErrorService.error_400(details="not found")
@@ -99,8 +100,8 @@ async def add_or_find_update(
99100
db_obj = cls.table()
100101
set_elements_by_dict(db_obj, body, **kwargs)
101102

102-
if user_auth:
103-
setattr(db_obj, "teacher_id", user_auth.id)
103+
if user_auth and hasattr(db_obj, conf.AUTH_PARENT_FIELD):
104+
setattr(db_obj, conf.AUTH_PARENT_FIELD, user_auth.id)
104105

105106
await cls.add_update(row=db_obj, **kwargs)
106107
return db_obj

fastapi-postgres/service/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async def jwt_required(token: str = Depends(oauth2_scheme)) -> str:
1616
return user
1717

1818

19-
def user_filtered_query(field_name: str = "teacher_id"):
19+
def user_filtered_query(field_name: str = conf.AUTH_PARENT_FIELD):
2020
def _inject_user_filter(
2121
filter_query: FilterQuery = Body(default=FilterQuery()),
2222
user_auth: TeacherModel.table = Depends(jwt_required),

0 commit comments

Comments
 (0)