From 0404e26b6af4158bf33c1c5bc57555a4b9700734 Mon Sep 17 00:00:00 2001 From: Emrullah Numan Sinan Date: Fri, 16 Sep 2022 14:56:01 +0300 Subject: [PATCH 01/11] test trait --- src/AIssue.php | 4 +- src/AIssueServiceProvider.php | 1 - .../TransitionPermissionException.php | 1 + tests/Unit/AIssueTest.php | 183 ++++++++++++++++++ 4 files changed, 185 insertions(+), 4 deletions(-) diff --git a/src/AIssue.php b/src/AIssue.php index 4abcd38..adc4c45 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -34,7 +34,6 @@ public function canMakeTransition(Models\AIssue $issue, string $status): bool * @param Models\AIssue $issue * @param string $status * @return Models\AIssue - * * @throws TransitionPermissionException */ public function makeTransition(Models\AIssue $issue, string $status): Models\AIssue @@ -42,8 +41,8 @@ public function makeTransition(Models\AIssue $issue, string $status): Models\AIs if ($this->canMakeTransition($issue, $status)) { $issue->status = $status; $issue->save(); + return $issue; } - throw new TransitionPermissionException(); } @@ -59,7 +58,6 @@ public function getTransitionableStatuses(Models\AIssue $issue): array $statuses[] = $index; } } - return $statuses; } } diff --git a/src/AIssueServiceProvider.php b/src/AIssueServiceProvider.php index 7694069..62c6ff6 100644 --- a/src/AIssueServiceProvider.php +++ b/src/AIssueServiceProvider.php @@ -28,7 +28,6 @@ public function boot(): void parent::boot(); // load packages migrations $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); - $this->publishes([ __DIR__.'/../config' => config_path(), ], 'aissue-config'); diff --git a/src/Exceptions/TransitionPermissionException.php b/src/Exceptions/TransitionPermissionException.php index 1d8b35b..eef53cc 100644 --- a/src/Exceptions/TransitionPermissionException.php +++ b/src/Exceptions/TransitionPermissionException.php @@ -6,4 +6,5 @@ class TransitionPermissionException extends AuthenticationException { + } diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index e28469e..eadd95d 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -90,3 +90,186 @@ $this->assertFalse($createdIssueModel->canMakeTransition('done')); }); + +test('can make transition ', function () { + $createdModel = Issueable::create( + ['name' => 'test isuable model 5'] + ); + + /** @var AIssue $createdIssueModel */ + $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 2.1', 'asdasd', 1, \Illuminate\Support\Carbon::now()); + + $transition = $createdIssueModel->makeTransition('in_progress'); + + $this->assertTrue($transition->status == 'in_progress' ); +}); + +test('can check get transitionable statuses ', function () { + $createdModel = Issueable::create( + ['name' => 'test isuable model 4'] + ); + + /** @var AIssue $createdIssueModel */ + $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 2.1', 'asdasd', 1, \Illuminate\Support\Carbon::now()); + $transitionable = $createdIssueModel->getTransitionableStatuses($createdIssueModel); + $this->assertTrue($transitionable == ["todo","in_progress"]); +}); + + +// AIssueModelTrait Test + +test('can create aissue from trait class ', function () { + + + $createdModel = Issueable::create( + ['name' => 'test isuable model 1 trait'] + ); + + $aissueTrait = new AuroraWebSoftware\AIssue\AIssue; + + $data = [ + 'model_type' => $createdModel->getAIssueModelType(), + 'model_id' => $createdModel->getAIssueModelId(), + 'assignee_id' => 1, + 'creater_id' => 1, + 'issue_type' => 'task', + 'summary' => 'test isssue trait', + 'description' => 'asdasd', + 'priority' => 1, + 'status' => $createdModel->getAIssueDefaultStatus('task'), + 'duedate' => \Illuminate\Support\Carbon::now(), + ]; + + $createdIssueModel = $aissueTrait->createIssue($data); + $this->assertEquals( + AIssue::where('id', '=', $createdIssueModel->id)->first()->summary, + $createdIssueModel->summary + ); +}); + +test('can check make transition for todo from trait class', function () { + $createdModel = Issueable::create( + ['name' => 'test isuable model 2 trait'] + ); + + $aissueTrait = new AuroraWebSoftware\AIssue\AIssue; + + $data = [ + 'model_type' => $createdModel->getAIssueModelType(), + 'model_id' => $createdModel->getAIssueModelId(), + 'assignee_id' => 1, + 'creater_id' => 1, + 'issue_type' => 'task', + 'summary' => 'test isssue trait', + 'description' => 'asdasd', + 'priority' => 1, + 'status' => $createdModel->getAIssueDefaultStatus('task'), + 'duedate' => \Illuminate\Support\Carbon::now(), + ]; + + $createdIssueModel = $aissueTrait->createIssue($data); + + $this->assertTrue($createdIssueModel->canMakeTransition('todo')); +}); + +test('can check make transition for in_progress from trait class', function () { + $createdModel = Issueable::create( + ['name' => 'test isuable model 3 trait'] + ); + + $aissueTrait = new AuroraWebSoftware\AIssue\AIssue; + + $data = [ + 'model_type' => $createdModel->getAIssueModelType(), + 'model_id' => $createdModel->getAIssueModelId(), + 'assignee_id' => 1, + 'creater_id' => 1, + 'issue_type' => 'task', + 'summary' => 'test isssue trait', + 'description' => 'asdasd', + 'priority' => 1, + 'status' => $createdModel->getAIssueDefaultStatus('task'), + 'duedate' => \Illuminate\Support\Carbon::now(), + ]; + + $createdIssueModel = $aissueTrait->createIssue($data); + $this->assertTrue($createdIssueModel->canMakeTransition('in_progress')); +}); + +test('can check make transition for done from trait class', function () { + $createdModel = Issueable::create( + ['name' => 'test isuable model 4 trait'] + ); + + $aissueTrait = new AuroraWebSoftware\AIssue\AIssue; + + $data = [ + 'model_type' => $createdModel->getAIssueModelType(), + 'model_id' => $createdModel->getAIssueModelId(), + 'assignee_id' => 1, + 'creater_id' => 1, + 'issue_type' => 'task', + 'summary' => 'test isssue trait', + 'description' => 'asdasd', + 'priority' => 1, + 'status' => $createdModel->getAIssueDefaultStatus('task'), + 'duedate' => \Illuminate\Support\Carbon::now(), + ]; + + $createdIssueModel = $aissueTrait->createIssue($data); + $this->assertFalse($createdIssueModel->canMakeTransition('done')); +}); + +test('can make transition from trait class', function () { + $createdModel = Issueable::create( + ['name' => 'test isuable model 5 trait'] + ); + + $aissueTrait = new AuroraWebSoftware\AIssue\AIssue; + + $data = [ + 'model_type' => $createdModel->getAIssueModelType(), + 'model_id' => $createdModel->getAIssueModelId(), + 'assignee_id' => 1, + 'creater_id' => 1, + 'issue_type' => 'task', + 'summary' => 'test isssue trait', + 'description' => 'asdasd', + 'priority' => 1, + 'status' => $createdModel->getAIssueDefaultStatus('task'), + 'duedate' => \Illuminate\Support\Carbon::now(), + ]; + + $createdIssueModel = $aissueTrait->createIssue($data); + + $transition = $createdIssueModel->makeTransition('in_progress'); + + $this->assertTrue($transition->status == 'in_progress' ); +}); + +test('can check get transitionable statuses from trait class', function () { + $createdModel = Issueable::create( + ['name' => 'test isuable model 4 trait'] + ); + + $aissueTrait = new AuroraWebSoftware\AIssue\AIssue; + + $data = [ + 'model_type' => $createdModel->getAIssueModelType(), + 'model_id' => $createdModel->getAIssueModelId(), + 'assignee_id' => 1, + 'creater_id' => 1, + 'issue_type' => 'task', + 'summary' => 'test isssue trait', + 'description' => 'asdasd', + 'priority' => 1, + 'status' => $createdModel->getAIssueDefaultStatus('task'), + 'duedate' => \Illuminate\Support\Carbon::now(), + ]; + + $createdIssueModel = $aissueTrait->createIssue($data); + + $transitionable = $createdIssueModel->getTransitionableStatuses($createdIssueModel); + $this->assertTrue($transitionable == ["todo","in_progress"]); +}); + From b56cff264784d428f05b0112b4f6bc8db10d8a71 Mon Sep 17 00:00:00 2001 From: nusinan Date: Fri, 16 Sep 2022 11:56:38 +0000 Subject: [PATCH 02/11] Fix styling --- src/AIssue.php | 3 +++ src/Exceptions/TransitionPermissionException.php | 1 - tests/Unit/AIssueTest.php | 12 ++++-------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/AIssue.php b/src/AIssue.php index adc4c45..c21c032 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -34,6 +34,7 @@ public function canMakeTransition(Models\AIssue $issue, string $status): bool * @param Models\AIssue $issue * @param string $status * @return Models\AIssue + * * @throws TransitionPermissionException */ public function makeTransition(Models\AIssue $issue, string $status): Models\AIssue @@ -41,6 +42,7 @@ public function makeTransition(Models\AIssue $issue, string $status): Models\AIs if ($this->canMakeTransition($issue, $status)) { $issue->status = $status; $issue->save(); + return $issue; } throw new TransitionPermissionException(); @@ -58,6 +60,7 @@ public function getTransitionableStatuses(Models\AIssue $issue): array $statuses[] = $index; } } + return $statuses; } } diff --git a/src/Exceptions/TransitionPermissionException.php b/src/Exceptions/TransitionPermissionException.php index eef53cc..1d8b35b 100644 --- a/src/Exceptions/TransitionPermissionException.php +++ b/src/Exceptions/TransitionPermissionException.php @@ -6,5 +6,4 @@ class TransitionPermissionException extends AuthenticationException { - } diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index eadd95d..378740d 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -101,7 +101,7 @@ $transition = $createdIssueModel->makeTransition('in_progress'); - $this->assertTrue($transition->status == 'in_progress' ); + $this->assertTrue($transition->status == 'in_progress'); }); test('can check get transitionable statuses ', function () { @@ -112,15 +112,12 @@ /** @var AIssue $createdIssueModel */ $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 2.1', 'asdasd', 1, \Illuminate\Support\Carbon::now()); $transitionable = $createdIssueModel->getTransitionableStatuses($createdIssueModel); - $this->assertTrue($transitionable == ["todo","in_progress"]); + $this->assertTrue($transitionable == ['todo', 'in_progress']); }); - // AIssueModelTrait Test test('can create aissue from trait class ', function () { - - $createdModel = Issueable::create( ['name' => 'test isuable model 1 trait'] ); @@ -244,7 +241,7 @@ $transition = $createdIssueModel->makeTransition('in_progress'); - $this->assertTrue($transition->status == 'in_progress' ); + $this->assertTrue($transition->status == 'in_progress'); }); test('can check get transitionable statuses from trait class', function () { @@ -270,6 +267,5 @@ $createdIssueModel = $aissueTrait->createIssue($data); $transitionable = $createdIssueModel->getTransitionableStatuses($createdIssueModel); - $this->assertTrue($transitionable == ["todo","in_progress"]); + $this->assertTrue($transitionable == ['todo', 'in_progress']); }); - From eaf0a23ea51ee1fb2c5d948b292a845ea80797ce Mon Sep 17 00:00:00 2001 From: Emrullah Numan Sinan Date: Fri, 16 Sep 2022 15:53:08 +0300 Subject: [PATCH 03/11] readme.md updated --- README.md | 137 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 111 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 9364fe9..c8f9ab3 100644 --- a/README.md +++ b/README.md @@ -24,15 +24,15 @@ You can install the package via composer: composer require aurorawebsoftware/aissue ``` -Todo +You must add AIssueModelTrait Trait to the Issueable Model. ```php -use Illuminate\Foundation\Auth\User as Authenticatable; -use AuroraWebSoftware\aissue\Traits\aissueUser; +use AuroraWebSoftware\AIssue\Contracts\AIssueModelContract; +use AuroraWebSoftware\AIssue\Traits\AIssueModelTrait; -class User extends Authenticatable +class Issueable extends Model implements AIssueModelContract { - use ; + use AAuthUser; // ... } @@ -44,19 +44,6 @@ You can publish and run the migrations with: php artisan migrate ``` -You can publish the sample data seeder with: - -```bash -php artisan vendor:publish --tag="aissue-seeders" -php artisan db:seed --class=SampleDataSeeder -``` - -Optionally, You can seed the sample data with: - -```bash -php artisan db:seed --class=SampleDataSeeder -``` - You can publish the config file with: ```bash @@ -64,14 +51,34 @@ php artisan vendor:publish --tag="aissue-config" ``` This is the example contents of the published config file: +```bash -```php -return [ -]; + return [ + 'policyMethod' => fn ($permission): bool => true, + 'issueTypes' => [ + 'task' => [ + 'todo' => ['sort' => 1, 'permission' => 'todo_perm'], + 'in_progress' => ['sort' => 2, 'permission' => 'in_progress_perm'], + 'done' => ['sort' => 3, 'permission' => 'done_perm'], + ], + ], + ]; ``` +**Permission Config File** + +Permissions are stored inside `config/aissue.php` which is published after installing + + # Main Philosophy -Todo +# + +In some systems, many users interact with each other. these interacting users perform a number of tasks +in a certain order by using the tools that the system allows them. the sequence and result of these +tasks completed by users are of concern to other users.The results of these tasks should also be reported +to other relevant users. This package, manages this process, which we call the work flow system, +and notifies the relevant users.This package manages this process, which we call the workflow system, +and informs the relevant users. also saves process information in database --- > If you don't need organizational roles, **aissue** may not be suitable for your work. @@ -79,8 +86,8 @@ Todo # Aissue Terminology -Before using aissue its worth to understand the main terminology of aissue. -aissue differs from other Auth Packages due to its organizational structure. +Before using AIssue its worth to understand the main terminology of AIssue. +The difference of Issue from other packages is that it perform simple-level workflows with its simplified structure. # Usage @@ -88,15 +95,93 @@ aissue differs from other Auth Packages due to its organizational structure. Before using this, please make sure that you published the config files. -## aissue Service and Facade Methods +## AIssue Services, Service Provider and Facade + +## AIssueServiceProvider + +Organization Service is used for organization related jobs. The service can be initialized as -### todo +```php + $aissueServiceProvider = new AIssueServiceProvider() +``` +or via dependency injecting ```php + public function index(AIssueServiceProvider $aissueServiceProvider) +{ + +} ``` + +### Creating an Issuable +```php + +$createdModel = Issueable::create( + ['name' => 'example isuable model'] + ); + +``` + +### Making a transition for todo, in_progres and done +```php + + $createdModel = Issueable::create( + ['name' => 'example isuable model'] + ); + + /** @var AIssue $createdIssueModel */ + $createdIssueModel = $createdModel->createIssue(1, 1, 'example', 'example isssue', 'example', 1, \Illuminate\Support\Carbon::now()); + //todo,in_progress,done + $createdIssueModel->canMakeTransition('todo') + +``` + +### Getting transitionable statuses +```php + + $createdModel = Issueable::create( + ['name' => 'example isuable model 4'] + ); + + /** @var AIssue $createdIssueModel */ + $createdIssueModel = $createdModel->createIssue(1, 1, 'example', 'example isssue', 'example', 1, \Illuminate\Support\Carbon::now()); + $transitionable = $createdIssueModel->getTransitionableStatuses($createdIssueModel); + + $this->assertTrue($transitionable == ["todo","in_progress"]); + +``` + +### Using AIssue Interface and Trait with Eloquent Models +To turn an Eloquent Model into an AIssue ; +Model must implement AIssueModelContract and use AIssueModelTrait Trait. +After adding AIssueModelContract trait, you will be able to use AIssue methods within the model +```php + + namespace App\Models\ExampleModel; + + use AuroraWebSoftware\AIssue\Contracts\AIssueModelContract; + use AuroraWebSoftware\AIssue\Traits\AIssueModelTrait; + use Illuminate\Database\Eloquent\Model; + + class ExampleModel extends Model implements AIssueModelContract + { + use AIssueModelTrait; + + // implementation +} + +``` + +Getting All Model Collection without any access control +```php + + ExampleModel::withoutGlobalScopes()->all() + +``` + ## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. From 1dfae18a8d48e62d3814de19f6536d10c8c67916 Mon Sep 17 00:00:00 2001 From: Emrullah Numan Sinan Date: Mon, 19 Sep 2022 14:27:05 +0300 Subject: [PATCH 04/11] IssueType Control --- src/AIssue.php | 2 -- src/Exceptions/IssueTypeNotFoundException.php | 9 ++++++++ src/Traits/AIssueModelTrait.php | 21 ++++++++++++------- 3 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 src/Exceptions/IssueTypeNotFoundException.php diff --git a/src/AIssue.php b/src/AIssue.php index c21c032..e91b636 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -26,7 +26,6 @@ public function canMakeTransition(Models\AIssue $issue, string $status): bool if (config('aissue')['policyMethod']($permission)) { return true; } - return false; } @@ -60,7 +59,6 @@ public function getTransitionableStatuses(Models\AIssue $issue): array $statuses[] = $index; } } - return $statuses; } } diff --git a/src/Exceptions/IssueTypeNotFoundException.php b/src/Exceptions/IssueTypeNotFoundException.php new file mode 100644 index 0000000..6391bbb --- /dev/null +++ b/src/Exceptions/IssueTypeNotFoundException.php @@ -0,0 +1,9 @@ + Date: Mon, 19 Sep 2022 11:27:35 +0000 Subject: [PATCH 05/11] Fix styling --- src/AIssue.php | 2 ++ src/Traits/AIssueModelTrait.php | 18 +++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/AIssue.php b/src/AIssue.php index e91b636..c21c032 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -26,6 +26,7 @@ public function canMakeTransition(Models\AIssue $issue, string $status): bool if (config('aissue')['policyMethod']($permission)) { return true; } + return false; } @@ -59,6 +60,7 @@ public function getTransitionableStatuses(Models\AIssue $issue): array $statuses[] = $index; } } + return $statuses; } } diff --git a/src/Traits/AIssueModelTrait.php b/src/Traits/AIssueModelTrait.php index fd73eb5..9fc530d 100644 --- a/src/Traits/AIssueModelTrait.php +++ b/src/Traits/AIssueModelTrait.php @@ -9,14 +9,15 @@ trait AIssueModelTrait { /** - * @param int $assigneeId - * @param int $createrId - * @param string $issueType - * @param string $summary - * @param string $description - * @param int $priority - * @param Carbon $duedate + * @param int $assigneeId + * @param int $createrId + * @param string $issueType + * @param string $summary + * @param string $description + * @param int $priority + * @param Carbon $duedate * @return \AuroraWebSoftware\AIssue\Models\AIssue + * * @throws IssueTypeNotFoundException */ public function createIssue( @@ -28,9 +29,8 @@ public function createIssue( int $priority, Carbon $duedate, ): \AuroraWebSoftware\AIssue\Models\AIssue { - $issueTypes = config('aissue')['issueTypes']; - if(!in_array($issueType, $issueTypes)){ + if (! in_array($issueType, $issueTypes)) { throw new IssueTypeNotFoundException(); } // todo issueType Kontrolü From 1fbfa5eeaef78ee1feb85d24a3a2ca9ce38d0bbf Mon Sep 17 00:00:00 2001 From: emreakay Date: Mon, 19 Sep 2022 14:30:30 +0300 Subject: [PATCH 06/11] - traits fixed - phpunit and pest fixed --- tests/Unit/AIssueTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index 378740d..ee81e37 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Schema; + beforeEach(function () { Artisan::call('migrate:fresh'); @@ -20,7 +21,6 @@ if ($permission == 'todo_perm' || $permission == 'in_progress_perm') { return true; } - return false; }; From 374cd8622d411cca9bd3d82bba119c158057a187 Mon Sep 17 00:00:00 2001 From: emreakay Date: Mon, 19 Sep 2022 14:35:32 +0300 Subject: [PATCH 07/11] - traits fixed - phpunit and pest fixed --- src/Traits/AIssueModelTrait.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Traits/AIssueModelTrait.php b/src/Traits/AIssueModelTrait.php index fd73eb5..1215860 100644 --- a/src/Traits/AIssueModelTrait.php +++ b/src/Traits/AIssueModelTrait.php @@ -20,20 +20,20 @@ trait AIssueModelTrait * @throws IssueTypeNotFoundException */ public function createIssue( - int $assigneeId, - int $createrId, + int $assigneeId, + int $createrId, string $issueType, string $summary, string $description, - int $priority, + int $priority, Carbon $duedate, - ): \AuroraWebSoftware\AIssue\Models\AIssue { - - $issueTypes = config('aissue')['issueTypes']; - if(!in_array($issueType, $issueTypes)){ - throw new IssueTypeNotFoundException(); + ): \AuroraWebSoftware\AIssue\Models\AIssue + { + $configIssueTypes = config('aissue')['issueTypes']; + if (! array_key_exists($issueType, $configIssueTypes)) { + throw new IssueTypeNotFoundException("$issueType Not Found, Please check Your Config File."); } - // todo issueType Kontrolü + // todo status yetki kontrolü $data = [ From f95f4645838da344cc588675271c0d090665e94c Mon Sep 17 00:00:00 2001 From: emreakay Date: Mon, 19 Sep 2022 14:53:18 +0300 Subject: [PATCH 08/11] - traits fixed - phpunit and pest fixed --- tests/Unit/AIssueTest.php | 116 +++++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 52 deletions(-) diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index ee81e37..73333e9 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -1,8 +1,10 @@ assertTrue(config('aissue')['policyMethod']('todo_perm')); }); -test('can get one specified issue', function () { - //AAuth::organizationNodes(); - // todo - expect(1)->toBeTruthy(); +test('can access policy method works for done', function () { + $this->assertFalse(config('aissue')['policyMethod']('done_perm')); }); -test('can create aissue for a model', function () { +test('can create aissue for a model using trait', function () { $createdModel = Issueable::create( ['name' => 'test isuable model 1'] ); - $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 1.1', 'asdasd', 1, \Illuminate\Support\Carbon::now()); + $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 1.1', 'asdasd', 1, Carbon::now()); $this->assertEquals( AIssue::where('id', '=', $createdIssueModel->id)->first()->summary, @@ -58,24 +58,24 @@ ); }); -test('can check make transition for todo', function () { +test('can check make transition for todo using trait', function () { $createdModel = Issueable::create( ['name' => 'test isuable model 2'] ); /** @var AIssue $createdIssueModel */ - $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 2.1', 'asdasd', 1, \Illuminate\Support\Carbon::now()); + $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 2.1', 'asdasd', 1, Carbon::now()); $this->assertTrue($createdIssueModel->canMakeTransition('todo')); }); -test('can check make transition for in_progress', function () { +test('can check make transition for in_progress using trait', function () { $createdModel = Issueable::create( ['name' => 'test isuable model 3'] ); /** @var AIssue $createdIssueModel */ - $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 2.1', 'asdasd', 1, \Illuminate\Support\Carbon::now()); + $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 2.1', 'asdasd', 1, Carbon::now()); $this->assertTrue($createdIssueModel->canMakeTransition('in_progress')); }); @@ -86,43 +86,53 @@ ); /** @var AIssue $createdIssueModel */ - $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 2.1', 'asdasd', 1, \Illuminate\Support\Carbon::now()); + $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 2.1', 'asdasd', 1, Carbon::now()); $this->assertFalse($createdIssueModel->canMakeTransition('done')); }); -test('can make transition ', function () { +test('can make transition using Issue Model', function () { $createdModel = Issueable::create( ['name' => 'test isuable model 5'] ); /** @var AIssue $createdIssueModel */ - $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 2.1', 'asdasd', 1, \Illuminate\Support\Carbon::now()); + $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 2.1', 'asdasd', 1, Carbon::now()); $transition = $createdIssueModel->makeTransition('in_progress'); $this->assertTrue($transition->status == 'in_progress'); }); +test('cannot make transition using Issue Model without permission', function () { + $createdModel = Issueable::create( + ['name' => 'test isuable model 5'] + ); + + /** @var AIssue $createdIssueModel */ + $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 2.1', 'asdasd', 1, Carbon::now()); + + $transition = $createdIssueModel->makeTransition('done'); +})->throws(TransitionPermissionException::class); + + test('can check get transitionable statuses ', function () { $createdModel = Issueable::create( ['name' => 'test isuable model 4'] ); /** @var AIssue $createdIssueModel */ - $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 2.1', 'asdasd', 1, \Illuminate\Support\Carbon::now()); + $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 2.1', 'asdasd', 1, Carbon::now()); $transitionable = $createdIssueModel->getTransitionableStatuses($createdIssueModel); $this->assertTrue($transitionable == ['todo', 'in_progress']); }); -// AIssueModelTrait Test - -test('can create aissue from trait class ', function () { +test('can create aissue using service class', function () { $createdModel = Issueable::create( - ['name' => 'test isuable model 1 trait'] + ['name' => 'test isuable model 1 service class'] ); - $aissueTrait = new AuroraWebSoftware\AIssue\AIssue; + $aissueService = new AuroraWebSoftware\AIssue\AIssue; $data = [ 'model_type' => $createdModel->getAIssueModelType(), @@ -130,26 +140,26 @@ 'assignee_id' => 1, 'creater_id' => 1, 'issue_type' => 'task', - 'summary' => 'test isssue trait', + 'summary' => 'test isssue service class', 'description' => 'asdasd', 'priority' => 1, 'status' => $createdModel->getAIssueDefaultStatus('task'), - 'duedate' => \Illuminate\Support\Carbon::now(), + 'duedate' => Carbon::now(), ]; - $createdIssueModel = $aissueTrait->createIssue($data); + $createdIssueModel = $aissueService->createIssue($data); $this->assertEquals( AIssue::where('id', '=', $createdIssueModel->id)->first()->summary, $createdIssueModel->summary ); }); -test('can check make transition for todo from trait class', function () { +test('can check make transition for todo using service class', function () { $createdModel = Issueable::create( - ['name' => 'test isuable model 2 trait'] + ['name' => 'test isuable model 2 service class'] ); - $aissueTrait = new AuroraWebSoftware\AIssue\AIssue; + $aissueService = new AuroraWebSoftware\AIssue\AIssue; $data = [ 'model_type' => $createdModel->getAIssueModelType(), @@ -157,24 +167,24 @@ 'assignee_id' => 1, 'creater_id' => 1, 'issue_type' => 'task', - 'summary' => 'test isssue trait', + 'summary' => 'test isssue service class', 'description' => 'asdasd', 'priority' => 1, 'status' => $createdModel->getAIssueDefaultStatus('task'), - 'duedate' => \Illuminate\Support\Carbon::now(), + 'duedate' => Carbon::now(), ]; - $createdIssueModel = $aissueTrait->createIssue($data); + $createdIssueModel = $aissueService->createIssue($data); $this->assertTrue($createdIssueModel->canMakeTransition('todo')); }); -test('can check make transition for in_progress from trait class', function () { +test('can check make transition for in_progress using service class', function () { $createdModel = Issueable::create( - ['name' => 'test isuable model 3 trait'] + ['name' => 'test isuable model 3 service class'] ); - $aissueTrait = new AuroraWebSoftware\AIssue\AIssue; + $aissueService = new AuroraWebSoftware\AIssue\AIssue; $data = [ 'model_type' => $createdModel->getAIssueModelType(), @@ -182,23 +192,23 @@ 'assignee_id' => 1, 'creater_id' => 1, 'issue_type' => 'task', - 'summary' => 'test isssue trait', + 'summary' => 'test isssue service class', 'description' => 'asdasd', 'priority' => 1, 'status' => $createdModel->getAIssueDefaultStatus('task'), - 'duedate' => \Illuminate\Support\Carbon::now(), + 'duedate' => Carbon::now(), ]; - $createdIssueModel = $aissueTrait->createIssue($data); + $createdIssueModel = $aissueService->createIssue($data); $this->assertTrue($createdIssueModel->canMakeTransition('in_progress')); }); -test('can check make transition for done from trait class', function () { +test('can check make transition for done from service class', function () { $createdModel = Issueable::create( - ['name' => 'test isuable model 4 trait'] + ['name' => 'test isuable model 4 service class'] ); - $aissueTrait = new AuroraWebSoftware\AIssue\AIssue; + $aissueService = new AuroraWebSoftware\AIssue\AIssue; $data = [ 'model_type' => $createdModel->getAIssueModelType(), @@ -206,23 +216,23 @@ 'assignee_id' => 1, 'creater_id' => 1, 'issue_type' => 'task', - 'summary' => 'test isssue trait', + 'summary' => 'test isssue service class', 'description' => 'asdasd', 'priority' => 1, 'status' => $createdModel->getAIssueDefaultStatus('task'), - 'duedate' => \Illuminate\Support\Carbon::now(), + 'duedate' => Carbon::now(), ]; - $createdIssueModel = $aissueTrait->createIssue($data); + $createdIssueModel = $aissueService->createIssue($data); $this->assertFalse($createdIssueModel->canMakeTransition('done')); }); -test('can make transition from trait class', function () { +test('can make transition using service class', function () { $createdModel = Issueable::create( - ['name' => 'test isuable model 5 trait'] + ['name' => 'test isuable model 5 service class'] ); - $aissueTrait = new AuroraWebSoftware\AIssue\AIssue; + $aissueService = new AuroraWebSoftware\AIssue\AIssue; $data = [ 'model_type' => $createdModel->getAIssueModelType(), @@ -230,26 +240,26 @@ 'assignee_id' => 1, 'creater_id' => 1, 'issue_type' => 'task', - 'summary' => 'test isssue trait', + 'summary' => 'test isssue service class', 'description' => 'asdasd', 'priority' => 1, 'status' => $createdModel->getAIssueDefaultStatus('task'), - 'duedate' => \Illuminate\Support\Carbon::now(), + 'duedate' => Carbon::now(), ]; - $createdIssueModel = $aissueTrait->createIssue($data); + $createdIssueModel = $aissueService->createIssue($data); $transition = $createdIssueModel->makeTransition('in_progress'); $this->assertTrue($transition->status == 'in_progress'); }); -test('can check get transitionable statuses from trait class', function () { +test('can check get transitionable statuses from service class', function () { $createdModel = Issueable::create( - ['name' => 'test isuable model 4 trait'] + ['name' => 'test isuable model 4 service class'] ); - $aissueTrait = new AuroraWebSoftware\AIssue\AIssue; + $aissueService = new AuroraWebSoftware\AIssue\AIssue; $data = [ 'model_type' => $createdModel->getAIssueModelType(), @@ -257,15 +267,17 @@ 'assignee_id' => 1, 'creater_id' => 1, 'issue_type' => 'task', - 'summary' => 'test isssue trait', + 'summary' => 'test isssue service class', 'description' => 'asdasd', 'priority' => 1, 'status' => $createdModel->getAIssueDefaultStatus('task'), - 'duedate' => \Illuminate\Support\Carbon::now(), + 'duedate' => Carbon::now(), ]; - $createdIssueModel = $aissueTrait->createIssue($data); + $createdIssueModel = $aissueService->createIssue($data); $transitionable = $createdIssueModel->getTransitionableStatuses($createdIssueModel); $this->assertTrue($transitionable == ['todo', 'in_progress']); }); + +// todo all Facade Class tests must be written. From 78d60125e96396106da08df13800da8915ab221a Mon Sep 17 00:00:00 2001 From: emreakay Date: Mon, 19 Sep 2022 14:54:32 +0300 Subject: [PATCH 09/11] - traits fixed - phpunit and pest fixed --- src/AIssue.php | 2 ++ src/Traits/AIssueModelTrait.php | 24 ++++++++++++------------ tests/Unit/AIssueTest.php | 3 +-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/AIssue.php b/src/AIssue.php index e91b636..c21c032 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -26,6 +26,7 @@ public function canMakeTransition(Models\AIssue $issue, string $status): bool if (config('aissue')['policyMethod']($permission)) { return true; } + return false; } @@ -59,6 +60,7 @@ public function getTransitionableStatuses(Models\AIssue $issue): array $statuses[] = $index; } } + return $statuses; } } diff --git a/src/Traits/AIssueModelTrait.php b/src/Traits/AIssueModelTrait.php index 1215860..7abf6be 100644 --- a/src/Traits/AIssueModelTrait.php +++ b/src/Traits/AIssueModelTrait.php @@ -9,26 +9,26 @@ trait AIssueModelTrait { /** - * @param int $assigneeId - * @param int $createrId - * @param string $issueType - * @param string $summary - * @param string $description - * @param int $priority - * @param Carbon $duedate + * @param int $assigneeId + * @param int $createrId + * @param string $issueType + * @param string $summary + * @param string $description + * @param int $priority + * @param Carbon $duedate * @return \AuroraWebSoftware\AIssue\Models\AIssue + * * @throws IssueTypeNotFoundException */ public function createIssue( - int $assigneeId, - int $createrId, + int $assigneeId, + int $createrId, string $issueType, string $summary, string $description, - int $priority, + int $priority, Carbon $duedate, - ): \AuroraWebSoftware\AIssue\Models\AIssue - { + ): \AuroraWebSoftware\AIssue\Models\AIssue { $configIssueTypes = config('aissue')['issueTypes']; if (! array_key_exists($issueType, $configIssueTypes)) { throw new IssueTypeNotFoundException("$issueType Not Found, Please check Your Config File."); diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index 73333e9..c1714ca 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -9,7 +9,6 @@ use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Schema; - beforeEach(function () { Artisan::call('migrate:fresh'); @@ -23,6 +22,7 @@ if ($permission == 'todo_perm' || $permission == 'in_progress_perm') { return true; } + return false; }; @@ -115,7 +115,6 @@ $transition = $createdIssueModel->makeTransition('done'); })->throws(TransitionPermissionException::class); - test('can check get transitionable statuses ', function () { $createdModel = Issueable::create( ['name' => 'test isuable model 4'] From f0d4fa9450091c00df0dc84f968c3c8cd21df287 Mon Sep 17 00:00:00 2001 From: emreakay Date: Mon, 19 Sep 2022 15:08:19 +0300 Subject: [PATCH 10/11] - traits fixed - phpunit and pest fixed --- README.md | 57 +++++++++++-------------------------------------------- 1 file changed, 11 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index c8f9ab3..b8459e8 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,20 @@ # AIssue for Laravel +Basic and Lean Issue Management Package for Laravel + [![Latest Version on Packagist](https://img.shields.io/packagist/v/aurorawebsoftware/aissue.svg?style=flat-square)](https://packagist.org/packages/aurorawebsoftware/aissue) [![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/aurorawebsoftware/aissue/run-tests?label=tests)](https://github.com/aurorawebsoftware/aissue/actions?query=workflow%3Arun-tests+branch%3Amain) [![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/aurorawebsoftware/aissue/Check%20&%20fix%20styling?label=code%20style)](https://github.com/aurorawebsoftware/aissue/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain) [![Total Downloads](https://img.shields.io/packagist/dt/aurorawebsoftware/aissue.svg?style=flat-square)](https://packagist.org/packages/aurora/aissue) -Todo .... # Features -- Todo ... - +- Basic Workflow and Issue Management +- Limitless Issue Types +- Limitless Statuses for Issue Types +- Authenticatable Issue Status Transitions +- Easy to Use and Lean --- @@ -24,7 +28,7 @@ You can install the package via composer: composer require aurorawebsoftware/aissue ``` -You must add AIssueModelTrait Trait to the Issueable Model. +You must add AIssueModelTrait Trait to the **Issueable** Model and The model must implement **AIssueModelContract** ```php use AuroraWebSoftware\AIssue\Contracts\AIssueModelContract; @@ -32,7 +36,7 @@ use AuroraWebSoftware\AIssue\Traits\AIssueModelTrait; class Issueable extends Model implements AIssueModelContract { - use AAuthUser; + use AIssueModelTrait;; // ... } @@ -67,22 +71,8 @@ This is the example contents of the published config file: **Permission Config File** -Permissions are stored inside `config/aissue.php` which is published after installing - +Permissions are stored `config/aissue.php` is published after installing -# Main Philosophy -# - -In some systems, many users interact with each other. these interacting users perform a number of tasks -in a certain order by using the tools that the system allows them. the sequence and result of these -tasks completed by users are of concern to other users.The results of these tasks should also be reported -to other relevant users. This package, manages this process, which we call the work flow system, -and notifies the relevant users.This package manages this process, which we call the workflow system, -and informs the relevant users. also saves process information in database - ---- -> If you don't need organizational roles, **aissue** may not be suitable for your work. ---- # Aissue Terminology @@ -97,24 +87,7 @@ Before using this, please make sure that you published the config files. ## AIssue Services, Service Provider and Facade -## AIssueServiceProvider - -Organization Service is used for organization related jobs. The service can be initialized as - -```php - $aissueServiceProvider = new AIssueServiceProvider() -``` -or via dependency injecting - -```php - - public function index(AIssueServiceProvider $aissueServiceProvider) -{ - -} -``` - - +// todo ### Creating an Issuable ```php @@ -122,7 +95,6 @@ or via dependency injecting $createdModel = Issueable::create( ['name' => 'example isuable model'] ); - ``` ### Making a transition for todo, in_progres and done @@ -175,12 +147,6 @@ After adding AIssueModelContract trait, you will be able to use AIssue methods w ``` -Getting All Model Collection without any access control -```php - - ExampleModel::withoutGlobalScopes()->all() - -``` ## Changelog @@ -192,7 +158,6 @@ Please see [CONTRIBUTING](README-contr.md) for details. ## Security Vulnerabilities -// todo ? Please review [our security policy](../../security/policy) on how to report security vulnerabilities. From 2a036ae1c02e12ea4f30a253882d9ba07ff24c57 Mon Sep 17 00:00:00 2001 From: emreakay Date: Mon, 19 Sep 2022 15:09:07 +0300 Subject: [PATCH 11/11] - traits fixed - phpunit and pest fixed --- tests/TestCase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 40ce6f6..86d2812 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -26,8 +26,8 @@ protected function getPackageProviders($app) public function getEnvironmentSetUp($app) { - //config()->set('database.default', 'testing'); - config()->set('database.default', 'mysql'); + config()->set('database.default', 'testing'); + // config()->set('database.default', 'mysql'); /* $migration = include __DIR__.'/../database/migrations/create_aissue_table.php.stub';