mirror of
https://github.com/coollabsio/coolify.git
synced 2026-03-11 08:55:47 +00:00
feat: add OAuth-only self-registration setting
This commit is contained in:
parent
5ef5353a96
commit
4367595a9f
1 changed files with 24 additions and 106 deletions
|
|
@ -2,123 +2,41 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Once;
|
||||
use Spatie\Url\Url;
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
#[OA\Schema(
|
||||
description: 'Instance Settings',
|
||||
type: 'object',
|
||||
properties: [
|
||||
'id' => ['type' => 'integer', 'description' => 'The instance settings identifier in the database.'],
|
||||
'fqdn' => ['type' => 'string', 'description' => 'The fully qualified domain name of the instance.'],
|
||||
'resale_license' => ['type' => 'string', 'description' => 'The resale license of the instance.'],
|
||||
'is_registration_enabled' => ['type' => 'boolean', 'description' => 'Whether general registration is enabled.'],
|
||||
'is_oauth_registration_enabled' => ['type' => 'boolean', 'description' => 'Whether registration via OAuth is enabled even when general registration is disabled.'],
|
||||
'is_auto_update_enabled' => ['type' => 'boolean', 'description' => 'Whether auto update is enabled.'],
|
||||
'is_backup_enabled' => ['type' => 'boolean', 'description' => 'Whether backup is enabled.'],
|
||||
'is_analytics_enabled' => ['type' => 'boolean', 'description' => 'Whether analytics is enabled.'],
|
||||
]
|
||||
)]
|
||||
class InstanceSettings extends Model
|
||||
{
|
||||
protected $table = 'instance_settings';
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'smtp_enabled' => 'boolean',
|
||||
'smtp_from_address' => 'encrypted',
|
||||
'smtp_from_name' => 'encrypted',
|
||||
'smtp_recipients' => 'encrypted',
|
||||
'smtp_host' => 'encrypted',
|
||||
'smtp_port' => 'integer',
|
||||
'smtp_username' => 'encrypted',
|
||||
'smtp_password' => 'encrypted',
|
||||
'smtp_timeout' => 'integer',
|
||||
|
||||
'resend_enabled' => 'boolean',
|
||||
'resend_api_key' => 'encrypted',
|
||||
|
||||
'allowed_ip_ranges' => 'array',
|
||||
'is_registration_enabled' => 'boolean',
|
||||
'is_oauth_registration_enabled' => 'boolean',
|
||||
'is_auto_update_enabled' => 'boolean',
|
||||
'auto_update_frequency' => 'string',
|
||||
'update_check_frequency' => 'string',
|
||||
'sentinel_token' => 'encrypted',
|
||||
'is_wire_navigate_enabled' => 'boolean',
|
||||
'is_backup_enabled' => 'boolean',
|
||||
'is_analytics_enabled' => 'boolean',
|
||||
'is_dns_validation_enabled' => 'boolean',
|
||||
'is_api_enabled' => 'boolean',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::updated(function ($settings) {
|
||||
// Clear once() cache so subsequent calls get fresh data
|
||||
Once::flush();
|
||||
|
||||
// Clear trusted hosts cache when FQDN changes
|
||||
if ($settings->wasChanged('fqdn')) {
|
||||
\Cache::forget('instance_settings_fqdn_host');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function fqdn(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
set: function ($value) {
|
||||
if ($value) {
|
||||
$url = Url::fromString($value);
|
||||
$host = $url->getHost();
|
||||
|
||||
return $url->getScheme().'://'.$host;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function updateCheckFrequency(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
set: function ($value) {
|
||||
return translate_cron_expression($value);
|
||||
},
|
||||
get: function ($value) {
|
||||
return translate_cron_expression($value);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function autoUpdateFrequency(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
set: function ($value) {
|
||||
return translate_cron_expression($value);
|
||||
},
|
||||
get: function ($value) {
|
||||
return translate_cron_expression($value);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static function get()
|
||||
{
|
||||
return once(fn () => InstanceSettings::findOrFail(0));
|
||||
return self::findOrFail(0);
|
||||
}
|
||||
|
||||
// public function getRecipients($notification)
|
||||
// {
|
||||
// $recipients = data_get($notification, 'emails', null);
|
||||
// if (is_null($recipients) || $recipients === '') {
|
||||
// return [];
|
||||
// }
|
||||
|
||||
// return explode(',', $recipients);
|
||||
// }
|
||||
|
||||
public function getTitleDisplayName(): string
|
||||
{
|
||||
$instanceName = $this->instance_name;
|
||||
if (! $instanceName) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return "[{$instanceName}]";
|
||||
}
|
||||
|
||||
// public function helperVersion(): Attribute
|
||||
// {
|
||||
// return Attribute::make(
|
||||
// get: function ($value) {
|
||||
// if (isDev()) {
|
||||
// return 'latest';
|
||||
// }
|
||||
|
||||
// return $value;
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue