From d7c175ab11262b77be5f7e739631c0790e0d7850 Mon Sep 17 00:00:00 2001 From: Timot Tarjani Date: Thu, 9 Jan 2025 12:20:22 +0100 Subject: [PATCH] Introduce settings group --- app/Model/Settings.php | 4 +- app/Model/UserRole.php | 8 ++-- ...016_10_20_000000_create_settings_table.php | 2 +- database/seeders/SettingsSeeder.php | 38 +++++++++++++++++++ routes/api.php | 8 ++++ 5 files changed, 53 insertions(+), 7 deletions(-) diff --git a/app/Model/Settings.php b/app/Model/Settings.php index 34a8bbefe..34e60a8bf 100644 --- a/app/Model/Settings.php +++ b/app/Model/Settings.php @@ -69,6 +69,8 @@ public function assignAll(){ } - + public function scopeGroup($query, $group){ + return $query->where('group', $group); + } } diff --git a/app/Model/UserRole.php b/app/Model/UserRole.php index c0866fa23..ce0696070 100644 --- a/app/Model/UserRole.php +++ b/app/Model/UserRole.php @@ -26,15 +26,13 @@ public function users(){ } public function addRight($right){ - $all_rights = $this->getRightsAttribute(); + $all_rights = $this->rights; array_push($all_rights, $right); - $this->setRightsAttribute($all_rights); + $this->rights = $all_rights; } public function isAdminRole(){ - $roles = $this->attributes['rights']; - - return $roles? in_array('admin_area',$roles) : false; + return $this->rights? in_array('admin_area',$this->rights) : false; } } diff --git a/database/migrations/2016_10_20_000000_create_settings_table.php b/database/migrations/2016_10_20_000000_create_settings_table.php index e9586bda7..5aa32f06d 100644 --- a/database/migrations/2016_10_20_000000_create_settings_table.php +++ b/database/migrations/2016_10_20_000000_create_settings_table.php @@ -19,10 +19,10 @@ public function up() Schema::create($this->table_name, function (Blueprint $table) { $table->increments('id'); + $table->string('group')->nullable(); $table->string('setting')->comment("Key"); $table->string('value',4000)->nullable()->comment("Value"); $table->timestamps(); - $table->boolean('more')->default(NULL); }); } diff --git a/database/seeders/SettingsSeeder.php b/database/seeders/SettingsSeeder.php index ba09dfeb1..c9eb0475d 100644 --- a/database/seeders/SettingsSeeder.php +++ b/database/seeders/SettingsSeeder.php @@ -17,6 +17,7 @@ public function run() { DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'title', 'value' => "Your title", 'more' => '1', @@ -24,216 +25,252 @@ public function run() DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'site_name', 'value' => "Your site", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'slogan', 'value' => "Your awesome slogan", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'favicon', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'scroll_text', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'default_email', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'address', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'default_phone', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'contact', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'theme', 'value' => 'TheWright', 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'language', 'value' => 'en', 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'date_format', 'value' => "Y.m.d H:i:s", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'home_page', 'value' => 1, 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'website_down', 'value' => "0", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'logo', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'favicon', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'admin', 'setting' => 'admin_logo', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'website_debug', 'value' => "0", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'admin', 'setting' => 'admin_debug', 'value' => "0", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'admin', 'setting' => 'admin_broadcast', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'website_type', 'value' => "website", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'blogposts_on_page', 'value' => "5", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'admin', 'setting' => 'default_user_role', 'value' => "2", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'admin', 'setting' => 'auto_upgrade_check', 'value' => "1", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'use_https', 'value' => "0", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'social_link_facebook', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'social_link_youtube', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'social_link_twitter', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'social_link_instagram', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'social_link_google', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'social_link_linkedin', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'social_link_github', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'social_link_gitlab', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'social_link_spotify', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'social_link_soundcloud', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'social_link_steam', 'value' => "", 'more' => '1', ]); DB::table('settings')->insert([ + 'group' => 'website', 'setting' => 'social_link_reddit', 'value' => "", 'more' => '1', @@ -241,6 +278,7 @@ public function run() DB::table('settings')->insert([ + 'group' => 'admin', 'setting' => 'scheduler', 'value' => "not configured", 'more' => '1', diff --git a/routes/api.php b/routes/api.php index 9ceffba32..8ccb0dd49 100644 --- a/routes/api.php +++ b/routes/api.php @@ -58,6 +58,14 @@ Route::apiResource('header-images', \App\Controllers\HeaderImageController::class) ->only(['index', 'show']); +Route::get('/settings', function(Request $request){ + + $settings = \App\Model\Settings::group('website')->get(); + + return response()->json($settings); + +}); + Route::get('/users',function(Request $request){ if(\Auth::user()->hasPermission("users")){