Adding Custom domains (#247)

* WIP

* wip

* Finished doing most of the work
This commit is contained in:
Julien Nahum
2023-11-29 14:53:08 +01:00
committed by GitHub
parent 57fdfb25a0
commit b50f579155
33 changed files with 1210 additions and 267 deletions

View File

@@ -53,6 +53,7 @@ class Form extends Model
'visibility',
// Customization
'custom_domain',
'theme',
'width',
'cover_picture',
@@ -141,12 +142,15 @@ class Form extends Model
public function getShareUrlAttribute()
{
return url('/forms/'.$this->slug);
if ($this->custom_domain) {
return 'https://' . $this->custom_domain . '/forms/' . $this->slug;
}
return url('/forms/' . $this->slug);
}
public function getEditUrlAttribute()
{
return url('/forms/'.$this->slug.'/show');
return url('/forms/' . $this->slug . '/show');
}
public function getSubmissionsCountAttribute()
@@ -156,12 +160,12 @@ class Form extends Model
public function getViewsCountAttribute()
{
if(env('DB_CONNECTION') == 'pgsql') {
if (env('DB_CONNECTION') == 'pgsql') {
return $this->views()->count() +
$this->statistics()->sum(DB::raw("cast(data->>'views' as integer)"));
} elseif(env('DB_CONNECTION') == 'mysql') {
$this->statistics()->sum(DB::raw("cast(data->>'views' as integer)"));
} elseif (env('DB_CONNECTION') == 'mysql') {
return (int)($this->views()->count() +
$this->statistics()->sum(DB::raw("json_extract(data, '$.views')")));
$this->statistics()->sum(DB::raw("json_extract(data, '$.views')")));
}
return 0;
}
@@ -219,7 +223,8 @@ class Form extends Model
return !empty($this->password);
}
protected function removedProperties(): Attribute {
protected function removedProperties(): Attribute
{
return Attribute::make(
get: function ($value) {
return $value ? json_decode($value, true) : [];
@@ -283,7 +288,7 @@ class Form extends Model
{
return !empty($this->webhook_url);
}
public function getNotifiesDiscordAttribute()
{
return !empty($this->discord_webhook_url);

View File

@@ -42,4 +42,13 @@ class License extends Model
3 => 75000000, // 75 MB,
][$this->meta['tier']];
}
public function getCustomDomainLimitCountAttribute()
{
return [
1 => 5,
2 => 25,
3 => null,
][$this->meta['tier']];
}
}

View File

@@ -14,10 +14,13 @@ class Workspace extends Model
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',
'user_id',
'custom_domain',
];
protected $appends = [
@@ -25,6 +28,10 @@ class Workspace extends Model
'is_enterprise'
];
protected $casts = [
'custom_domains' => 'array',
];
public function getIsProAttribute()
{
if(is_null(config('cashier.key'))){
@@ -60,6 +67,26 @@ class Workspace extends Model
return self::MAX_FILE_SIZE_FREE;
}
public function getCustomDomainCountLimitAttribute()
{
if(is_null(config('cashier.key'))){
return null;
}
// Return max file size depending on subscription
foreach ($this->owners as $owner) {
if ($owner->is_subscribed) {
if ($license = $owner->activeLicense()) {
// In case of special License
return $license->custom_domain_limit_count;
}
}
return self::MAX_DOMAIN_PRO;
}
return 0;
}
public function getIsEnterpriseAttribute()
{
if(is_null(config('cashier.key'))){