Esempio n. 1
0
 public function validatePost(PostWillBeSaved $event)
 {
     $post = $event->post;
     if ($post->exists || $post->user->groups()->count()) {
         return;
     }
     $akismet = new Akismet($this->settings->get('akismet.api_key'), Core::url());
     $isSpam = $akismet->isSpam($post->content, $post->user->username, $post->user->email, null, 'comment');
     if ($isSpam) {
         $post->hide();
         $this->savingPost = $post;
         CommentPost::saved(function (CommentPost $post) {
             if ($post !== $this->savingPost) {
                 return;
             }
             $report = new Report();
             $report->post_id = $post->id;
             $report->reporter = 'Akismet';
             $report->reason = 'spam';
             $report->time = time();
             $report->save();
             $this->savingPost = null;
         });
     }
 }
Esempio n. 2
0
 protected function data(JsonApiRequest $request, Document $document)
 {
     $actor = $request->actor;
     $actor->reports_read_time = time();
     $actor->save();
     return Report::whereVisibleTo($actor)->with($request->include)->latest('reports.time')->groupBy('post_id')->get();
 }
Esempio n. 3
0
 /**
  * @param CreateReport $command
  * @return Report
  */
 public function handle(CreateReport $command)
 {
     $actor = $command->actor;
     $data = $command->data;
     $postId = array_get($data, 'relationships.post.data.id');
     $post = $this->posts->findOrFail($postId, $actor);
     if (!$post instanceof CommentPost) {
         // TODO: throw 400(?) error
         throw new Exception();
     }
     $post->assertCan($actor, 'report');
     Report::unguard();
     $report = Report::firstOrNew(['post_id' => $post->id, 'user_id' => $actor->id]);
     $report->post_id = $post->id;
     $report->user_id = $actor->id;
     $report->reason = array_get($data, 'attributes.reason');
     $report->reason_detail = array_get($data, 'attributes.reasonDetail');
     $report->time = time();
     $report->save();
     return $report;
 }
Esempio n. 4
0
 public function addAttributes(ApiAttributes $event)
 {
     if ($event->serializer instanceof ForumSerializer) {
         $event->attributes['canViewReports'] = $event->actor->hasPermissionLike('discussion.viewReports');
         if ($event->attributes['canViewReports']) {
             $query = Report::whereVisibleTo($event->actor);
             if ($time = $event->actor->reports_read_time) {
                 $query->where('reports.time', '>', $time);
             }
             $event->attributes['unreadReportsCount'] = $query->distinct('reports.post_id')->count();
         }
     }
     if ($event->serializer instanceof PostSerializer) {
         $event->attributes['canReport'] = $event->model->can($event->actor, 'report');
     }
 }