Beispiel #1
0
 /**
  * Anonymous user try to edit existing lyric
  */
 public function testGetAllowedFields()
 {
     $user = new User();
     $lyric = new Lyric();
     $lyric->setId(5);
     $allowedFields = $user->getAllowedLyricFields($lyric);
     $this->assertEmpty($allowedFields);
 }
 public function indexAction(Request $request, $id)
 {
     if ($this->getUser()) {
         $user = $this->getUser();
     } else {
         $user = new User();
     }
     if ($id) {
         $lyricQuery = new LyricQuery();
         $lyric = $lyricQuery->findOneById($id);
     } else {
         $lyric = new Lyric();
     }
     $allowedFields = $user->getAllowedLyricFields($lyric);
     $data = ['item' => ['fields' => $allowedFields]];
     return $this->handleData($request, $data);
 }
 public function deleteAction(Request $request, $id)
 {
     $this->getContext()->setGroups(['Details']);
     $lyricQuery = new LyricQuery();
     /* @var $lyric Lyric */
     $lyric = $lyricQuery->findOneById($id);
     try {
         if ($this->getUser()) {
             $user = $this->getUser();
         } else {
             $user = new User();
         }
         $allowedFields = $user->getAllowedLyricFields($lyric);
         if (!in_array('delete', $allowedFields)) {
             throw new \Exception("Delete not allowed");
         }
         $lyric->delete();
         return $this->handleData($request, $lyric);
     } catch (LyricHumanReadableException $e) {
         $view = $this->handleData($request, $e->getErrors());
         $view->setStatusCode(400);
         return $view;
     }
 }