summaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2024-02-05 12:53:22 -0600
committerHombreLaser <sebastian-440@live.com>2024-02-05 12:53:22 -0600
commit3fa4434d417c4bc85916ed79cc7bbb324b2768ac (patch)
treee2c1586b94f5ac877ad0a260cd95876e99be59da /src/services
parentbc01c595dc4f78bcbeb81577f4947b42bf8f9d61 (diff)
Add blacklist matching
Diffstat (limited to 'src/services')
-rw-r--r--src/services/callback.py6
-rw-r--r--src/services/comment_creation_callbacks.py27
-rw-r--r--src/services/create_comment_service.py3
3 files changed, 36 insertions, 0 deletions
diff --git a/src/services/callback.py b/src/services/callback.py
new file mode 100644
index 0000000..5dc3149
--- /dev/null
+++ b/src/services/callback.py
@@ -0,0 +1,6 @@
+class Callback:
+ def _moderate(self):
+ pass
+
+ def deliver_notification(self):
+ pass
diff --git a/src/services/comment_creation_callbacks.py b/src/services/comment_creation_callbacks.py
new file mode 100644
index 0000000..5f5d024
--- /dev/null
+++ b/src/services/comment_creation_callbacks.py
@@ -0,0 +1,27 @@
+import src.lib as lib
+from config import user_config
+from src.services.callback import Callback
+
+
+class CommentCreationCallbacks(Callback):
+ """
+ Check config for blacklists, moderation behavior and
+ notification delivery.
+ """
+ def __init__(self, comment):
+ self._comment = comment
+
+ def run_callbacks(self):
+ self._moderate()
+ self._deliver_notification()
+
+ return self._comment
+
+ def _moderate(self):
+ if user_config['Env']['moderation'] == 'strict':
+ self._comment.approved = False
+ return
+
+ if lib.contains_forbidden_term(self._comment.content):
+ if user_config['Env']['blacklist_match_action'] == 'reject':
+ self._comment.approved = False
diff --git a/src/services/create_comment_service.py b/src/services/create_comment_service.py
index b995b25..97cf726 100644
--- a/src/services/create_comment_service.py
+++ b/src/services/create_comment_service.py
@@ -1,6 +1,7 @@
from sqlalchemy import select
from src.database.models import Blog, Comment
from src.database import db
+from src.services.comment_creation_callbacks import CommentCreationCallbacks
class CreateCommentService:
@@ -26,6 +27,8 @@ class CreateCommentService:
comment = Comment(blog_id=self._blog_id, content=self._content,
email=self._email, author=self._author,
post=self._post, language='en')
+ comment_callbacks = CommentCreationCallbacks(comment)
+ comment = comment_callbacks.run_callbacks()
db.session.add(comment)
db.session.commit()