From d4bc7a9a801263919e9bca4e0dbeba04064573ef Mon Sep 17 00:00:00 2001 From: Leon Jacobs Date: Fri, 18 May 2018 21:40:59 +0200 Subject: [PATCH] Apply settings to a group rather than a specific user. --- composer.json | 1 + src/Settings/Profile.php | 5 ++- src/Settings/Settings.php | 13 ++++--- ...8_05_18_185619_move_settings_to_groups.php | 36 +++++++++++++++++++ 4 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 src/database/migrations/2018_05_18_185619_move_settings_to_groups.php diff --git a/composer.json b/composer.json index 4d792195..fe0c4cbe 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,7 @@ "php": ">=7.1", "laravel/framework": "5.5.*", "coduo/php-humanizer": "^2.0", + "doctrine/dbal": "^2.6", "eveseat/eveapi": "~3" }, "extra": { diff --git a/src/Settings/Profile.php b/src/Settings/Profile.php index 2b5b4791..bd621be5 100644 --- a/src/Settings/Profile.php +++ b/src/Settings/Profile.php @@ -75,15 +75,18 @@ class Profile extends Settings 'language' => 'en', 'mail_threads' => 'yes', + // A groups main character_id + 'main_character_id' => 0, + // Numbers 'thousand_seperator' => ' ', 'decimal_seperator' => '.', // Notifications 'email_notifications' => 'no', + 'email_address' => '', // Multi factor authentication 'require_mfa' => 'no', ]; - } diff --git a/src/Settings/Settings.php b/src/Settings/Settings.php index fe8e6817..a21a6983 100644 --- a/src/Settings/Settings.php +++ b/src/Settings/Settings.php @@ -80,9 +80,9 @@ public static function get($name, $for_id = null) $value = (new static::$model); // If we are not in the global scope, add a constraint - // to be user specific. + // to be user group specific. if (static::$scope != 'global') - $value = $value->where('user_id', + $value = $value->where('group_id', is_null($for_id) ? auth()->user()->id : $for_id); // Retrieve the value @@ -138,10 +138,10 @@ public static function set($name, $value, $for_id = null) $db = (new static::$model); // If we are not in the global scope, add a constraint - // to be user specific. + // to be user group specific. if (static::$scope != 'global') - $db = $db->where('user_id', - is_null($for_id) ? auth()->user()->id : $for_id); + $db = $db->where('group_id', + is_null($for_id) ? auth()->user()->group->id : $for_id); // Retrieve the value $db = $db->where('name', $name) @@ -163,12 +163,11 @@ public static function set($name, $value, $for_id = null) // Again, if we are not in the global context, then // we need to constrain this setting to a user. if (static::$scope != 'global') - $db->user_id = is_null($for_id) ? auth()->user()->id : $for_id; + $db->group_id = is_null($for_id) ? auth()->user()->group->id : $for_id; $db->save(); // Update the cached entry with the new value Cache::forever(self::get_key_prefix($name), json_decode($value)); - } } diff --git a/src/database/migrations/2018_05_18_185619_move_settings_to_groups.php b/src/database/migrations/2018_05_18_185619_move_settings_to_groups.php new file mode 100644 index 00000000..eca5fa44 --- /dev/null +++ b/src/database/migrations/2018_05_18_185619_move_settings_to_groups.php @@ -0,0 +1,36 @@ +renameColumn('user_id', 'group_id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + + Schema::table('user_settings', function (Blueprint $table) { + + $table->renameColumn('group_id', 'user_id'); + }); + } +}