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

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

parent 75d495b6
Loading
Loading
Loading
Loading
+25 −10
Original line number Original line Diff line number Diff line
@@ -12,17 +12,32 @@ class Spam


    public function check($entity)
    public function check($entity)
    {
    {
        if ($this->strposa($entity->getBody(), $this->prohibitedDomains())
        $foundSpam = false;
            || $this->strposa($entity->getDescription(), $this->prohibitedDomains())

            || $this->strposa($entity->getBriefDescription, $this->prohibitedDomains())
        switch ($entity->getType()) {
        ) {
            case 'comment':
            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 = $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 ($entity->type == 'group' 
         if ($foundSpam) {
            && $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');
        ) {
            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');
        }
        }
    }
    }


+12 −0
Original line number Original line Diff line number Diff line
@@ -147,6 +147,12 @@ class ManagerSpec extends ObjectBehavior
        $this->spam->check($blog)
        $this->spam->check($blog)
            ->shouldBeCalled();
            ->shouldBeCalled();


        $blog->getType()
            ->willReturn('object');

        $blog->getSubtype()
            ->willReturn('blog');

        $blog->setTimeCreated(Argument::type('int'))
        $blog->setTimeCreated(Argument::type('int'))
            ->shouldBeCalled()
            ->shouldBeCalled()
            ->willReturn($blog);
            ->willReturn($blog);
@@ -269,6 +275,12 @@ class ManagerSpec extends ObjectBehavior
            $this->search
            $this->search
        );
        );


        $blog->getType()
            ->willReturn('object');

        $blog->getSubtype()
            ->willReturn('blog');

        $blog->getBody()
        $blog->getBody()
            ->shouldBeCalled()
            ->shouldBeCalled()
            ->willReturn('movieblog.tumblr.com');
            ->willReturn('movieblog.tumblr.com');