diff --git a/lib/classes/JsonApi/RouteMap.php b/lib/classes/JsonApi/RouteMap.php index effbf8f5fa5bb3238772055fdd9d90bbf274d5cb..e779e8b25aee30fd93e362c16153af0205c58317 100644 --- a/lib/classes/JsonApi/RouteMap.php +++ b/lib/classes/JsonApi/RouteMap.php @@ -115,6 +115,8 @@ class RouteMap $group->get('/config-values/{id}', Routes\ConfigValues\ConfigValuesShow::class); $group->patch('/config-values/{id}', Routes\ConfigValues\ConfigValuesUpdate::class); + $group->get('/status-groups/{id}', Routes\StatusgroupShow::class); + $this->addAuthenticatedBlubberRoutes($group); $this->addAuthenticatedConsultationRoutes($group); $this->addAuthenticatedContactsRoutes($group); diff --git a/lib/classes/JsonApi/Routes/StatusgroupShow.php b/lib/classes/JsonApi/Routes/StatusgroupShow.php new file mode 100644 index 0000000000000000000000000000000000000000..ba7814fa86940a82d3629908581a22a3d97fb6be --- /dev/null +++ b/lib/classes/JsonApi/Routes/StatusgroupShow.php @@ -0,0 +1,33 @@ +<?php + +namespace JsonApi\Routes; + +use JsonApi\Errors\AuthorizationFailedException; +use Psr\Http\Message\ResponseInterface as Response; +use Psr\Http\Message\ServerRequestInterface as Request; +use JsonApi\JsonApiController; +use JsonApi\Errors\RecordNotFoundException; + +class StatusgroupShow extends JsonApiController +{ + protected $allowedIncludePaths = [ + 'range' + ]; + + public function __invoke(Request $request, Response $response, $args) + { + $group = \Statusgruppen::find($args['id']); + if (!$group) { + throw new RecordNotFoundException(); + } + + $user = $this->getUser($request); + $range = $group->range; + + if ($range && !$range->isAccessibleToUser($user->id)) { + throw new AuthorizationFailedException(); + } + + return $this->getContentResponse($group); + } +} diff --git a/lib/models/Statusgruppen.php b/lib/models/Statusgruppen.php index 5775abd01d187af930c33a12883848e6168f5811..b4a0b69e8558824e08bad0d525aeb13e51c96d81 100644 --- a/lib/models/Statusgruppen.php +++ b/lib/models/Statusgruppen.php @@ -42,6 +42,7 @@ * @property BlubberStatusgruppeThread $blubberthread has_one BlubberStatusgruppeThread * @property SimpleORMapCollection|CourseDate[] $dates has_and_belongs_to_many CourseDate * @property mixed $children additional field + * @property-read Range|null $range */ class Statusgruppen extends SimpleORMap implements PrivacyObject { @@ -96,6 +97,12 @@ class Statusgruppen extends SimpleORMap implements PrivacyObject $config['additional_fields']['children'] = true; + $config['additional_fields']['range'] = [ + 'get' => function (Statusgruppen $group): ?Range { + return RangeFactory::find($group->range_id); + }, + ]; + $config['default_values']['position'] = null; $config['registered_callbacks']['before_store'][] = 'cbAddPosition';