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

Don't allow review of storage requests that were not submitted #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion src/Http/Controllers/Views/StorageRequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ public function create(Request $request)
public function review($id)
{
$request = StorageRequest::whereNull('expires_at')
->whereNotNull('submitted_at')
->with('files')
->findOrFail($id);
$this->authorize('approve', $request);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

return view('user-storage::review', [
'request' => $request,
]);
Expand Down
54 changes: 31 additions & 23 deletions tests/Http/Controllers/Views/StorageRequestControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,42 @@ public function testIndex()
}

public function testReview()
{
$request = StorageRequest::factory()->create();
$id = $request->id;
{
$request = StorageRequest::factory()->create();
$id = $request->id;

$this->get("storage-requests/{$id}/review")->assertRedirect('login');
$this->get("storage-requests/{$id}/review")->assertRedirect('login');

$this->actingAs($request->user)
->get("storage-requests/{$id}/review")
->assertStatus(403);
$this->actingAs($request->user)
->get("storage-requests/{$id}/review")
->assertStatus(403);

$user = UserTest::create([
'role_id' => Role::editorId(),
]);
$user = UserTest::create([
'role_id' => Role::editorId(),
]);

$this->actingAs($user)
->get("storage-requests/{$id}/review")
->assertStatus(403);
$this->actingAs($user)
->get("storage-requests/{$id}/review")
->assertStatus(403);
Comment on lines +69 to +71
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails with Expected response status code [403] but received 404.


$user->role_id = Role::adminId();
$user->save();
$user->role_id = Role::adminId();
$user->save();

$this->actingAs($user)
->get("storage-requests/{$id}/review")
->assertViewIs('user-storage::review');
// Test for unsubmitted request
$this->actingAs($user)
->get("storage-requests/{$id}/review")
->assertStatus(404);

$request->update(['expires_at' => '2022-03-28 10:40:00']);
$this->actingAs($user)
->get("storage-requests/{$id}/review")
->assertStatus(404);
}
// Mark the request as submitted
$request->update(['submitted_at' => now()]);

$this->actingAs($user)
->get("storage-requests/{$id}/review")
->assertViewIs('user-storage::review');

$request->update(['expires_at' => '2022-03-28 10:40:00']);
$this->actingAs($user)
->get("storage-requests/{$id}/review")
->assertStatus(404);
}
Comment on lines +55 to +92
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the indentation here.

}
Loading