Commit c96f482e authored by Ben Hayward's avatar Ben Hayward

Changed location of call and put ban reasons in settings

1 merge request!328[Sprint/NuancedNumbat](fix): Ban email now returning string of ban reason rather than index.
Pipeline #84124651 canceled with stages
in 2 seconds
......@@ -16,23 +16,6 @@ class Ban
/** @var EventsDispatcher */
protected $eventsDispatcher;
private const REASONS = array(
1 => 'is illegal',
2 => 'Should be marked as explicit',
3 => 'Encourages or incites violence',
4 => 'Harassment',
5 => 'contains personal and confidential info' ,
6 => 'Maliciously targets users (@name, links, images or videos)',
7 => 'Impersonates someone in a misleading or deceptive manner',
8 => 'is spam',
10 => 'is a copyright infringement',
11 => 'Another reason',
12 => 'Incorrect use of hashtags',
13 => 'Malware',
15 => 'Trademark infringement',
16 => 'Token manipulation',
);
public function __construct($eventsDispatcher = null)
{
$this->eventsDispatcher = $eventsDispatcher ?: Di::_()->get('EventsDispatcher');
......@@ -61,15 +44,4 @@ class Ban
return $saved;
}
/**
* Gets the text of a reason associated with a ban_reason index.
*
* @param int $i ban_reason index.
* @return string text reason e.g. "is illegal".
*/
public function getReasonText($i)
{
return static::REASONS[$i];
}
}
......@@ -7,12 +7,18 @@
use Minds\Core;
use Minds\Entities;
use Minds\Helpers;
use Minds\Core\Di\Di;
use Minds\Core\Analytics\Metrics\Event;
use Minds\Core\Events\Dispatcher;
use Minds\Core\Channels\Delegates\Ban;
class Events
{
{
public function __construct()
{
$this->config = Di::_()->get('Config');
}
public function register()
{
Core\Di\Di::_()->get('EventsDispatcher')->register('ban', 'user', function ($event) {
......@@ -24,7 +30,7 @@ class Events
->setBody('banned.tpl')
->set('username', $user->username)
->set('email', $user->getEmail())
->set('reason', getReasonText($user->ban_reason))
->set('reason', getBanReasons($user->ban_reason))
->set('user', $user);
$message = new Core\Email\Message();
$message->setTo($user)
......@@ -45,4 +51,9 @@ class Events
->push();
});
}
public function getBanReasons($index)
{
return $this->config->get('ban_reasons')[$index];
}
}
......@@ -47,9 +47,4 @@ class BanSpec extends ObjectBehavior
->shouldReturn(true);
}
public function it_should_discern_ban_reason_text()
{
$this->getReasonText(1)
->shouldReturn("is illegal");
}
}
......@@ -7,18 +7,21 @@ use Minds\Core\Events\EventsDispatcher;
use Minds\Core\Reports\Events;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Minds\Core\Config;
class EventsSpec extends ObjectBehavior
{
/** @var EventsDispatcher */
protected $dispatcher;
protected $config;
public function let(EventsDispatcher $dispatcher)
public function let(EventsDispatcher $dispatcher, Config $config)
{
Di::_()->bind('EventsDispatcher', function ($di) use ($dispatcher) {
return $dispatcher->getWrappedObject();
});
$this->dispatcher = $dispatcher;
$this->config = $config;
}
public function it_is_initializable()
......@@ -33,4 +36,18 @@ class EventsSpec extends ObjectBehavior
$this->register();
}
public function it_should_discern_ban_reason_text()
{
$reasons = [
1 => 'is illegal',
2 => 'Should be marked as explicit',
3 => 'Encourages or incites violence',
];
Di::_()->get('Config')->set('ban_reasons', $reasons);
$this->getBanReasons(1)
->shouldReturn("is illegal");
}
}
......@@ -572,3 +572,20 @@ $CONFIG->set('gitlab', [
],
'private_key' => ''
]);
$CONFIG->set('ban_reasons', [
1 => 'is illegal',
2 => 'Should be marked as explicit',
3 => 'Encourages or incites violence',
4 => 'Harassment',
5 => 'contains personal and confidential info' ,
6 => 'Maliciously targets users (@name, links, images or videos)',
7 => 'Impersonates someone in a misleading or deceptive manner',
8 => 'is spam',
10 => 'is a copyright infringement',
11 => 'Another reason',
12 => 'Incorrect use of hashtags',
13 => 'Malware',
15 => 'Trademark infringement',
16 => 'Token manipulation'
]);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment