Skip to content

Commit

Permalink
refactor(acl): drop Group class and use an unique user bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
warlof committed Nov 16, 2019
1 parent a7e1e02 commit e27af33
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Helpers/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function human_diff($time)
* @return string
* @throws \Seat\Services\Exceptions\EveImageException
*/
function img(string $type, string $variation, $id, int $size, array $attr, $lazy = true)
function img(string $type, string $variation, $id, int $size, array $attr = [], $lazy = true)
{

$image = (new \Seat\Services\Image\Eve($type, $variation, (int) $id, $size, $attr, $lazy))
Expand Down
4 changes: 1 addition & 3 deletions src/Image/Eve.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Eve
* @param bool $lazy
* @throws \Seat\Services\Exceptions\EveImageException
*/
public function __construct(string $type, string $variation, int $id, int $size, array $attr, bool $lazy = true)
public function __construct(string $type, string $variation, int $id, int $size, array $attr = [], bool $lazy = true)
{

// Validate the arguments
Expand Down Expand Up @@ -209,8 +209,6 @@ public function html()
*/
public function url($size)
{

return sprintf('%s/%s/%d/%s?size=%d', $this->img_server, $this->type, $this->id, $this->variation, $size);

}
}
2 changes: 1 addition & 1 deletion src/Repositories/Configuration/UserRespository.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getAllFullUsers() : Builder
public function getFullUser($user_id)
{

return UserModel::with('group', 'group.users', 'group.roles.permissions')
return UserModel::with('refresh_tokens', 'characters', 'roles.permissions')
->where('id', $user_id)
->first();
}
Expand Down
16 changes: 8 additions & 8 deletions src/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,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 group specific.
// to be user user specific.
if (static::$scope != 'global')
$value = $value->where('group_id', self::get_affected_id($for_id));
$value = $value->where('user_id', self::get_affected_id($for_id));

// Retrieve the value
$value = $value->where('name', $name)
Expand Down Expand Up @@ -118,7 +118,7 @@ public static function get_key_prefix($name, $for_id = null)
if (is_null(static::$prefix))
throw new SettingException('No prefix defined. Have you extended and declared $prefix?');

// Prefix user keys with group_id
// Prefix user keys with user_id
if (static::$scope != 'global')
return implode('.', [$for_id, static::$prefix, $name]);

Expand All @@ -127,7 +127,7 @@ public static function get_key_prefix($name, $for_id = null)
}

/**
* Determine the effected group id.
* Determine the effected user id.
*
* If this is for a specific id use that, otherwise
* assume the currently logged in user's id. If we
Expand All @@ -146,7 +146,7 @@ public static function get_affected_id($for_id)
return $for_id;

if (is_null($for_id))
return auth()->user()->group->id;
return auth()->user()->id;

return $for_id;
}
Expand All @@ -165,9 +165,9 @@ 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 group specific.
// to be user specific.
if (static::$scope != 'global')
$db = $db->where('group_id', self::get_affected_id($for_id));
$db = $db->where('user_id', self::get_affected_id($for_id));

// Retrieve the value
$db = $db->where('name', $name)
Expand All @@ -189,7 +189,7 @@ 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->group_id = self::get_affected_id($for_id);
$db->user_id = self::get_affected_id($for_id);

$db->save();

Expand Down

0 comments on commit e27af33

Please sign in to comment.