aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Routes/Files/FoldersShow.php
blob: 2e16b3218e07d7fc1323fec73817c8f4b411a0d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php

namespace JsonApi\Routes\Files;

use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use JsonApi\Errors\AuthorizationFailedException;
use JsonApi\Errors\RecordNotFoundException;
use JsonApi\JsonApiController;

class FoldersShow extends JsonApiController
{
    protected $allowedIncludePaths = ['owner', 'parent', 'range', 'folders', 'file-refs'];

    /**
     * @SuppressWarnings(PHPMD.UnusedFormalParameters)
     */
    public function __invoke(Request $request, Response $response, $args)
    {
        if (!$folder = \FileManager::getTypedFolder($args['id'])) {
            throw new RecordNotFoundException();
        }

        if (!Authority::canShowFolder($this->getUser($request), $folder)) {
            throw new AuthorizationFailedException();
        }

        return $this->getContentResponse($folder);
    }
}