From b85721d7edb73e8a075a21fff86af372340f22d5 Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Jul 16 2020 16:01:29 +0000 Subject: Add a Noggin decision plugin Signed-off-by: Aurélien Bompard --- diff --git a/basset/core.py b/basset/core.py index d1c71e6..dcbe99b 100644 --- a/basset/core.py +++ b/basset/core.py @@ -32,6 +32,7 @@ from basset.score.content import ContentScore from basset.score.mx import MailExchangeScore from basset.decision.fas import FASRegisterDecision from basset.decision.fas import FASCLADecision +from basset.decision.noggin import NogginRegisterDecision from basset.decision.mediawiki import MediawikiDecision, MediawikiBlockDecision from basset.decision.trac import TracDecision @@ -47,7 +48,8 @@ PLUGINS = { FASCLADecision, MediawikiDecision, MediawikiBlockDecision, - TracDecision + TracDecision, + NogginRegisterDecision, ] } diff --git a/basset/decision/noggin.py b/basset/decision/noggin.py new file mode 100644 index 0000000..200abd5 --- /dev/null +++ b/basset/decision/noggin.py @@ -0,0 +1,78 @@ +# Copyright (c) 2016, Patrick Uiterwijk +# All rights reserved. +# +# This file is part of Basset. +# +# Basset is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Basset is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Basset. If not, see . + + +import requests + +from basset.decision.base import DecisionPlugin + + +class NogginRegisterDecision(DecisionPlugin): + name = 'nogginregistration' + handled_decisions = ['fedora.noggin.registration'] + + def tests_to_run(self, action, time, data): + return ['ip', 'details', 'mailexchange'] + + def generate_decisions(self, action, time, data, decision): + if decision is None: + return {'action': action, + 'username': data['user']['username'], + 'decision': 'manual'} + elif decision is True: + return {'action': action, + 'username': data['user']['username'], + 'decision': 'accept'} + else: + return {'action': action, + 'username': data['user']['username'], + 'decision': 'deny'} + + def _update_account_status(self, username, new_status, message_data): + self.log.info('Updating status for %s to %s' % (username, new_status)) + response = requests.post( + message_data["callback"], json={ + "token": message_data["token"], + "status": new_status, + } + ) + if not response.ok or response.json().get("status") != "success": + self.log.error('Error saving status: %s %s', + response.status_code, response.text) + return False + + return True + + def handle(self, decision, message_data): + if not self.coreconfig.get('core', 'do_noggin') == 'true': + self.log.info('Ignoring noggin decisions') + return True + + if decision['decision'] == 'deny': + return self._update_account_status( + decision['username'], 'spamcheck_denied', message_data) + elif decision['decision'] == 'manual': + return self._update_account_status( + decision['username'], 'spamcheck_manual', message_data) + elif decision['decision'] == 'accept': + return self._update_account_status( + decision['username'], 'active', message_data) + else: + raise ValueError( + 'Invalid decision value: {!r}'.format(decision['decision']) + ) diff --git a/worker.default.cfg b/worker.default.cfg index 36f7718..2d642a0 100644 --- a/worker.default.cfg +++ b/worker.default.cfg @@ -11,6 +11,7 @@ registration_check_manually = 5 registration_deny = 10 do_fas = true +do_noggin = true do_wiki = true do_trac = true