Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
#89 - add organization profile scope bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Anna-Sokolowska committed May 11, 2022
1 parent d95551e commit d6cd834
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
12 changes: 6 additions & 6 deletions src/Http/Controllers/OrganizationProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,26 @@ public function store(StoreOrganizationProfileRequest $request, Organization $or
return redirect()->route("organizations.edit", $organization);
}

public function edit(Organization $organization, OrganizationProfile $profile): View
public function edit(Organization $organization, OrganizationProfile $organizationProfile): View
{
return view("organizations.profiles.edit")
->with([
"organization" => $organization,
"profile" => $profile,
"profile" => $organizationProfile,
"availableProfiles" => AvailableProfiles::casesToSelect(),
]);
}

public function update(UpdateOrganizationProfileRequest $request, Organization $organization, OrganizationProfile $profile): RedirectResponse
public function update(UpdateOrganizationProfileRequest $request, Organization $organization, OrganizationProfile $organizationProfile): RedirectResponse
{
$profile->update($request->validated());
$organizationProfile->update($request->validated());

return redirect()->route("organizations.edit", $organization);
}

public function destroy(Organization $organization, OrganizationProfile $profile): RedirectResponse
public function destroy(Organization $organization, OrganizationProfile $organizationProfile): RedirectResponse
{
$profile->delete();
$organizationProfile->delete();

return back();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Routing/WebRouting.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public function wire(): void
$this->router->controller(OrganizationProfileController::class)->group(function (): void {
$this->router->get("/organizations/{organization}/profiles/create", "create")->name("organizations.profiles.create");
$this->router->post("/organizations/{organization}/profiles", "store")->name("organizations.profiles.store");
$this->router->get("/organizations/{organization}/profiles/{profile}/edit", "edit")->name("organizations.profiles.edit");
$this->router->put("/organizations/{organization}/profiles/{profile}", "update")->name("organizations.profiles.update");
$this->router->delete("/organizations/{organization}/profiles/{profile}", "destroy")->name("organizations.profiles.destroy");
$this->router->get("/organizations/{organization}/profiles/{organizationProfile}/edit", "edit")->name("organizations.profiles.edit")->scopeBindings();
$this->router->put("/organizations/{organization}/profiles/{organizationProfile}", "update")->name("organizations.profiles.update")->scopeBindings();
$this->router->delete("/organizations/{organization}/profiles/{organizationProfile}", "destroy")->name("organizations.profiles.destroy")->scopeBindings();
});

$this->router->controller(SpeakersController::class)->group(function (): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,17 @@ public function testOrganizationProfileRequestHasRelatedOrganization(): void
$organization = Organization::factory()->create();
$foreignOrganization = Organization::factory()->create();

$organizationProfile = OrganizationProfile::factory()
OrganizationProfile::factory()
->for($organization)
->create();

$this->actingAs($this->admin)
->get(route("organizations.profiles.create", [$foreignOrganization, $organizationProfile]))
->assertNotFound();
$this->assertDatabaseCount("organization_profiles", 1);
$organizationProfile = OrganizationProfile::query()->first();

$this->actingAs($this->admin)
->get(route("organizations.profiles.edit", [$foreignOrganization, $organizationProfile]))
->assertNotFound();

$this->actingAs($this->admin)
->post(route("organizations.profiles.store", [$foreignOrganization, $organizationProfile]))
->assertNotFound();

$this->actingAs($this->admin)
->put(route("organizations.profiles.update", [$foreignOrganization, $organizationProfile]))
->assertNotFound();
Expand Down

0 comments on commit d6cd834

Please sign in to comment.