Skip to content

Commit 2cf6598

Browse files
authored
fix:'createdAt' not returning (#48)
* Update activities_router.py * Remove useless code * Remove trophy API * Remove useless code * Clear useless commented code * Remove notification api
1 parent a6b161b commit 2cf6598

File tree

6 files changed

+29
-465
lines changed

6 files changed

+29
-465
lines changed

routers/activities_router.py

Lines changed: 2 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ async def read_activities(
269269
# User permission check
270270
if (
271271
"admin" not in user["per"]
272-
and "auditor" not in user["per"]
273272
and "department" not in user["per"]
274273
and mode == "campus"
275274
):
@@ -290,7 +289,7 @@ async def read_activities(
290289
# Read activities
291290
result = []
292291

293-
audit = "auditor" in user["per"] or "admin" in user["per"]
292+
audit = "admin" in user["per"]
294293

295294
pipeline = [
296295
{
@@ -486,6 +485,7 @@ async def read_activity(activity_oid: str, user=Depends(get_current_user)):
486485
"type": True,
487486
"special": True,
488487
"creator": True,
488+
"createdAt": True,
489489
"updatedAt": True,
490490
"registration": True,
491491
}
@@ -626,8 +626,6 @@ async def read_activity_user(
626626
if (
627627
"department" not in user["per"]
628628
and "admin" not in user["per"]
629-
and "auditor" not in user["per"]
630-
and "inspector" not in user["per"]
631629
and ("secretary" not in user["per"])
632630
and user["id"] != str(validate_object_id(uid))
633631
):
@@ -639,27 +637,6 @@ async def read_activity_user(
639637
return {"status": "ok", "code": 200, "data": activity[0]["members"][0]}
640638

641639

642-
@router.get("/{activity_oid}/member/{uid}/history")
643-
async def read_user_history(
644-
activity_oid: str, uid: str, user=Depends(get_current_user)
645-
):
646-
if (
647-
"department" not in user["per"]
648-
and "admin" not in user["per"]
649-
and "auditor" not in user["per"]
650-
and "inspector" not in user["per"]
651-
and ("secretary" not in user["per"])
652-
and user["id"] != str(validate_object_id(uid))
653-
):
654-
raise HTTPException(status_code=403, detail="Permission denined.")
655-
activity = await db.zvms.activities.find_one(
656-
{"_id": validate_object_id(activity_oid), "members._id": uid},
657-
{"members.$": 1, "_id": 0},
658-
)
659-
if not activity:
660-
raise HTTPException(status_code=404, detail="Activity not found")
661-
return {"status": "ok", "code": 200, "data": activity["members"][0]["history"]}
662-
663640

664641
@router.delete("/{activity_oid}/member/{uid}")
665642
async def user_activity_signoff(
@@ -738,55 +715,3 @@ async def delete_activity(activity_oid: str, user=Depends(compulsory_temporary_t
738715
"status": "ok",
739716
"code": 200,
740717
}
741-
742-
743-
@router.get("/{activity_oid}/ratings")
744-
async def get_activity_ratings(activity_oid: str, user=Depends(get_current_user)):
745-
"""
746-
Get activity ratings
747-
"""
748-
749-
if "admin" not in user["per"] and "department" not in user["per"] and "rating" not in user["elg"]:
750-
raise HTTPException(status_code=403, detail="Permission denied")
751-
752-
activity = await db.zvms.activities.find_one(
753-
{"_id": validate_object_id(activity_oid)}
754-
)
755-
756-
if not activity:
757-
raise HTTPException(status_code=404, detail="Activity not found")
758-
759-
if (
760-
user["id"] != activity["creator"]
761-
and "admin" not in user["per"]
762-
and "department" not in user["per"]
763-
):
764-
raise HTTPException(status_code=403, detail="Permission denied")
765-
766-
# Check the average rating for each int-typed field, and remain the original value for other fields
767-
768-
res = await db.zvms.ratings.find(
769-
{"activity_id": activity_oid}
770-
).to_list(None)
771-
772-
result = {}
773-
ratings = {}
774-
775-
for rating in res:
776-
rating["_id"] = str(rating["_id"])
777-
for key, value in rating.items():
778-
if key in ["_id", "activity_id", "user_id"]:
779-
continue
780-
if isinstance(value, int):
781-
if key not in result:
782-
result[key] = 0
783-
result[key] += value
784-
785-
for key, value in result.items():
786-
result[key] = value / len(ratings)
787-
788-
return {
789-
"status": "ok",
790-
"code": 200,
791-
"data": result,
792-
}

routers/exports_router.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import uuid
23
from time import sleep
34

@@ -56,7 +57,7 @@ async def process_task(task_id: str):
5657
'group': group['name'],
5758
'on-campus': user_time["on-campus"],
5859
'off-campus': user_time["off-campus"],
59-
'social-practice': user_time["social-practice"]
60+
'social-practice': user_
6061
}
6162
result.append(doc)
6263
task['percentage'] = (idx + 1) / len(users) * 100
@@ -174,3 +175,4 @@ async def get_export_list():
174175
"status": "ok",
175176
"data": result
176177
}
178+

routers/notifications_router.py

Lines changed: 7 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -10,77 +10,18 @@
1010

1111
@router.post("")
1212
async def create_notification(request: Notification, user=Depends(get_current_user)):
13-
"""
14-
Create Notification
15-
"""
16-
# Create notification
17-
if "admin" not in user["per"] and "department" not in user["per"]:
18-
raise HTTPException(status_code=403, detail="Permission denied")
19-
notification = request.model_dump()
20-
notification["global"] = notification["global_"]
21-
notification["publisher"] = user["id"]
22-
del notification["global_"]
23-
del notification["id"]
24-
for i in notification["receivers"]:
25-
validate_object_id(i)
26-
result = await db.zvms.notifications.insert_one(notification)
27-
return {
28-
"status": "ok",
29-
"code": 201,
30-
"data": {"_id": str(result.inserted_id)},
31-
}
13+
raise HTTPException(status_code=410, detail="Gone")
3214

3315

3416
@router.get("")
3517
async def get_notifications(
3618
page: int = 1, perpage: int = 10, user=Depends(get_current_user)
3719
):
38-
"""
39-
Get Notifications
40-
"""
41-
if "admin" not in user["per"]:
42-
raise HTTPException(status_code=403, detail="Permission denied")
43-
# Get notifications
44-
count = await db.zvms.notifications.count_documents({})
45-
result = (
46-
await db.zvms.notifications.find()
47-
.sort("_id", -1)
48-
.skip(0 if page == -1 else (page - 1) * perpage)
49-
.limit(0 if page == -1 else perpage)
50-
.to_list(None if page == -1 else perpage)
51-
)
52-
for i in result:
53-
i["_id"] = str(i["_id"])
54-
return {
55-
"status": "ok",
56-
"code": 200,
57-
"data": result,
58-
"metadata": {
59-
"size": count,
60-
},
61-
}
62-
20+
raise HTTPException(status_code=410, detail="Gone")
6321

6422
@router.get("/{notification_oid}")
6523
async def get_notification(notification_oid: str, user=Depends(get_current_user)):
66-
"""
67-
Get Notification
68-
"""
69-
item = await db.zvms.notifications.find_one(
70-
{"_id": validate_object_id(notification_oid)}
71-
)
72-
if not item:
73-
raise HTTPException(status_code=404, detail="Notification not found")
74-
if user["id"] != item["publisher"] and "admin" not in user["per"]:
75-
raise HTTPException(status_code=403, detail="Permission denied")
76-
# Get notification
77-
item["_id"] = str(item["_id"])
78-
return {
79-
"status": "ok",
80-
"code": 200,
81-
"data": item,
82-
}
83-
24+
raise HTTPException(status_code=410, detail="Gone")
8425

8526
class PutContent(BaseModel):
8627
content: str
@@ -94,65 +35,17 @@ class PutTitle(BaseModel):
9435
async def update_notification_content(
9536
notification_oid: str, request: PutContent, user=Depends(get_current_user)
9637
):
97-
"""
98-
Update Notification Content
99-
"""
100-
item = await db.zvms.notifications.find_one(
101-
{"_id": validate_object_id(notification_oid)}
102-
)
103-
if item is None:
104-
raise HTTPException(status_code=404, detail="Notification not found")
105-
if user["id"] != item["publisher"] or "admin" not in user["per"]:
106-
raise HTTPException(status_code=403, detail="Permission denied")
107-
actioner = await db.zvms.users.find_one({"_id": item["publisher"]})
108-
if actioner is None:
109-
raise HTTPException(status_code=404, detail="User not found")
110-
msg = f"{actioner['name']} modified notification at {datetime.now()}"
111-
if user["id"] != item["publisher"] or "admin" not in user["per"]:
112-
raise HTTPException(status_code=403, detail="Permission denied")
113-
# Update notification content
114-
await db.zvms.notifications.update_one(
115-
{"_id": validate_object_id(notification_oid)},
116-
{"$set": {"content": request.content + "\n" + msg}},
117-
)
118-
38+
raise HTTPException(status_code=410, detail="Gone")
11939

12040
@router.put("/{notification_oid}/title")
12141
async def update_notification_title(
12242
notification_oid: str, request: PutTitle, user=Depends(get_current_user)
12343
):
124-
"""
125-
Update Notification Title
126-
"""
127-
item = await db.zvms.notifications.find_one(
128-
{"_id": validate_object_id(notification_oid)}
129-
)
130-
if item is None:
131-
raise HTTPException(status_code=404, detail="Notification not found")
132-
if user["id"] != item["publisher"] or "admin" not in user["per"]:
133-
raise HTTPException(status_code=403, detail="Permission denied")
134-
# Update notification title
135-
await db.zvms.notifications.update_one(
136-
{"_id": validate_object_id(notification_oid)},
137-
{"$set": {"title": request.title}},
138-
)
139-
44+
raise HTTPException(status_code=410, detail="Gone")
14045

14146
@router.delete("/{notification_oid}")
14247
async def delete_notification(
14348
notification_oid: str, user=Depends(compulsory_temporary_token)
14449
):
145-
"""
146-
Remove Notification
147-
"""
148-
item = await db.zvms.notifications.find_one(
149-
{"_id": validate_object_id(notification_oid)}
150-
)
151-
if item is None:
152-
raise HTTPException(status_code=404, detail="Notification not found")
153-
if user["id"] != item["publisher"] and "admin" not in user["per"]:
154-
raise HTTPException(status_code=403, detail="Permission denied")
155-
# Remove notification
156-
await db.zvms.notifications.delete_one(
157-
{"_id": validate_object_id(notification_oid)}
158-
)
50+
raise HTTPException(status_code=410, detail="Gone")
51+

routers/plugins_router.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,8 @@
88

99
@router.get('/dictionary/oxford/{word}')
1010
def get_word_oxford(word: str):
11-
result = requests.get(f'https://api.dictionaryapi.dev/api/v2/entries/en/{word}').json()
12-
return {
13-
'status': 'ok',
14-
'code': 200,
15-
'data': result
16-
}
17-
11+
raise HTTPException(status_code=410, detail="Gone")
1812

1913
@router.get('/translate/deepl')
2014
def translate_deepl(text: str, lang: str):
21-
data = {'text': text, 'target_lang': lang}
22-
data = json.dumps(data)
23-
result = requests.post(f'http://127.0.0.1:1188/translate', data=data).json()
24-
return {
25-
'status': 'ok',
26-
'code': 200,
27-
'data': result
28-
}
15+
raise HTTPException(status_code=410, detail="Gone")

routers/rating_router.py

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,10 @@
1010

1111
@router.post("")
1212
async def create_rating(rating: ActivityRating, user=Depends(get_current_user)):
13-
if 'admin' not in user['per'] and 'department' not in user['per'] and 'rating' not in user['elg']:
14-
raise HTTPException(status_code=403, detail="Forbidden")
15-
16-
# Find duplicated document, if exists, return bad request
17-
redunants = await db.zvms.ratings.find({
18-
"activity_id": rating.activity_id,
19-
"user_id": rating.user_id
20-
}).to_list(None)
21-
22-
if len(redunants) > 0:
23-
raise HTTPException(status_code=400, detail="Duplicated rating")
24-
25-
if rating.user_id != user['id']:
26-
raise HTTPException(status_code=403, detail="Permission denied")
27-
28-
# Create rating
29-
rating = rating.model_dump()
30-
await db.zvms.ratings.insert_one(rating)
31-
return {
32-
"status": "ok",
33-
"code": 201,
34-
"data": {"_id": str(rating["_id"])},
35-
}
36-
13+
raise HTTPException(status_code=410, detail="Gone")
3714

3815
@router.get("")
3916
async def get_ratings(
4017
page: int = 1, perpage: int = 10, user=Depends(get_current_user)
4118
):
42-
if "admin" not in user["per"] or "rating" not in user["elg"]:
43-
raise HTTPException(status_code=403, detail="Permission denied")
44-
# Get ratings
45-
count = await db.zvms.ratings.count_documents({})
46-
result = (
47-
await db.zvms.ratings.find()
48-
.sort("_id", -1)
49-
.skip(0 if page == -1 else (page - 1) * perpage)
50-
.limit(0 if page == -1 else perpage)
51-
.to_list(None if page == -1 else perpage)
52-
)
53-
for i in result:
54-
i["_id"] = str(i["_id"])
55-
return {
56-
"status": "ok",
57-
"code": 200,
58-
"data": result,
59-
"metadata": {
60-
"size": count,
61-
},
62-
}
19+
raise HTTPException(status_code=410, detail="Gone")

0 commit comments

Comments
 (0)