Example #1
0
 /**
  * 미리보기
  *
  * @return \Illuminate\Http\RedirectResponse
  * @throws \Xpressengine\Keygen\UnknownGeneratorException
  */
 public function preview()
 {
     /** @var \Illuminate\Http\Request $request */
     $request = app('request');
     if ($this->permissionHandler->hasCreate($this->boardId) === false) {
         throw new AccessDeniedHttpException();
     }
     $user = Auth::user();
     // get rules
     /** @var \Xpressengine\Plugins\Board\Validator $validator */
     $validator = app('xe.board.validator');
     $rules = $validator->makeRule($this->config);
     if ($user instanceof Guest) {
         $rules = array_merge($rules, $validator->guestStore());
     }
     $this->validate($request, $rules);
     $doc = new DocumentEntity($this->handler->documentFilter($request->all()));
     $doc->id = 'preview-' . (new Keygen())->generate();
     $doc->instanceId = $this->boardId;
     $doc->createdAt = date('Y-m-d H:i:s');
     if ($user instanceof Guest) {
         $doc->setUserType($doc::USER_TYPE_GUEST);
     }
     $doc->setAuthor($user);
     $item = $this->handler->makeItem($doc);
     /** @var \Xpressengine\Storage\Storage $storage */
     if (($fileIds = $request->get('_files')) !== null) {
         $storage = app('xe.storage');
         $item->setFiles($storage->getsIn($fileIds));
     }
     $formColumns = $this->configHandler->formColumns($this->boardId);
     return Presenter::make('preview', ['config' => $this->config, 'item' => $item, 'handler' => $this->handler, 'formColumns' => $formColumns]);
 }
 /**
  * test permission
  *
  * @return void
  */
 public function testPermission()
 {
     $entity = new DocumentEntity();
     $entity->setUserType(DocumentEntity::USER_TYPE_GUEST);
     $guest = m::mock('Xpressengine\\Member\\Entities\\Guest');
     $guest->shouldReceive('getId')->andReturn('guest');
     $guest->shouldReceive('getDisplayName')->andReturn('guest');
     $this->assertTrue($entity->alterPerm($guest));
     $this->assertTrue($entity->deletePerm($guest));
     $entity->setUserType(DocumentEntity::USER_TYPE_USER);
     $entity->userId = 'id';
     $this->assertFalse($entity->alterPerm($guest));
     $this->assertFalse($entity->deletePerm($guest));
     $user = m::mock('Xpressengine\\Member\\Entities\\Database\\MemberEntity');
     $user->shouldReceive('getId')->andReturn('id');
     $user->shouldReceive('getDisplayName')->andReturn('name');
     $author = m::mock('Xpressengine\\Member\\Entities\\Database\\MemberEntity');
     $author->shouldReceive('getId')->andReturn('id_author');
     $author->shouldReceive('getDisplayName')->andReturn('name_author');
     $entity->setAuthor($user);
     $this->assertFalse($entity->alterPerm($author));
     $this->assertFalse($entity->deletePerm($author));
     $this->assertTrue($entity->alterPerm($user));
     $this->assertTrue($entity->deletePerm($user));
 }
Example #3
0
 /**
  * create board item entity by document entity
  *
  * @param DocumentEntity        $doc     document entity
  * @param Request               $request request
  * @param MemberEntityInterface $user    user
  * @return ItemEntity
  */
 public function makeItem(DocumentEntity $doc, Request $request = null, MemberEntityInterface $user = null)
 {
     if ($request !== null && $user !== null) {
         if ($request->get('notice') === '1') {
             $doc->notice();
         }
         // 비회원 글쓰기 또는 익명 글쓰기 처리
         if ($user instanceof Guest) {
             $doc->guest();
         } elseif ($request->get('anonymity') == '1') {
             $doc->anonymity($this->config->get('anonymityName'));
         } else {
             $doc->setAuthor($user);
         }
     }
     $item = new ItemEntity();
     $item->setDocument($doc);
     if ($request !== null) {
         // set files
         if (($fileIds = $request->get('_files')) !== null) {
             $item->setFiles($this->storage->getsIn($fileIds));
         }
     }
     return $item;
 }