1
1
from collections .abc import Callable
2
2
from datetime import datetime
3
3
4
- from sqlalchemy import exists , select
4
+ from sqlalchemy import select
5
5
from sqlalchemy .dialects .postgresql import insert
6
6
from sqlalchemy .orm import Session
7
7
8
8
from h import i18n
9
- from h .models import Annotation , AnnotationModeration , AnnotationSlim , User
9
+ from h .models import Annotation , AnnotationSlim , User
10
10
from h .models .document import update_document_metadata
11
11
from h .schemas import ValidationError
12
12
from h .security import Permission
@@ -168,7 +168,6 @@ def update_annotation(
168
168
def hide (self , annotation : Annotation , user : User ):
169
169
"""Hides an annotation marking it it as "moderated"."""
170
170
if not annotation .is_hidden :
171
- annotation .moderation = AnnotationModeration ()
172
171
self ._moderation_service .set_status (
173
172
annotation , user , Annotation .ModerationStatus .DENIED
174
173
)
@@ -177,11 +176,10 @@ def hide(self, annotation: Annotation, user: User):
177
176
178
177
def unhide (self , annotation : Annotation , user : User ):
179
178
"""Remove the moderation status of an annotation."""
180
- annotation .moderation = None
181
- self .upsert_annotation_slim (annotation )
182
179
self ._moderation_service .set_status (
183
180
annotation , user , Annotation .ModerationStatus .APPROVED
184
181
)
182
+ self .upsert_annotation_slim (annotation )
185
183
186
184
@staticmethod
187
185
def change_document (db , old_document_ids , new_document ):
@@ -235,7 +233,7 @@ def _validate_group(self, annotation: Annotation, enforce_write_permission=True)
235
233
+ _ ("Annotations for this target URI are not allowed in this group" )
236
234
)
237
235
238
- def upsert_annotation_slim (self , annotation ) :
236
+ def upsert_annotation_slim (self , annotation : Annotation ) -> None :
239
237
self ._db .flush () # See the last model changes in the transaction
240
238
241
239
user_id = self ._db .scalar (
@@ -247,15 +245,6 @@ def upsert_annotation_slim(self, annotation):
247
245
# The AnnotationSlim records will get deleted by a cascade, no need to do anything here.
248
246
return
249
247
250
- moderated = self ._db .scalar (
251
- select (
252
- exists (
253
- select (AnnotationModeration .id ).where (
254
- AnnotationModeration .annotation_id == annotation .id
255
- )
256
- )
257
- )
258
- )
259
248
stmt = insert (AnnotationSlim ).values (
260
249
[
261
250
{
@@ -270,7 +259,7 @@ def upsert_annotation_slim(self, annotation):
270
259
# Fields of AnnotationSlim
271
260
"group_id" : annotation .group .id ,
272
261
"user_id" : user_id ,
273
- "moderated" : moderated ,
262
+ "moderated" : annotation . is_hidden ,
274
263
}
275
264
]
276
265
)
0 commit comments