Skip to content

Commit

Permalink
fix api (#1827)
Browse files Browse the repository at this point in the history
* fix api
* only available as admin
  • Loading branch information
ildyria committed May 7, 2023
1 parent 9957db8 commit 61d6e09
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 58 deletions.
7 changes: 4 additions & 3 deletions app/Http/Resources/Collections/AlbumForestResource.php
Expand Up @@ -15,7 +15,8 @@ public function __construct(
private Collection $albums,
private ?Collection $sharedAlbums = null
) {
parent::__construct(null);
// Laravel applies a shortcut when this value === null but not when it is something else.
parent::__construct('must_not_be_null');

$this->albums = $albums;
$this->sharedAlbums = $sharedAlbums ?? new Collection();
Expand All @@ -31,8 +32,8 @@ public function __construct(
public function toArray($request)
{
return [
'albums' => AlbumTreeResource::collection($this->albums)->toArray($request),
'shared_albums' => AlbumTreeResource::collection($this->sharedAlbums)->toArray($request),
'albums' => AlbumTreeResource::collection($this->albums),
'shared_albums' => AlbumTreeResource::collection($this->sharedAlbums),
];
}
}
2 changes: 1 addition & 1 deletion app/Http/Resources/Collections/PositionDataResource.php
Expand Up @@ -45,7 +45,7 @@ public function toArray($request)
return [
'id' => $this->id,
'title' => $this->title,
'photos' => PhotoResource::collection($this->resource)->toArray($request),
'photos' => PhotoResource::collection($this->resource),
'track_url' => $this->track_url,
];
}
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Resources/Collections/TopAlbumsResource.php
Expand Up @@ -26,7 +26,8 @@ public function __construct(
public Collection $albums,
public ?Collection $shared_albums = null
) {
parent::__construct(null);
// Laravel applies a shortcut when this value === null but not when it is something else.
parent::__construct('must_not_be_null');

$this->shared_albums ??= new Collection();
}
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Resources/ConfigurationResource.php
Expand Up @@ -20,7 +20,8 @@ class ConfigurationResource extends JsonResource
{
public function __construct()
{
parent::__construct(null);
// Laravel applies a shortcut when this value === null but not when it is something else.
parent::__construct('must_not_be_null');
}

/**
Expand Down
7 changes: 4 additions & 3 deletions app/Http/Resources/InitResource.php
Expand Up @@ -14,7 +14,8 @@ class InitResource extends JsonResource
{
public function __construct()
{
parent::__construct(null);
// Laravel applies a shortcut when this value === null but not when it is something else.
parent::__construct('must_not_be_null');
}

/**
Expand All @@ -39,8 +40,8 @@ public function toArray($request): array

return [
'user' => $this->when(Auth::check(), UserResource::make(Auth::user()), null),
'rights' => GlobalRightsResource::make()->toArray($request),
'config' => ConfigurationResource::make()->toArray($request),
'rights' => GlobalRightsResource::make(),
'config' => ConfigurationResource::make(),
'update_json' => !$fileVersion->isUpToDate(),
'update_available' => !$gitHubVersion->isUpToDate(),
'locale' => $locale,
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/Models/AlbumResource.php
Expand Up @@ -47,7 +47,7 @@ public function toArray($request)
'parent_id' => $this->resource->parent_id,
'has_albums' => !$this->resource->isLeaf(),
'albums' => AlbumResource::collection($this->whenLoaded('children')),
'photos' => new PhotoCollectionResource($this->whenLoaded('photos')),
'photos' => PhotoCollectionResource::make($this->whenLoaded('photos')),
'num_subalbums' => $this->resource->num_children,
'num_photos' => $this->resource->num_photos,

Expand Down
3 changes: 2 additions & 1 deletion app/Http/Resources/Rights/AlbumRightsResource.php
Expand Up @@ -26,7 +26,8 @@ class AlbumRightsResource extends JsonResource
*/
public function __construct(AbstractAlbum $abstractAlbum)
{
parent::__construct(null);
// Laravel applies a shortcut when this value === null but not when it is something else.
parent::__construct('must_not_be_null');

$this->can_edit = Gate::check(AlbumPolicy::CAN_EDIT, [AbstractAlbum::class, $abstractAlbum]);
$this->can_share_with_users = Gate::check(AlbumPolicy::CAN_SHARE_WITH_USERS, [AbstractAlbum::class, $abstractAlbum]);
Expand Down
11 changes: 6 additions & 5 deletions app/Http/Resources/Rights/GlobalRightsResource.php
Expand Up @@ -11,7 +11,8 @@ class GlobalRightsResource extends JsonResource
{
public function __construct()
{
parent::__construct(null);
// Laravel applies a shortcut when this value === null but not when it is something else.
parent::__construct('must_not_be_null');
}

/**
Expand All @@ -24,10 +25,10 @@ public function __construct()
public function toArray($request)
{
return [
'root_album' => RootAlbumRightsResource::make()->toArray($request),
'settings' => SettingsRightsResource::make()->toArray($request),
'user_management' => UserManagementRightsResource::make()->toArray($request),
'user' => UserRightsResource::make()->toArray($request),
'root_album' => RootAlbumRightsResource::make(),
'settings' => SettingsRightsResource::make(),
'user_management' => UserManagementRightsResource::make(),
'user' => UserRightsResource::make(),
];
}
}
3 changes: 2 additions & 1 deletion app/Http/Resources/Rights/PhotoRightsResource.php
Expand Up @@ -25,7 +25,8 @@ class PhotoRightsResource extends JsonResource
*/
public function __construct(Photo $photo)
{
parent::__construct(null);
// Laravel applies a shortcut when this value === null but not when it is something else.
parent::__construct('must_not_be_null');
$this->can_edit = Gate::check(PhotoPolicy::CAN_EDIT, [Photo::class, $photo]);
$this->can_download = Gate::check(PhotoPolicy::CAN_DOWNLOAD, [Photo::class, $photo]);
$this->can_access_full_photo = Gate::check(PhotoPolicy::CAN_ACCESS_FULL_PHOTO, [Photo::class, $photo]);
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Resources/Rights/RootAlbumRightsResource.php
Expand Up @@ -14,7 +14,8 @@ class RootAlbumRightsResource extends JsonResource
{
public function __construct()
{
parent::__construct(null);
// Laravel applies a shortcut when this value === null but not when it is something else.
parent::__construct('must_not_be_null');
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Resources/Rights/SettingsRightsResource.php
Expand Up @@ -14,7 +14,8 @@ class SettingsRightsResource extends JsonResource
{
public function __construct()
{
parent::__construct(null);
// Laravel applies a shortcut when this value === null but not when it is something else.
parent::__construct('must_not_be_null');
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Resources/Rights/UserManagementRightsResource.php
Expand Up @@ -14,7 +14,8 @@ class UserManagementRightsResource extends JsonResource
{
public function __construct()
{
parent::__construct(null);
// Laravel applies a shortcut when this value === null but not when it is something else.
parent::__construct('must_not_be_null');
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Resources/Rights/UserRightsResource.php
Expand Up @@ -14,7 +14,8 @@ class UserRightsResource extends JsonResource
{
public function __construct()
{
parent::__construct(null);
// Laravel applies a shortcut when this value === null but not when it is something else.
parent::__construct('must_not_be_null');
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Resources/SearchResource.php
Expand Up @@ -18,7 +18,8 @@ public function __construct(
public Collection $tag_albums,
public Collection $photos,
) {
parent::__construct(null);
// Laravel applies a shortcut when this value === null but not when it is something else.
parent::__construct('must_not_be_null');
}

/**
Expand Down
9 changes: 5 additions & 4 deletions app/Http/Resources/Sharing/SharesResource.php
Expand Up @@ -15,7 +15,8 @@ public function __construct(
public Collection $albums,
public Collection $users)
{
parent::__construct(null);
// Laravel applies a shortcut when this value === null but not when it is something else.
parent::__construct('must_not_be_null');
}

/**
Expand All @@ -28,9 +29,9 @@ public function __construct(
public function toArray($request): array
{
return [
'shared' => SharedAlbumResource::collection($this->shared)->toArray($request),
'albums' => ListedAlbumsResource::collection($this->albums)->toArray($request),
'users' => UserSharedResource::collection($this->users)->toArray($request),
'shared' => SharedAlbumResource::collection($this->shared),
'albums' => ListedAlbumsResource::collection($this->albums),
'users' => UserSharedResource::collection($this->users),
];
}
}
5 changes: 3 additions & 2 deletions composer.json
Expand Up @@ -65,14 +65,15 @@
"ext-zip": "*",
"barryvdh/laravel-debugbar": "^3.6",
"barryvdh/laravel-ide-helper": "^2.10",
"dedoc/scramble": "^0.7.2",
"filp/whoops": "^2.5",
"friendsofphp/php-cs-fixer": "^3.3",
"itsgoingd/clockwork": "^5.1",
"lychee-org/phpstan-lychee": "^v1.0.1",
"mockery/mockery": "^1.5",
"phpunit/phpunit": "^10.0",
"nunomaduro/larastan": "^2.0",
"php-parallel-lint/php-parallel-lint": "^1.3"
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpunit/phpunit": "^10.0"
},
"autoload": {
"classmap": [
Expand Down
77 changes: 76 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions config/scramble.php
@@ -0,0 +1,50 @@
<?php

return [
/*
* Your API path. By default, all routes starting with this path will be added to the docs.
* If you need to change this behavior, you can add your custom routes resolver using `Scramble::routes()`.
*/
'api_path' => 'api',

/*
* Your API domain. By default, app domain is used. This is also a part of the default API routes
* matcher, so when implementing your own, make sure you use this config if needed.
*/
'api_domain' => null,

'info' => [
/*
* API version.
*/
'version' => env('API_VERSION', '0.0.1'),

/*
* Description rendered on the home page of the API documentation (`/docs/api`).
*/
'description' => '',
],

/*
* The list of servers of the API. By default (when `null`), server URL will be created from
* `scramble.api_path` and `scramble.api_domain` config variables. When providing an array, you
* will need to specify the local server URL manually (if needed).
*
* Example of non-default config (final URLs are generated using Laravel `url` helper):
*
* ```php
* 'servers' => [
* 'Live' => 'api',
* 'Prod' => 'https://scramble.dedoc.co/api',
* ],
* ```
*/
'servers' => null,

'middleware' => [
// Only available for admin
'web-admin',
],

'extensions' => [],
];
1 change: 0 additions & 1 deletion routes/api.php
Expand Up @@ -157,7 +157,6 @@
/**
* SETTINGS.
*/
Route::post('/Settings::setLogin', [Administration\SettingsController::class, 'setLogin']);
Route::post('/Settings::setSorting', [Administration\SettingsController::class, 'setSorting']);
Route::post('/Settings::setLang', [Administration\SettingsController::class, 'setLang']);
Route::post('/Settings::setLayout', [Administration\SettingsController::class, 'setLayout']);
Expand Down

0 comments on commit 61d6e09

Please sign in to comment.