mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-12 01:54:41 +08:00
Applied API role specs to global visits
This commit is contained in:
@@ -9,6 +9,7 @@ use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Shlinkio\Shlink\Core\Visit\VisitsStatsHelperInterface;
|
||||
use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
|
||||
use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware;
|
||||
|
||||
class GlobalVisitsAction extends AbstractRestAction
|
||||
{
|
||||
@@ -24,8 +25,10 @@ class GlobalVisitsAction extends AbstractRestAction
|
||||
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$apiKey = AuthenticationMiddleware::apiKeyFromRequest($request);
|
||||
|
||||
return new JsonResponse([
|
||||
'visits' => $this->statsHelper->getVisitsStats(),
|
||||
'visits' => $this->statsHelper->getVisitsStats($apiKey),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,17 +12,19 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
class WithApiKeySpecsEnsuringJoin extends BaseSpecification
|
||||
{
|
||||
private ?ApiKey $apiKey;
|
||||
private string $fieldToJoin;
|
||||
|
||||
public function __construct(?ApiKey $apiKey)
|
||||
public function __construct(?ApiKey $apiKey, string $fieldToJoin)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->apiKey = $apiKey;
|
||||
$this->fieldToJoin = $fieldToJoin;
|
||||
}
|
||||
|
||||
protected function getSpec(): Specification
|
||||
{
|
||||
return $this->apiKey === null || $this->apiKey->isAdmin() ? Spec::andX() : Spec::andX(
|
||||
Spec::join('shortUrls', 's'),
|
||||
Spec::join($this->fieldToJoin, 's'),
|
||||
$this->apiKey->spec(),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user