-
Notifications
You must be signed in to change notification settings - Fork 255
FOUR-31145: Self Service tasks not visible to users in assigned subgroups #9022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rodriquelca
wants to merge
1
commit into
develop
Choose a base branch
from
bugfix/FOUR-31145
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Tests\Feature; | ||
|
|
||
| use Illuminate\Foundation\Testing\RefreshDatabase; | ||
| use Illuminate\Support\Facades\Auth; | ||
| use ProcessMaker\Models\Group; | ||
| use ProcessMaker\Models\GroupMember; | ||
| use ProcessMaker\Models\ProcessRequestToken; | ||
| use ProcessMaker\Models\User; | ||
| use Tests\TestCase; | ||
|
|
||
| class SelfServiceSubgroupTest extends TestCase | ||
| { | ||
| use RefreshDatabase; | ||
|
|
||
| public function test_subgroup_member_sees_and_can_claim_parent_group_self_service_task(): void | ||
| { | ||
| [$parent, $subgroup, $nestedUser, $directUser, $outsider] = $this->createNestedGroups(); | ||
|
|
||
| $task = ProcessRequestToken::factory()->create([ | ||
| 'is_self_service' => true, | ||
| 'status' => 'ACTIVE', | ||
| 'user_id' => null, | ||
| 'self_service_groups' => ['groups' => [$parent->id]], | ||
| ]); | ||
|
|
||
| $this->assertContains($task->id, $nestedUser->availableSelfServiceTaskIds()); | ||
| $this->assertContains($task->id, $directUser->availableSelfServiceTaskIds()); | ||
| $this->assertNotContains($task->id, $outsider->availableSelfServiceTaskIds()); | ||
|
|
||
| Auth::login($nestedUser); | ||
| $this->assertTrue($nestedUser->canSelfServe($task)); | ||
|
|
||
| Auth::login($directUser); | ||
| $this->assertTrue($directUser->canSelfServe($task)); | ||
|
|
||
| Auth::login($outsider); | ||
| $this->assertFalse($outsider->canSelfServe($task)); | ||
|
|
||
| $this->assertContains($parent->id, $nestedUser->selfServiceGroupIds()); | ||
| $this->assertNotContains($subgroup->id, $outsider->selfServiceGroupIds()); | ||
| } | ||
|
|
||
| public function test_two_level_nested_subgroup_member_sees_self_service_task(): void | ||
| { | ||
| $parent = Group::factory()->create(); | ||
| $child = Group::factory()->create(); | ||
| $grandchild = Group::factory()->create(); | ||
| $user = User::factory()->create(); | ||
|
|
||
| GroupMember::factory()->create([ | ||
| 'group_id' => $parent->id, | ||
| 'member_id' => $child->id, | ||
| 'member_type' => Group::class, | ||
| ]); | ||
| GroupMember::factory()->create([ | ||
| 'group_id' => $child->id, | ||
| 'member_id' => $grandchild->id, | ||
| 'member_type' => Group::class, | ||
| ]); | ||
| $user->groups()->attach($grandchild); | ||
|
|
||
| $task = ProcessRequestToken::factory()->create([ | ||
| 'is_self_service' => true, | ||
| 'status' => 'ACTIVE', | ||
| 'user_id' => null, | ||
| 'self_service_groups' => ['groups' => [(string) $parent->id]], | ||
| ]); | ||
|
|
||
| $this->assertContains($task->id, $user->availableSelfServiceTaskIds()); | ||
| Auth::login($user); | ||
| $this->assertTrue($user->canSelfServe($task)); | ||
| } | ||
|
|
||
| public function test_removing_subgroup_from_parent_drops_cached_self_service_visibility(): void | ||
| { | ||
| [$parent, $subgroup, $nestedUser] = $this->createNestedGroups(); | ||
|
|
||
| $task = ProcessRequestToken::factory()->create([ | ||
| 'is_self_service' => true, | ||
| 'status' => 'ACTIVE', | ||
| 'user_id' => null, | ||
| 'self_service_groups' => ['groups' => [$parent->id]], | ||
| ]); | ||
|
|
||
| $this->assertContains($task->id, $nestedUser->availableSelfServiceTaskIds()); | ||
|
|
||
| GroupMember::where('group_id', $parent->id) | ||
| ->where('member_id', $subgroup->id) | ||
| ->where('member_type', Group::class) | ||
| ->first() | ||
| ->delete(); | ||
|
|
||
| $this->assertNotContains($task->id, $nestedUser->fresh()->availableSelfServiceTaskIds()); | ||
| } | ||
|
|
||
| public function test_exclude_qualifies_columns_with_the_model_table(): void | ||
| { | ||
| $task = ProcessRequestToken::factory()->create([ | ||
| 'element_type' => 'task', | ||
| ]); | ||
|
|
||
| $found = ProcessRequestToken::exclude(['data'])->find($task->id); | ||
|
|
||
| $this->assertNotNull($found); | ||
| $this->assertSame($task->id, $found->id); | ||
| $this->assertStringContainsString( | ||
| '`process_request_tokens`.`id`', | ||
| ProcessRequestToken::exclude(['data'])->toSql() | ||
| ); | ||
| } | ||
|
|
||
| public function test_subgroup_member_sees_parent_self_service_task_on_tasks_index(): void | ||
| { | ||
| [$parent, , $nestedUser] = $this->createNestedGroups(); | ||
|
|
||
| $task = ProcessRequestToken::factory()->create([ | ||
| 'is_self_service' => true, | ||
| 'status' => 'ACTIVE', | ||
| 'user_id' => null, | ||
| 'element_type' => 'task', | ||
| 'self_service_groups' => ['groups' => [(string) $parent->id], 'users' => []], | ||
| ]); | ||
|
|
||
| $response = $this->actingAs($nestedUser, 'api')->getJson(route('api.tasks.index', [ | ||
| 'pmql' => '(status = "Self Service")', | ||
| 'per_page' => 15, | ||
| 'order_by' => 'ID', | ||
| 'order_direction' => 'DESC', | ||
| 'non_system' => true, | ||
| 'processesIManage' => false, | ||
| ])); | ||
|
|
||
| $response->assertOk(); | ||
| $this->assertContains($task->id, collect($response->json('data'))->pluck('id')); | ||
| } | ||
|
|
||
| /** | ||
| * @return array{0: Group, 1: Group, 2: User, 3: User, 4: User} | ||
| */ | ||
| private function createNestedGroups(): array | ||
| { | ||
| $parent = Group::factory()->create(['name' => 'Main']); | ||
| $subgroup = Group::factory()->create(['name' => 'Sub']); | ||
| $nestedUser = User::factory()->create(); | ||
| $directUser = User::factory()->create(); | ||
| $outsider = User::factory()->create(); | ||
|
|
||
| GroupMember::factory()->create([ | ||
| 'group_id' => $parent->id, | ||
| 'member_id' => $subgroup->id, | ||
| 'member_type' => Group::class, | ||
| ]); | ||
| $nestedUser->groups()->attach($subgroup); | ||
| $directUser->groups()->attach($parent); | ||
|
|
||
| return [$parent, $subgroup, $nestedUser, $directUser, $outsider]; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rodriquelca Could changing this foreach to a while loop cause any performance issues? Could you analyze it and also check what happens if a group has a recursive assignment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rodriquelca consider to add a test with circular reference of groups:
Seems the code covers it but please include it in a test