10
10
11
11
@router .post ("" )
12
12
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" )
32
14
33
15
34
16
@router .get ("" )
35
17
async def get_notifications (
36
18
page : int = 1 , perpage : int = 10 , user = Depends (get_current_user )
37
19
):
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" )
63
21
64
22
@router .get ("/{notification_oid}" )
65
23
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" )
84
25
85
26
class PutContent (BaseModel ):
86
27
content : str
@@ -94,65 +35,17 @@ class PutTitle(BaseModel):
94
35
async def update_notification_content (
95
36
notification_oid : str , request : PutContent , user = Depends (get_current_user )
96
37
):
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" )
119
39
120
40
@router .put ("/{notification_oid}/title" )
121
41
async def update_notification_title (
122
42
notification_oid : str , request : PutTitle , user = Depends (get_current_user )
123
43
):
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" )
140
45
141
46
@router .delete ("/{notification_oid}" )
142
47
async def delete_notification (
143
48
notification_oid : str , user = Depends (compulsory_temporary_token )
144
49
):
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
+
0 commit comments