Separated laravel app to its own folder (#540)

This commit is contained in:
Julien Nahum
2024-08-26 18:24:56 +02:00
committed by GitHub
parent 39b8df5eed
commit 5bd1dda504
546 changed files with 124 additions and 143 deletions

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @property \App\Models\Integration\FormIntegration $resource
*/
class FormIntegrationResource extends JsonResource
{
public function toArray($request)
{
return [
...parent::toArray($request),
'provider' => OAuthProviderResource::make($this->resource->provider),
];
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class FormIntegrationsEventResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return [
'date' => date('Y-m-d H:i', strtotime($this->created_at)),
'status' => ucfirst($this->status),
'data' => $this->data
];
}
}

View File

@@ -0,0 +1,112 @@
<?php
namespace App\Http\Resources;
use App\Http\Middleware\Form\ProtectedForm;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Auth;
class FormResource extends JsonResource
{
private array $cleanings = [];
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
if (!$this->userIsFormOwner() && ProtectedForm::isProtected($request, $this->resource)) {
return $this->getProtectedForm();
}
$ownerData = $this->userIsFormOwner() ? [
'views_count' => $this->views_count,
'submissions_count' => $this->submissions_count,
'redirect_url' => $this->redirect_url,
'database_fields_update' => $this->database_fields_update,
'cleanings' => $this->getCleanigns(),
'can_be_indexed' => $this->can_be_indexed,
'password' => $this->password,
'tags' => $this->tags,
'visibility' => $this->visibility,
'removed_properties' => $this->removed_properties,
'last_edited_human' => $this->updated_at?->diffForHumans(),
'seo_meta' => $this->seo_meta,
] : [];
return array_merge(parent::toArray($request), $ownerData, [
'is_pro' => $this->workspaceIsPro(),
'is_trialing' => $this->workspaceIsTrialing(),
'workspace_id' => $this->workspace_id,
'workspace' => new WorkspaceResource($this->getWorkspace()),
'is_closed' => $this->is_closed,
'is_password_protected' => false,
'has_password' => $this->has_password,
'max_number_of_submissions_reached' => $this->max_number_of_submissions_reached,
'form_pending_submission_key' => $this->form_pending_submission_key,
'max_file_size' => $this->max_file_size / 1000000,
]);
}
public function setCleanings(array $cleanings)
{
$this->cleanings = $cleanings;
return $this;
}
private function getProtectedForm()
{
return [
'id' => $this->id,
'title' => $this->title,
'description' => $this->description,
'slug' => $this->slug,
'custom_code' => $this->custom_code,
'dark_mode' => $this->dark_mode,
'transparent_background' => $this->transparent_background,
'color' => $this->color,
'theme' => $this->theme,
'is_password_protected' => true,
'has_password' => $this->has_password,
'width' => 'centered',
'no_branding' => $this->no_branding,
'properties' => [],
'logo_picture' => $this->logo_picture,
'seo_meta' => $this->seo_meta,
'cover_picture' => $this->cover_picture,
];
}
private function getWorkspace()
{
return $this->extra?->loadedWorkspace ?? $this->workspace;
}
private function workspaceIsPro()
{
return $this->extra?->workspaceIsPro ?? $this->getWorkspace()->is_pro ?? $this->is_pro;
}
private function workspaceIsTrialing()
{
return $this->getWorkspace()->is_trialing;
}
private function userIsFormOwner()
{
return $this->extra?->userIsOwner ??
(
Auth::check() && Auth::user()->ownsForm($this->resource)
);
}
private function getCleanigns()
{
return $this->extra?->cleanings ?? $this->cleanings;
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class FormSubmissionResource extends JsonResource
{
public bool $publiclyAccessed = false;
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
$this->generateFileLinks();
if (!$this->publiclyAccessed) {
$this->addExtraData();
}
return array_merge([
'data' => $this->data
], ($this->publiclyAccessed) ? [] : [
'form_id' => $this->form_id,
'id' => $this->id
]);
}
public function publiclyAccessed($publiclyAccessed = true)
{
$this->publiclyAccessed = $publiclyAccessed;
return $this;
}
private function addExtraData()
{
$this->data = array_merge($this->data, [
'created_at' => $this->created_at->toDateTimeString(),
'id' => $this->id,
]);
}
/**
* Link to the file (generating signed s3 URL)
*
* @return void
*/
private function generateFileLinks()
{
$data = $this->data;
$formFields = collect($this->form->properties)->concat(collect($this->form->removed_properties));
$fileFields = $formFields->filter(function ($field) {
return in_array($field['type'], ['files', 'signature']);
});
foreach ($fileFields as $field) {
if (isset($data[$field['id']]) && !empty($data[$field['id']])) {
$data[$field['id']] = collect($data[$field['id']])->filter(function ($file) {
return $file !== null && $file;
})->map(function ($file) {
return [
'file_url' => \URL::signedRoute(
'open.forms.submissions.file',
[$this->form_id, $file],
now()->addMinutes(10)
),
'file_name' => $file,
];
});
}
}
$this->data = $data;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class FormTemplateResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return array_merge(parent::toArray($request), [
'is_new' => $this->created_at->isAfter(now()->subDays(7)),
]);
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Auth;
/**
* @property \App\Models\OAuthProvider $resource
*/
class OAuthProviderResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
$userId = Auth::id();
$intention = cache()->get("oauth-intention:{$userId}");
return [
'id' => $this->resource->id,
'provider' => $this->resource->provider,
'name' => $this->resource->name,
'email' => $this->resource->email,
'intention' => $intention,
'user' => $this->whenLoaded(
'user',
fn () => OAuthProviderUserResource::make($this->resource->user),
null,
),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @property \App\Models\User $resource
*/
class OAuthProviderUserResource extends JsonResource
{
public function toArray($request)
{
return [
'name' => $this->resource->name,
'email' => $this->resource->email,
];
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @property \Laravel\Sanctum\PersonalAccessToken $resource
*/
class TokenResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->resource->id,
'name' => $this->resource->name,
'abilities' => $this->resource->abilities,
];
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class UserResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
$personalData = \Auth::id() === $this->id ? [
'is_subscribed' => $this->is_subscribed,
'has_enterprise_subscription' => $this->has_enterprise_subscription,
'admin' => $this->admin,
'moderator' => $this->moderator,
'template_editor' => $this->template_editor,
'has_customer_id' => $this->has_customer_id,
'has_forms' => $this->has_forms,
'active_license' => $this->licenses()->active()->first(),
] : [];
return array_merge(parent::toArray($request), $personalData);
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class WorkspaceResource extends JsonResource
{
public static $wrap = null;
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return array_merge(parent::toArray($request), [
'max_file_size' => $this->max_file_size / 1000000,
]);
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Http\Resources\Zapier;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @property \App\Models\Forms\Form $resource
*/
class FormResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->resource->id,
'name' => $this->resource->title,
'label' => $this->resource->title . ' (' . $this->resource->slug . ')'
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Http\Resources\Zapier;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @property \App\Models\Workspace $resource
*/
class WorkspaceResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->resource->id,
'name' => $this->resource->name,
];
}
}