Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions config/asseco-authorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
* Model bindings.
*/
'models' => [
'authorizable_model' => AuthorizableModel::class,
'authorizable_model' => AuthorizableModel::class,
'authorizable_set_type' => AuthorizableSetType::class,
'authorization_rule' => AuthorizationRule::class,
'authorization_rule' => AuthorizationRule::class,
],

'migrations' => [
'migrations' => [

/**
* UUIDs as primary keys.
*/
'uuid' => false,
'uuid' => false,

/**
* Timestamp types.
Expand All @@ -35,7 +35,7 @@
* Should the package run the migrations. Set to false if you're publishing
* and changing default migrations.
*/
'run' => true,
'run' => true,
],

/**
Expand All @@ -44,20 +44,20 @@
* This does not recurse in folders, so you need to specify
* an array of paths if non-standard models are to be used
*/
'models_path' => [
'models_path' => [
app_path('Models') => 'App\\Models\\',
],

/**
* Namespace to Authorizable trait.
*/
'trait_path' => Authorizable::class,
'trait_path' => Authorizable::class,

/**
* List of roles/groups/etc which have absolute admin/root rights.
* Key must resemble names from authorization_manage_types table.
*/
'absolute_rights' => [
'absolute_rights' => [
// 'roles' => [
// 'asseco-voice-admin'
// ],
Expand All @@ -76,5 +76,5 @@
* your auth service (or whoever is responsible for providing user roles). Check readme
* for more details.
*/
'virtual_role' => env('VIRTUAL_ROLE', 'voice-all-mighty'),
'virtual_role' => env('VIRTUAL_ROLE', 'voice-all-mighty'),
];
4 changes: 2 additions & 2 deletions src/App/Models/AuthorizationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ public static function format($authorizableSetTypeId, string $authorizableSetVal
{
return [
self::SET_TYPE_ID => $authorizableSetTypeId,
self::SET_VALUE => $authorizableSetValue,
self::RULES => $rules,
self::SET_VALUE => $authorizableSetValue,
self::RULES => $rules,
];
}
}
2 changes: 1 addition & 1 deletion src/Database/Factories/AuthorizableModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function modelName()
public function definition()
{
return [
'name' => $this->faker->word,
'name' => $this->faker->word,
'created_at' => now(),
'updated_at' => now(),
];
Expand Down
6 changes: 3 additions & 3 deletions src/Database/Factories/AuthorizableSetTypeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public function modelName()
public function definition()
{
return [
'name' => $this->faker->word,
'name' => $this->faker->word,
'description' => $this->faker->sentence,
'created_at' => now(),
'updated_at' => now(),
'created_at' => now(),
'updated_at' => now(),
];
}
}
10 changes: 5 additions & 5 deletions src/Database/Factories/AuthorizationRuleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public function definition()
{
return [
'authorizable_set_type_id' => $this->faker->randomNumber(),
'authorizable_set_value' => $this->faker->word,
'authorizable_model_id' => $this->faker->randomNumber(),
'rules' => json_encode($this->faker->words(10)),
'created_at' => now(),
'updated_at' => now(),
'authorizable_set_value' => $this->faker->word,
'authorizable_model_id' => $this->faker->randomNumber(),
'rules' => json_encode($this->faker->words(10)),
'created_at' => now(),
'updated_at' => now(),
];
}
}
8 changes: 4 additions & 4 deletions src/Database/Seeders/AuthorizableSetTypeSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ public function run(): void

$basicTypes = [
[
'name' => AuthorizableSetCollection::VIRTUAL_SET_TYPE,
'name' => AuthorizableSetCollection::VIRTUAL_SET_TYPE,
'description' => 'Virtual set type attached automatically to every user.',
],
[
'name' => 'roles',
'name' => 'roles',
'description' => 'Authentication service roles',
],
[
'name' => 'groups',
'name' => 'groups',
'description' => 'Authentication service groups',
],
[
'name' => 'id',
'name' => 'id',
'description' => 'Authentication service ID',
],
];
Expand Down
6 changes: 3 additions & 3 deletions src/Database/Seeders/AuthorizationRuleSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public function run(): void

$authorizationRule::query()->create([
'authorizable_set_type_id' => 1,
'authorizable_set_value' => $role,
'authorizable_model_id' => $authorizableModel->id,
'rules' => json_encode($rules, JSON_THROW_ON_ERROR),
'authorizable_set_value' => $role,
'authorizable_model_id' => $authorizableModel->id,
'rules' => json_encode($rules, JSON_THROW_ON_ERROR),
]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TestUser extends Authenticatable implements AuthorizationInterface
public function getAuthorizableSets(): array
{
return [
'roles' => [
'roles' => [
'role1',
'role2',
],
Expand Down
16 changes: 8 additions & 8 deletions tests/Unit/App/Collections/AuthorizableSetCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,23 @@ public function transforms_output_to_authorization_rule_format()
$expected = [
[
'authorizable_set_type_id' => $roleType->id,
'authorizable_set_value' => 'role1',
'rules' => [],
'authorizable_set_value' => 'role1',
'rules' => [],
],
[
'authorizable_set_type_id' => $roleType->id,
'authorizable_set_value' => 'role2',
'rules' => [],
'authorizable_set_value' => 'role2',
'rules' => [],
],
[
'authorizable_set_type_id' => $groupType->id,
'authorizable_set_value' => 'group1',
'rules' => [],
'authorizable_set_value' => 'group1',
'rules' => [],
],
[
'authorizable_set_type_id' => $groupType->id,
'authorizable_set_value' => 'group2',
'rules' => [],
'authorizable_set_value' => 'group2',
'rules' => [],
],
];

Expand Down
22 changes: 11 additions & 11 deletions tests/Unit/App/Models/AuthorizationRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public function resolves_existing_rule_if_it_matches_user_defined_roles()

$this->authorizationRule::factory()->create([
'authorizable_set_type_id' => $roleType->id,
'authorizable_set_value' => 'role1',
'authorizable_model_id' => $model->id,
'rules' => json_encode([
'authorizable_set_value' => 'role1',
'authorizable_model_id' => $model->id,
'rules' => json_encode([
'read' => '*',
]),
]);
Expand All @@ -101,18 +101,18 @@ public function resolves_multiple_existing_rules_if_it_matches_user_defined_role

$this->authorizationRule::factory()->create([
'authorizable_set_type_id' => $roleType->id,
'authorizable_set_value' => 'role1',
'authorizable_model_id' => $model->id,
'rules' => json_encode([
'authorizable_set_value' => 'role1',
'authorizable_model_id' => $model->id,
'rules' => json_encode([
'read' => '*',
]),
]);

$this->authorizationRule::factory()->create([
'authorizable_set_type_id' => $roleType->id,
'authorizable_set_value' => 'role2',
'authorizable_model_id' => $model->id,
'rules' => json_encode([
'authorizable_set_value' => 'role2',
'authorizable_model_id' => $model->id,
'rules' => json_encode([
'write' => '*',
]),
]);
Expand All @@ -131,8 +131,8 @@ public function formats_data_for_writing_to_cache()
{
$expected = [
'authorizable_set_type_id' => 1,
'authorizable_set_value' => 'role1',
'rules' => [
'authorizable_set_value' => 'role1',
'rules' => [
'test' => 'test',
],
];
Expand Down
20 changes: 10 additions & 10 deletions tests/Unit/Authorization/UserAuthorizableSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,28 @@ public function returns_prepared_rules()
$expected = [
[
'authorizable_set_type_id' => $roleType->id,
'authorizable_set_value' => 'role1',
'rules' => [],
'authorizable_set_value' => 'role1',
'rules' => [],
],
[
'authorizable_set_type_id' => $roleType->id,
'authorizable_set_value' => 'role2',
'rules' => [],
'authorizable_set_value' => 'role2',
'rules' => [],
],
[
'authorizable_set_type_id' => $groupType->id,
'authorizable_set_value' => 'group1',
'rules' => [],
'authorizable_set_value' => 'group1',
'rules' => [],
],
[
'authorizable_set_type_id' => $groupType->id,
'authorizable_set_value' => 'group2',
'rules' => [],
'authorizable_set_value' => 'group2',
'rules' => [],
],
[
'authorizable_set_type_id' => 3,
'authorizable_set_value' => 'voice-all-mighty',
'rules' => [],
'authorizable_set_value' => 'voice-all-mighty',
'rules' => [],
],
];

Expand Down
Loading