Merge changes from main

This commit is contained in:
Julien Nahum
2024-01-05 11:12:25 +01:00
7 changed files with 22 additions and 22 deletions

View File

@@ -60,7 +60,7 @@ class AnswerFormRequest extends FormRequest
if(isset($data[$field['id']]) && is_array($data[$field['id']])){
$data[$field['id']] = array_map(function ($val) use ($field) {
$tmpop = collect($field[$field['type']]['options'])->first(function ($op) use ($val) {
return ($op['id'] === $val);
return ($op['id'] ?? $op['value'] === $val);
});
return isset($tmpop['name']) ? $tmpop['name'] : "";
}, $data[$field['id']]);

View File

@@ -126,7 +126,7 @@ abstract class UserFormRequest extends \Illuminate\Foundation\Http\FormRequest
// Custom SEO
'seo_meta' => 'nullable|array',
'custom_domain' => 'sometimes|nullable|regex:/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}$/'
'custom_domain' => 'sometimes|nullable|regex:/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,20}$/'
];
}

View File

@@ -32,7 +32,7 @@ class CustomDomainRequest extends FormRequest
$domains = collect($value)->filter(function ($domain) {
return !empty( trim($domain) );
})->each(function($domain) use (&$errors) {
if (!preg_match('/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}$/', $domain)) {
if (!preg_match('/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,20}$/', $domain)) {
$errors[] = 'Invalid domain: ' . $domain;
}
});

View File

@@ -50,7 +50,8 @@ class FormResource extends JsonResource
'notification_settings' => $this->notification_settings,
'removed_properties' => $this->removed_properties,
'last_edited_human' => $this->updated_at?->diffForHumans(),
'seo_meta' => $this->seo_meta
'seo_meta' => $this->seo_meta,
'max_file_size' => $this->max_file_size / 1000000,
] : [];
$baseData = $this->getFilteredFormData(parent::toArray($request), $this->userIsFormOwner());

View File

@@ -133,6 +133,7 @@ class Form extends Model implements CachableAttributes
protected $cachableAttributes = [
'is_pro',
'views_count',
'max_file_size'
];
/**
@@ -234,6 +235,13 @@ class Form extends Model implements CachableAttributes
return !empty($this->password);
}
public function getMaxFileSizeAttribute()
{
return $this->remember('max_file_size', 15 * 60, function(): int {
return $this->workspace->max_file_size;
});
}
protected function removedProperties(): Attribute
{
return Attribute::make(

View File

@@ -14,9 +14,7 @@ class Workspace extends Model implements CachableAttributes
const MAX_FILE_SIZE_FREE = 5000000; // 5 MB
const MAX_FILE_SIZE_PRO = 50000000; // 50 MB
const MAX_DOMAIN_PRO = 1;
protected $fillable = [
'name',
'icon',