예제 #1
0
 public function restore($id)
 {
     $id = intval($id);
     $userInstance = User::onlyTrashed()->findOrFail($id);
     $userInstance->comments->each(function ($comment) {
         Comment::withTrashed()->find($comment->id)->restore();
     });
     if ($userInstance->restore()) {
         return redirect()->back()->with('success', 'restore success');
     } else {
         return redirect()->back()->withError('this user haven\'t been deleted yet.');
     }
 }
예제 #2
0
 public function index()
 {
     $comments = Comment::withTrashed()->paginate(10);
     return view('admin.comment')->withComments($comments);
 }
예제 #3
0
 public function getRestoreDoc($docId)
 {
     $doc = Doc::withTrashed()->find($docId);
     if ($doc->publish_state == Doc::PUBLISH_STATE_DELETED_ADMIN) {
         if (!Auth::user()->hasRole('admin')) {
             return Response('Unauthorized.', 403);
         }
     }
     if (!$doc->canUserEdit(Auth::user())) {
         return Response('Unauthorized.', 403);
     }
     DocMeta::withTrashed()->where('doc_id', $docId)->restore();
     DocContent::withTrashed()->where('doc_id', $docId)->restore();
     Annotation::withTrashed()->where('doc_id', $docId)->restore();
     Comment::withTrashed()->where('doc_id', $docId)->restore();
     $doc->restore();
     $doc->publish_state = Doc::PUBLISH_STATE_UNPUBLISHED;
     $doc->save();
     return Response::json($doc);
 }
예제 #4
0
 public function restore(Request $request, $id)
 {
     if (!$request->has('reason')) {
         return 'invalid_request';
     }
     $reason = trim($request->get('reason'));
     if ($reason == '') {
         return 'invalid_request';
     }
     $user = auth()->check() ? auth()->user() : null;
     if (is_null($user)) {
         return 'not_logged_in';
     }
     if (!$user->can('delete_comment')) {
         return 'insufficient_permissions';
     }
     $comment = Comment::withTrashed()->whereId($id)->first();
     if (is_null($comment)) {
         return 'comment_not_found';
     }
     if (!$comment->trashed()) {
         return 'comment_not_deleted';
     }
     $receiver = $comment->user;
     $video = $comment->video;
     $comment->restore();
     if ($user->id != $receiver->id) {
         Message::send(1, $receiver->id, 'A moderator restored your comment', view('messages.moderation.commentrestore', ['video' => $video, 'comment' => $comment, 'reason' => $reason]));
     }
     $log = new ModeratorLog();
     $log->user()->associate($user);
     $log->type = 'restore';
     $log->target_type = 'comment';
     $log->target_id = $id;
     $log->reason = $reason;
     $log->save();
     return 'success';
 }
예제 #5
0
 public function restoreComment($id)
 {
     $user = auth()->check() ? auth()->user() : null;
     if (is_null($user)) {
         return redirect()->back()->with('error', 'Not logged in');
     }
     if ($user->can('delete_comment')) {
         Comment::withTrashed()->whereId($id)->restore();
         $log = new ModeratorLog();
         $log->user()->associate($user);
         $log->type = 'restore';
         $log->target_type = 'comment';
         $log->target_id = $id;
         $log->save();
         return redirect()->back()->with('success', 'Comment restored');
     }
     return redirect()->back()->with('error', 'Insufficient permissions');
 }