-
Notifications
You must be signed in to change notification settings - Fork 425
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4473 from hypothesis/add-nipsa-index-for-moderate…
…d-ann Mark moderated annotations as nipsa'd in search index
- Loading branch information
Showing
6 changed files
with
123 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import unicode_literals | ||
|
||
|
||
def transform_annotation(event): | ||
"""Add a {"nipsa": True} field on annotations whose users are flagged.""" | ||
annotation = event.annotation_dict | ||
nipsa_service = event.request.find_service(name='nipsa') | ||
if 'user' in annotation and nipsa_service.is_flagged(annotation['user']): | ||
annotation['nipsa'] = True | ||
"""Add a {"nipsa": True} field on moderated annotations or those whose users are flagged.""" | ||
payload = event.annotation_dict | ||
|
||
nipsa = _user_nipsa(event.request, payload) | ||
nipsa = nipsa or _annotation_moderated(event.request, payload) | ||
|
||
if nipsa: | ||
payload['nipsa'] = True | ||
|
||
|
||
def _user_nipsa(request, payload): | ||
nipsa_service = request.find_service(name='nipsa') | ||
return 'user' in payload and nipsa_service.is_flagged(payload['user']) | ||
|
||
|
||
def _annotation_moderated(request, payload): | ||
svc = request.find_service(name='annotation_moderation') | ||
return svc.hidden(payload['id']) |
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
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