Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Backend of spam prevention * Add comments and small tweaks * Add language detection * Initial mattermost notification system * Fix listener broken on unknown arguments * Update requirements * Fix potentiel * Add trailing slash Co-authored-by: maudetes <maudet.estelle@gmail.com> * fix discussion without first message * Fix breadcrumbs and enable Mattermost notifications * Add admin permissions on delete spam * Use inheritence instead of signals to detect spam * Fix updates of models for spam detection * Use _created * Small tweaks * Fix two notifications sent * Add API endpoint to fetch all potential spam * Try again tests * Remove comment * Fix test * Add new env to settings * Add SPAM_MINIMUM_STRING_LENGTH_FOR_LANG_CHECK conf --------- Co-authored-by: maudetes <maudet.estelle@gmail.com>
- Loading branch information
1 parent
cda9af2
commit d7fbea1
Showing
15 changed files
with
558 additions
and
16 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
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from mongoengine import Q | ||
|
||
from udata.api import api, API | ||
from udata.auth import admin_permission | ||
from udata.core.discussions.models import Discussion | ||
from udata.core.spam.fields import potential_spam_fields | ||
from udata.core.spam.models import POTENTIAL_SPAM | ||
from udata.utils import id_or_404 | ||
|
||
|
||
class SpamAPIMixin(API): | ||
""" | ||
Base Spam Model API. | ||
""" | ||
model = None | ||
|
||
def get_model(self, id): | ||
""" | ||
This function returns the base model and the spamable model which can be different. The base model is the | ||
model stored inside Mongo and the spamable model is the embed document (for example a comment inside a | ||
discussion) | ||
""" | ||
model = self.model.objects.get_or_404(id=id_or_404(id)) | ||
return model, model | ||
|
||
@api.secure(admin_permission) | ||
def delete(self, **kwargs): | ||
""" | ||
Mark a potential spam as no spam | ||
""" | ||
base_model, model = self.get_model(**kwargs) | ||
|
||
if not model.is_spam(): | ||
return {}, 200 | ||
|
||
model.mark_as_no_spam(base_model) | ||
return {}, 200 | ||
|
||
|
||
ns = api.namespace('spam', 'Spam related operations') | ||
|
||
|
||
@ns.route('/', endpoint='spam') | ||
class SpamAPI(API): | ||
""" | ||
Base class for a discussion thread. | ||
""" | ||
@api.doc('get_potential_spams') | ||
@api.secure(admin_permission) | ||
@api.marshal_with(potential_spam_fields) | ||
def get(self): | ||
"""Get all potential spam objects""" | ||
discussions = Discussion.objects(Q(spam__status=POTENTIAL_SPAM) | Q(discussion__spam__status=POTENTIAL_SPAM)) | ||
|
||
return [{ | ||
'title': discussion.spam_report_title(), | ||
'link': discussion.spam_report_link(), | ||
} for discussion in discussions] |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from udata.api import api, fields | ||
from .models import SPAM_STATUS_CHOICES | ||
|
||
spam_fields = api.model('Spam', { | ||
'status': fields.String(description='Status', enum=SPAM_STATUS_CHOICES, readonly=True), | ||
}) | ||
|
||
potential_spam_fields = api.model('PotentialSpam', { | ||
'title': fields.String(readonly=True), | ||
'link': fields.String(readonly=True), | ||
}) | ||
|
Oops, something went wrong.