Commit 73e13d3e authored by Mark Harding's avatar Mark Harding

(fix): #485 - filter spam by entity type to fix user profile saving

parent 75d495b6
No related merge requests found
Pipeline #64566647 passed with stages
in 7 minutes and 8 seconds
......@@ -12,17 +12,32 @@ class Spam
public function check($entity)
{
if ($this->strposa($entity->getBody(), $this->prohibitedDomains())
|| $this->strposa($entity->getDescription(), $this->prohibitedDomains())
|| $this->strposa($entity->getBriefDescription, $this->prohibitedDomains())
) {
throw new \Exception('Sorry, you included a reference to a domain name linked to spam. You can not use short urls (eg. bit.ly). Please remove it and try again');
}
$foundSpam = false;
if ($entity->type == 'group'
&& $this->strposa($entity->getBriefDescription(), $this->prohibitedDomains())
) {
new \Exception('Sorry, you included a reference to a domain name linked to spam. You can not use short urls (eg. bit.ly). Please remove it and try again');
switch ($entity->getType()) {
case 'comment':
$foundSpam = $this->strposa($entity->getBody(), $this->prohibitedDomains());
break;
case 'activity':
case 'object':
if ($entity->getSubtype() === 'blog') {
$foundSpam = $this->strposa($entity->getBody(), $this->prohibitedDomains());
break;
}
$foundSpam = $this->strposa($entity->getDescription(), $this->prohibitedDomains());
break;
case 'user':
$foundSpam = $this->strposa($entity->briefdescription, $this->prohibitedDomains());
break;
case 'group':
$foundSpam = $this->strposa($entity->getBriefDescription(), $this->prohibitedDomains());
break;
default:
error_log("[spam-check]: $entity->type:$entity->subtype not supported");
}
if ($foundSpam) {
throw new \Exception('Sorry, you included a reference to a domain name linked to spam. You can not use short urls (eg. bit.ly). Please remove it and try again');
}
}
......
......@@ -147,6 +147,12 @@ class ManagerSpec extends ObjectBehavior
$this->spam->check($blog)
->shouldBeCalled();
$blog->getType()
->willReturn('object');
$blog->getSubtype()
->willReturn('blog');
$blog->setTimeCreated(Argument::type('int'))
->shouldBeCalled()
->willReturn($blog);
......@@ -269,6 +275,12 @@ class ManagerSpec extends ObjectBehavior
$this->search
);
$blog->getType()
->willReturn('object');
$blog->getSubtype()
->willReturn('blog');
$blog->getBody()
->shouldBeCalled()
->willReturn('movieblog.tumblr.com');
......
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