Commit 63ea0f30 authored by Ben Hayward's avatar Ben Hayward

Updated to include subtree

1 merge request!328WIP: [Sprint/NuancedNumbat](fix): Ban email now returning string of ban reason rather than index.
Pipeline #90333077 failed with stages
in 14 minutes and 46 seconds
......@@ -54,10 +54,10 @@ class Events
/**
* Returns a readable format for a given ban reason, converting
* tree indicies to their text counterparts, discarding sub-reason.
* tree indices to their text counterparts.
*
* e.g. with the default config, an index of 1 returns "is illegal"
* an index of 1.1 also returns "is illegal"
* e.g. with the default config, an index of 3 returns "Illegal"
* an index of 1.3 returns "Illegal (Extortion)"
*
* @param string $index - the given ban reason index
* @return string the first reason in the ban reason tree, or
......@@ -65,9 +65,16 @@ class Events
*/
public function getBanReasons($reason)
{
$reason = preg_split("/\./", $reason)[0];
if (is_numeric($reason)) {
return $this->config->get('ban_reasons')[$reason];
$banReasons = $this->config->get('ban_reasons');
$splitReason = preg_split("/\./", $reason);
if (is_numeric($reason) && isset($splitReason[1])) {
$index = $splitReason[0];
$subIndex = $splitReason[1];
return $banReasons[$index]['label']
.$banReasons[$index]['reasons'][$subIndex];
}
if (is_numeric($reason) && isset($splitReason[0])) {
return $banReasons[$splitReason[0]]['label'];
}
return $reason;
}
......
......@@ -14,6 +14,7 @@ class EventsSpec extends ObjectBehavior
/** @var EventsDispatcher */
protected $dispatcher;
protected $config;
protected $banReasons;
public function let(EventsDispatcher $dispatcher, Config $config)
{
......@@ -22,6 +23,43 @@ class EventsSpec extends ObjectBehavior
});
$this->dispatcher = $dispatcher;
$this->config = $config;
$this->banReasons = [
1 => [
'label' => 'Illegal ',
'reasons' => [
1 => '(Terrorism)',
2 => '(Paedophilia)',
3 => '(Extortion)',
4 => '(Fraud)',
5 => '(Revenge porn)',
6 => '(Sex trafficking)'
],
],
2 => [
'label' => 'Should be marked as explicit ',
'reasons' => [
1 => 'for nudity',
2 => 'for pornography',
3 => 'for profanity',
4 => 'for violence and gore',
5 => 'for race, religion or gender',
]
],
3 => [ 'label' => 'Encourages or incites violence' ],
4 => [ 'label' => 'Harassment' ],
5 => [ 'label' => 'Contains personal and confidential info' ],
6 => [ 'label' => 'Maliciously targets users (@name, links, images or videos)' ],
7 => [ 'label' => 'Impersonates someone in a misleading or deceptive manner' ],
8 => [ 'label' => 'Is spam'],
9 => [ 'label' => '' ],
10 => [ 'label' => 'Copyright infringement' ],
11 => [ 'label' => 'Another reason' ],
12 => [ 'label' => 'Incorrect use of hashtags' ],
13 => [ 'label' => 'Malware' ],
14 => [ 'label' => '' ],
15 => [ 'label' => 'Trademark infringement' ],
16 => [ 'label' => 'Token manipulation' ],
];
}
public function it_is_initializable()
......@@ -40,26 +78,17 @@ class EventsSpec extends ObjectBehavior
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);
Di::_()->get('Config')->set('ban_reasons', $this->banReasons);
$this->getBanReasons(1)
->shouldReturn("is illegal");
->shouldReturn("Illegal ");
$this->getBanReasons("1.1")
->shouldReturn("is illegal");
$this->getBanReasons("1.3")
->shouldReturn("Illegal (Extortion)");
$this->getBanReasons("2.9.9.9.9.9..9")
->shouldReturn("Should be marked as explicit");
$this->getBanReasons("2.3")
->shouldReturn("Should be marked as explicit for profanity");
$this->getBanReasons("3.14159265359")
->shouldReturn("Encourages or incites violence");
$this->getBanReasons("3")
->shouldReturn("Encourages or incites violence");
......
......@@ -581,18 +581,39 @@ $CONFIG->set('pro', [
]);
$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'
1 => [
'label' => 'Illegal',
'reasons' => [
1 => '(Terrorism)',
2 => '(Paedophilia)',
3 => '(Extortion)',
4 => '(Fraud)',
5 => '(Revenge porn)',
6 => '(Sex trafficking)'
],
],
2 => [
'label' => 'Should be marked as explicit',
'reasons' => [
1 => 'for nudity',
2 => 'for pornography',
3 => 'for profanity',
4 => 'for violence and gore',
5 => 'for race, religion or gender',
]
],
3 => [ 'label' => 'Encourages or incites violence' ],
4 => [ 'label' => 'Harassment' ],
5 => [ 'label' => 'Contains personal and confidential info' ],
6 => [ 'label' => 'Maliciously targets users (@name, links, images or videos)' ],
7 => [ 'label' => 'Impersonates someone in a misleading or deceptive manner' ],
8 => [ 'label' => 'Is spam'],
9 => [ 'label' => '' ],
10 => [ 'label' => 'Copyright infringement' ],
11 => [ 'label' => 'Another reason' ],
12 => [ 'label' => 'Incorrect use of hashtags' ],
13 => [ 'label' => 'Malware' ],
14 => [ 'label' => '' ],
15 => [ 'label' => 'Trademark infringement' ],
16 => [ 'label' => '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