Skip to content
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

RES-1891 Network Coordinator can't create events on other groups they created #646

Merged
merged 1 commit into from
May 17, 2023
Merged
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
16 changes: 7 additions & 9 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,14 +537,12 @@ public function isCoordinatorForGroup($group)

public function groupsInChargeOf()
{
$groupsUserIsInChargeOf = collect([]);

if ($this->hasRole('Host')) {
$groupsUserIsInChargeOf = Group::join('users_groups', 'groups.idgroups', '=', 'users_groups.group')
->where('user', $this->id)
->where('role', 3)
->get();
} elseif ($this->hasRole('NetworkCoordinator')) {
$groupsUserIsInChargeOf = Group::join('users_groups', 'groups.idgroups', '=', 'users_groups.group')
->where('user', $this->id)
->where('role', 3)
->get();

if ($this->hasRole('NetworkCoordinator')) {
foreach ($this->networks as $network) {
foreach ($network->groups as $group) {
$groupsUserIsInChargeOf->push($group);
Expand All @@ -554,7 +552,7 @@ public function groupsInChargeOf()
$groupsUserIsInChargeOf = Group::all();
}

return $groupsUserIsInChargeOf;
return $groupsUserIsInChargeOf->unique();
}

public function ensureAPIToken()
Expand Down
26 changes: 26 additions & 0 deletions tests/Feature/Events/CreateEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -711,4 +711,30 @@ public function notifications_are_queued_as_expected()
# Should have queued ApproveEvent.
self::assertEquals(0, Queue::size('database'));
}

/** @test */
public function network_coordinator_other_group() {
$network = Network::factory()->create();

// Create a group in the network.
$groupInNetwork = Group::factory()->create();
$network->addGroup($groupInNetwork);

$coordinator = User::factory()->networkCoordinator()->create();
$network->addCoordinator($coordinator);

$this->actingAs($coordinator);

// Create a group not in the network.
$idgroup = $this->createGroup();
$groupNotInNetwork = Group::findOrFail($idgroup);
ngm marked this conversation as resolved.
Show resolved Hide resolved

// Both groups should show in the dropdown list for event creation.
$response = $this->get('/party/create');
$props = $this->getVueProperties($response);
$groups = json_decode($props[1][':groups'], TRUE);
self::assertEquals(2, count($groups));
self::assertEquals($groupNotInNetwork->idgroups, $groups[0]['idgroups']);
self::assertEquals($groupInNetwork->idgroups, $groups[1]['idgroups']);
}
}