= feaa8b6c93 Feat: Add modular URL app creation with role-based access and Microsoft integration support
- Introduced `StoreURLAppForm` and `StoreURLAppData` for form handling and data transformation.
- Added `UrlAppService` to streamline URL app creation with settings like `accessUrl` and `isConnectedToMicrosoft`.
- Enhanced user access controls with role-based permissions using `UserAccessTypeEnum`.
- Updated UI for URL app creation with support for logos and dynamic role selection.
- Implemented feature tests to validate URL app creation and access URL formatting.
2026-06-22 07:21:26 +00:00

67 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Services\Applications\URL;
use App\Data\Application\StoreURLAppData;
use App\Data\ConnectedApp\{ConnectAppRequest, ConnectedAppData};
use App\Enums\{ConnectionProtocolEnum, ConnectionStatusEnum};
use App\Models\{ConnectionProtocol, ConnectionStatus};
use App\Services\{ApplicationLogoUploader, ConnectedAppService};
use Illuminate\Support\Facades\{DB, Log};
use Illuminate\Support\Str;
use Throwable;
readonly class UrlAppService
{
public function __construct(
private ApplicationLogoUploader $logoUploader,
private ConnectedAppService $connectedAppService,
) {}
/**
* @throws Throwable
*/
public function createApp(StoreURLAppData $data): ConnectedAppData
{
Log::info('Creating URL app', [
'name' => $data->name,
]);
try {
DB::beginTransaction();
$logo = $this->logoUploader->store($data->logo);
$appData = $this->connectedAppService->create(
new ConnectAppRequest(
name: $data->name,
connectionProtocolId: ConnectionProtocol::query()->where('name', ConnectionProtocolEnum::URL->value)->first()->id,
connectionProviderId: 0,
slug: Str::slug($data->name),
connectionStatusId: ConnectionStatus::query()->where('name', ConnectionStatusEnum::Connected->value)->first()->id,
settings: [
'access_url' => $data->accessUrl,
'is_connected_to_microsoft' => $data->isConnectedToMicrosoft,
],
logo: $logo,
)
);
DB::commit();
Log::info('URL app created', [
'name' => $data->name,
'id' => $appData->id,
]);
return $appData;
} catch (Throwable $e) {
DB::rollBack();
Log::error('Failed to create URL app', [
'name' => $data->name,
]);
throw $e;
}
}
}