Skip to content

Commit

Permalink
Apply settings to a group rather than a specific user.
Browse files Browse the repository at this point in the history
  • Loading branch information
leonjza committed May 18, 2018
1 parent 0d3b09c commit d4bc7a9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"php": ">=7.1",
"laravel/framework": "5.5.*",
"coduo/php-humanizer": "^2.0",
"doctrine/dbal": "^2.6",
"eveseat/eveapi": "~3"
},
"extra": {
Expand Down
5 changes: 4 additions & 1 deletion src/Settings/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];

}
13 changes: 6 additions & 7 deletions src/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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));

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class MoveSettingsToGroups extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{

Schema::table('user_settings', function (Blueprint $table) {

$table->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');
});
}
}

0 comments on commit d4bc7a9

Please sign in to comment.