Skip to content

Commit

Permalink
Fix editing URLs (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
NFarrington authored Aug 8, 2024
1 parent 03a2f31 commit c84ac0e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/Http/Controllers/Platform/UrlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand All @@ -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],
Expand Down
22 changes: 22 additions & 0 deletions tests/Feature/Platform/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
7 changes: 7 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit c84ac0e

Please sign in to comment.