diff --git a/README.md b/README.md index 06de289..d8508a4 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,23 @@ MS_HUB_BASE_URI="https://api-dev-hub.nave.dev" MS_HUB_PREFIX="/api" ``` +## Change permission and role model from spatie/laravel-permissions + +You should change the default spatie/laravel-permissions models to ours, as we have some substantial changes to the use of Role and Permission. + +```php +// config/permission.php + +return [ + 'models' = [ + 'permission' => \BildVitta\Hub\Entities\HubPermission::class, + 'role' => \BildVitta\Hub\Entities\HubRole::class, + ] +]; +``` + +If you already have a change to these models, just extend our classes to have the correct functionalities. + ## Add Trait on User Model And remember to add the `BildVitta\Hub\Traits\User\HasCompanyLinks` Trait in the Users model. @@ -200,48 +217,6 @@ return (new RealEstateDevelopmentResource('index', $query->get()))->count($count Remembering that the scope name has to be permission, if not, it doesn't work <3 -## Logging - -To generate the log, just put the settings in the `config/logging.php` file - -```php -[ - - - 'channels' => [ - 'stack' => [ - 'driver' => 'stack', - 'channels' => ['single', 'stderr', 'satelliteX9'], # Add satelliteX9 on channels - 'ignore_exceptions' => false, - ], - - ... - - 'satelliteX9' => [ - 'driver' => 'custom', - 'via' => BildVitta\Hub\Logging\SatelliteX9Logger::class, - 'with' => [ - 'app_url' => env('SATELLITE_X9_URL', ''), - 'app_endpoint' => env('SATELLITE_X9_ENDPOINT', ''), - 'app_module' => env('SATELLITE_X9_MODULE', '') - ] - ] - ] -] -``` - -After the configuration, just use the normal Laravel Log. Passing the entity, entity uuid and action attributes as arguments. - -```php -use Log; - -Log::info(__('Created user'), [ - 'entity' => 'user', - 'entity_uuid' => $user->uuid, - 'action' => 'store' -]); -``` - ## Testing coming soon... diff --git a/database/migrations/2024_05_21_112100_add_columns_on_roles_and_permissions_tables.php b/database/migrations/2024_05_21_112100_add_columns_on_roles_and_permissions_tables.php new file mode 100644 index 0000000..7265e01 --- /dev/null +++ b/database/migrations/2024_05_21_112100_add_columns_on_roles_and_permissions_tables.php @@ -0,0 +1,45 @@ +getTable(), function (Blueprint $table) use ($hubCompany) { + $table->uuid('uuid')->unique(); + $table->string('description')->nullable(); + $table->foreignId('hub_company_id')->constrained($hubCompany->getTable())->cascadeOnDelete()->index('roles_hub_company_id_foreign'); + $table->boolean('has_all_real_estate_developments')->default(false); + $table->boolean('is_post_construction')->default(false); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + $role = app(config('permission.models.role')); + + Schema::table($role->getTable(), function (Blueprint $table) { + $table->dropColumn('uuid'); + $table->dropColumn('description'); + $table->dropForeign(['hub_company_id']); + $table->dropColumn('has_all_real_estate_developments'); + $table->dropColumn('is_post_construction'); + }); + } +}; diff --git a/src/Entities/HubPermission.php b/src/Entities/HubPermission.php new file mode 100644 index 0000000..86b9890 --- /dev/null +++ b/src/Entities/HubPermission.php @@ -0,0 +1,8 @@ + 'boolean', + 'is_post_construction' => 'boolean', + ]; + + public function company(): BelongsTo + { + return $this->belongsTo(HubCompany::class, 'hub_company_id', 'id'); + } + + public function positions(): BelongsToMany + { + return $this->morphedByMany( + HubPosition::class, + 'model', + config('permission.table_names.model_has_roles'), + config('permission.column_names.model_morph_key'), + ); + } +} diff --git a/src/Services/UserCompanyService.php b/src/Services/UserCompanyService.php index bd15d22..32f1b1c 100644 --- a/src/Services/UserCompanyService.php +++ b/src/Services/UserCompanyService.php @@ -32,7 +32,7 @@ public static function clearCacheByUserCompany($userCompany) * @param string $parentUserUuid * @param string $companyUuid * @param bool $allBelow - * @param int $onlyPositionOrder null|0|1|2 + * @param int $onlyPositionOrder null|0|1|2 * @param array $attributes * @return User */ @@ -235,7 +235,7 @@ private static function getAllUserParentsByUserCompanyChildren($userCompanyChild * Get users by companyUuid and positionUuid * * @param string $companyUuid - * @param int $positionOrder 0|1|2 + * @param int $positionOrder 0|1|2 * @param array $filter * @param array $attributes * @return User @@ -350,7 +350,7 @@ private static function sortPositions($positions) * * @param string $companyUuid * @param string $userUuid - * @param int $positionOrder 0|1|2 + * @param int $positionOrder 0|1|2 * @return bool */ public static function checkPositionUser($companyUuid, $userUuid, $positionOrder) @@ -393,7 +393,7 @@ public static function checkPositionUser($companyUuid, $userUuid, $positionOrder * * @param string $userUuid * @param string $companyUuid - * @param int $onlyPositionOrder null|0|1 + * @param int $onlyPositionOrder null|0|1 * @param array $attributes * @return User */