mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
API Feature (#334)
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Actions\StorageProvider;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\StorageProvider;
|
||||
use App\Models\User;
|
||||
use Illuminate\Validation\Rule;
|
||||
@ -12,13 +13,13 @@ class CreateStorageProvider
|
||||
/**
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function create(User $user, array $input): void
|
||||
public function create(User $user, Project $project, array $input): StorageProvider
|
||||
{
|
||||
$storageProvider = new StorageProvider([
|
||||
'user_id' => $user->id,
|
||||
'provider' => $input['provider'],
|
||||
'profile' => $input['name'],
|
||||
'project_id' => isset($input['global']) && $input['global'] ? null : $user->current_project_id,
|
||||
'project_id' => isset($input['global']) && $input['global'] ? null : $project->id,
|
||||
]);
|
||||
|
||||
$storageProvider->credentials = $storageProvider->provider()->credentialData($input);
|
||||
@ -36,6 +37,8 @@ public function create(User $user, array $input): void
|
||||
}
|
||||
|
||||
$storageProvider->save();
|
||||
|
||||
return $storageProvider;
|
||||
}
|
||||
|
||||
public static function rules(array $input): array
|
||||
|
@ -3,17 +3,16 @@
|
||||
namespace App\Actions\StorageProvider;
|
||||
|
||||
use App\Models\StorageProvider;
|
||||
use Exception;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class DeleteStorageProvider
|
||||
{
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function delete(StorageProvider $storageProvider): void
|
||||
{
|
||||
if ($storageProvider->backups()->exists()) {
|
||||
throw new Exception('This storage provider is being used by a backup.');
|
||||
throw ValidationException::withMessages([
|
||||
'provider' => __('This storage provider is being used by a backup.'),
|
||||
]);
|
||||
}
|
||||
|
||||
$storageProvider->delete();
|
||||
|
@ -2,18 +2,20 @@
|
||||
|
||||
namespace App\Actions\StorageProvider;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\StorageProvider;
|
||||
use App\Models\User;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class EditStorageProvider
|
||||
{
|
||||
public function edit(StorageProvider $storageProvider, User $user, array $input): void
|
||||
public function edit(StorageProvider $storageProvider, Project $project, array $input): StorageProvider
|
||||
{
|
||||
$storageProvider->profile = $input['name'];
|
||||
$storageProvider->project_id = isset($input['global']) && $input['global'] ? null : $user->current_project_id;
|
||||
$storageProvider->project_id = isset($input['global']) && $input['global'] ? null : $project->id;
|
||||
|
||||
$storageProvider->save();
|
||||
|
||||
return $storageProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user