mirror of
				https://github.com/grocy/grocy.git
				synced 2025-10-31 10:46:36 +00:00 
			
		
		
		
	Always execute migration 9999 (can be used to fix things manually) Optimized meal plan navigation / date range filtering Prepared next release Pulled translations from Transifex Various code optimizations
		
			
				
	
	
		
			89 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			89 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace Grocy\Controllers;
 | |
| 
 | |
| use Grocy\Controllers\Users\User;
 | |
| 
 | |
| class OpenApiController extends BaseApiController
 | |
| {
 | |
| 	public function ApiKeysList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
 | |
| 	{
 | |
| 		$apiKeys = $this->getDatabase()->api_keys();
 | |
| 		if (!User::hasPermissions(User::PERMISSION_ADMIN))
 | |
| 		{
 | |
| 			$apiKeys = $apiKeys->where('user_id', GROCY_USER_ID);
 | |
| 		}
 | |
| 		return $this->renderPage($response, 'manageapikeys', [
 | |
| 			'apiKeys' => $apiKeys,
 | |
| 			'users' => $this->getDatabase()->users()
 | |
| 		]);
 | |
| 	}
 | |
| 
 | |
| 	public function CreateNewApiKey(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
 | |
| 	{
 | |
| 		$newApiKey = $this->getApiKeyService()->CreateApiKey();
 | |
| 		$newApiKeyId = $this->getApiKeyService()->GetApiKeyId($newApiKey);
 | |
| 		return $response->withRedirect($this->AppContainer->get('UrlManager')->ConstructUrl("/manageapikeys?CreatedApiKeyId=$newApiKeyId"));
 | |
| 	}
 | |
| 
 | |
| 	public function DocumentationSpec(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
 | |
| 	{
 | |
| 		$spec = $this->getOpenApiSpec();
 | |
| 
 | |
| 		$applicationService = $this->getApplicationService();
 | |
| 		$versionInfo = $applicationService->GetInstalledVersion();
 | |
| 		$spec->info->version = $versionInfo->Version;
 | |
| 		$spec->info->description = str_replace('PlaceHolderManageApiKeysUrl', $this->AppContainer->get('UrlManager')->ConstructUrl('/manageapikeys'), $spec->info->description);
 | |
| 		$spec->servers[0]->url = $this->AppContainer->get('UrlManager')->ConstructUrl('/api');
 | |
| 
 | |
| 		$spec->components->schemas->ExposedEntity_IncludingUserEntities = clone $spec->components->schemas->ExposedEntity;
 | |
| 		foreach ($this->getUserfieldsService()->GetEntities() as $userEntity)
 | |
| 		{
 | |
| 			array_push($spec->components->schemas->ExposedEntity_IncludingUserEntities->enum, $userEntity);
 | |
| 		}
 | |
| 
 | |
| 		$spec->components->schemas->ExposedEntity_NotIncludingNotEditable = clone $spec->components->schemas->StringEnumTemplate;
 | |
| 		foreach ($spec->components->schemas->ExposedEntity->enum as $value)
 | |
| 		{
 | |
| 			if (!in_array($value, $spec->components->schemas->ExposedEntityNoEdit->enum))
 | |
| 			{
 | |
| 				array_push($spec->components->schemas->ExposedEntity_NotIncludingNotEditable->enum, $value);
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		$spec->components->schemas->ExposedEntity_IncludingUserEntities_NotIncludingNotEditable = clone $spec->components->schemas->StringEnumTemplate;
 | |
| 		foreach ($spec->components->schemas->ExposedEntity_IncludingUserEntities->enum as $value)
 | |
| 		{
 | |
| 			if (!in_array($value, $spec->components->schemas->ExposedEntityNoEdit->enum))
 | |
| 			{
 | |
| 				array_push($spec->components->schemas->ExposedEntity_IncludingUserEntities_NotIncludingNotEditable->enum, $value);
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		$spec->components->schemas->ExposedEntity_NotIncludingNotDeletable = clone $spec->components->schemas->StringEnumTemplate;
 | |
| 		foreach ($spec->components->schemas->ExposedEntity->enum as $value)
 | |
| 		{
 | |
| 			if (!in_array($value, $spec->components->schemas->ExposedEntityNoDelete->enum))
 | |
| 			{
 | |
| 				array_push($spec->components->schemas->ExposedEntity_NotIncludingNotDeletable->enum, $value);
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		$spec->components->schemas->ExposedEntity_NotIncludingNotListable = clone $spec->components->schemas->StringEnumTemplate;
 | |
| 		foreach ($spec->components->schemas->ExposedEntity->enum as $value)
 | |
| 		{
 | |
| 			if (!in_array($value, $spec->components->schemas->ExposedEntityNoListing->enum))
 | |
| 			{
 | |
| 				array_push($spec->components->schemas->ExposedEntity_NotIncludingNotListable->enum, $value);
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		return $this->ApiResponse($response, $spec);
 | |
| 	}
 | |
| 
 | |
| 	public function DocumentationUi(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
 | |
| 	{
 | |
| 		return $this->render($response, 'openapiui');
 | |
| 	}
 | |
| }
 |