diff --git a/app/Http/Controllers/Platform/UrlController.php b/app/Http/Controllers/Platform/UrlController.php index e60b5f7..67c2c48 100644 --- a/app/Http/Controllers/Platform/UrlController.php +++ b/app/Http/Controllers/Platform/UrlController.php @@ -270,6 +270,9 @@ public function update(Request $request, Url $url) 'organization_id' => 'nullable|integer|exists:'.Organization::class.',id', ] ); + if ($attributes['organization_id'] !== null) { + $attributes['organization_id'] = (int) $attributes['organization_id']; + } $oldOrganizationId = $url->getOrganization() ? $url->getOrganization()->getId() : null; if ($attributes['organization_id'] !== $oldOrganizationId) { @@ -306,7 +309,7 @@ public function destroy(Url $url) $this->entityManager->flush(); $this->simpleDbClient->deleteAttributes([ 'DomainName' => self::simpleDbDomainName, - 'ItemName' => Str::lower($url->getFullUrl()), + 'ItemName' => Str::lower($url->getFullUrl()), ]); $this->urlService->removeUrlFromCache($url); @@ -318,7 +321,7 @@ public function createOrUpdateUrlInSimpleDb(Url $url) { $putAttributesCommand = $this->simpleDbClient->getCommand('putAttributes', [ 'DomainName' => self::simpleDbDomainName, - 'ItemName' => Str::lower($url->getFullUrl()), + 'ItemName' => Str::lower($url->getFullUrl()), 'Attributes' => [ ['Name' => 'RedirectUrl', 'Value' => $url->getRedirectUrl(), 'Replace' => true], ['Name' => 'UpdatedAt', 'Value' => Carbon::now()->toIso8601ZuluString(), 'Replace' => true], diff --git a/tests/Feature/Platform/UrlTest.php b/tests/Feature/Platform/UrlTest.php index 9fdf2a4..7b6eef3 100644 --- a/tests/Feature/Platform/UrlTest.php +++ b/tests/Feature/Platform/UrlTest.php @@ -309,6 +309,28 @@ function user_can_edit_url_owned_by_organization() ]); } + /** @test */ + function user_can_edit_url_with_a_prefix_owned_by_organization() + { + $template = make(Url::class); + $organization = entity(Organization::class)->states('prefix')->create(); + create(OrganizationUser::class, ['user' => $this->user, 'organization' => $organization, 'roleId' => OrganizationUser::ROLE_MEMBER]); + EntityManager::refresh($organization); + EntityManager::refresh($this->user); + $url = entity(Url::class)->states('org', 'prefix')->create(['organization' => $organization]); + + $this->get(route('platform.urls.edit', $url)); + $this->put(route('platform.urls.update', $url), [ + 'redirect_url' => $template->getRedirectUrl(), + 'organization_id' => $organization->getId(), + ])->assertRedirect() + ->assertSessionHas('success'); + $this->assertDatabaseHas(EntityManager::getClassMetadata(Url::class)->getTableName(), [ + 'redirect_url' => $template->getRedirectUrl(), + 'organization_id' => $organization->getId(), + ]); + } + /** @test */ function user_can_move_url_into_an_organization() { diff --git a/tests/TestCase.php b/tests/TestCase.php index e44e181..8ca20c6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -66,4 +66,11 @@ protected function refreshAllEntities(EntityManagerInterface $em = null) } } } + + public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null) + { + $parameters = array_map(function ($a) { return (string) $a; }, $parameters); + + return parent::call($method, $uri, $parameters, $cookies, $files, $server, $content); + } }