예제 #1
0
 public function filter($route, $request)
 {
     if (!isset($this->user) || !$this->user || $this->user == parent::ANONYMOUS_USER) {
         return Response::json(['error' => true, 'error_description' => 'Permission denied'], 401);
     }
     if (!$this->user->can('bookmark_delete')) {
         return Response::json(['error' => true, 'error_description' => 'Permission denied'], 401);
     }
     $id = Request::segment(3);
     $bookmark = BookmarkObject::find($id);
     if (!$bookmark) {
         return Response::json(['error' => true, 'error_description' => 'Bookmark not found'], 400);
     }
     if (!$this->user->hasRole('admin') && $bookmark->user_id != $this->user->id) {
         return Response::json(['error' => true, 'error_description' => 'Only admin can delete others\' bookmarks'], 401);
     }
 }
예제 #2
0
 /**
  * Delete bookmark
  * type - company or item
  * object_id
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $bookmark = BookmarkObject::find($id);
     if (!$bookmark) {
         return Response::json(array('error_code' => '500', 'error_message' => 'Bookmark not found.'), 500);
     }
     $bookmark->delete();
     return Response::json(array('success_code' => 'OK', 'success_message' => 'Bookmark has been successfully deleted'), 200);
 }