Skip to content

Commit

Permalink
Implement exceptions so global admins can access Largo everywhere
Browse files Browse the repository at this point in the history
References #86
References biigle/core#331
  • Loading branch information
mzur committed Mar 19, 2021
1 parent fa48e44 commit 3fd350e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/Http/Controllers/Views/Projects/LargoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Biigle\Http\Controllers\Views\Controller;
use Biigle\Project;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Storage;

Expand All @@ -12,13 +13,16 @@ class LargoController extends Controller
/**
* Show the Largo view for a project.
*
* @param Request $request
* @param int $id Project ID
* @return \Illuminate\Http\Response
*/
public function index($id)
public function index(Request $request, $id)
{
$project = Project::findOrFail($id);
$this->authorize('edit-in', $project);
if (!$request->user()->can('sudo')) {
$this->authorize('edit-in', $project);
}

if (!$project->volumes()->exists()) {
abort(Response::HTTP_NOT_FOUND);
Expand Down
4 changes: 3 additions & 1 deletion src/Http/Controllers/Views/Volumes/LargoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class LargoController extends Controller
public function index(Request $request, $id)
{
$volume = Volume::findOrFail($id);
$this->authorize('edit-in', $volume);
if (!$request->user()->can('sudo')) {
$this->authorize('edit-in', $volume);
}

if ($request->user()->can('sudo')) {
// Global admins have no restrictions.
Expand Down
2 changes: 1 addition & 1 deletion src/resources/views/projectsShowTabs.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@if ($user->can('edit-in', $project) && $project->volumes()->exists())
@if (($user->can('edit-in', $project) || $user->can('sudo')) && $project->volumes()->exists())
<li role="presentation">
<a href="{{route('projectsLargo', $project->id)}}" title="Perform Largo re-evaluation of annotations for this project"><i class="fa fa-check-square"></i> Largo</a>
</li>
Expand Down
4 changes: 2 additions & 2 deletions src/resources/views/volumesSidebar.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@can ('edit-in', $volume)
@canany (['edit-in', 'sudo'], $volume)
<sidebar-tab name="largo" icon="check-square" title="Perform Largo re-evaluation of annotations for this volume" href="{{ route('largo', $volume->id) }}"></sidebar-tab>
@endcan
@endcanany
9 changes: 9 additions & 0 deletions tests/Http/Controllers/Views/LargoControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public function testIndexImageVolume()

$this->beEditor();
$this->get("volumes/{$id}/largo")->assertStatus(200);

$this->beGlobalAdmin();
$this->get("volumes/{$id}/largo")->assertStatus(200);
}

public function testIndexVideoVolume()
Expand All @@ -30,6 +33,9 @@ public function testIndexVideoVolume()

$this->beEditor();
$this->get("volumes/{$id}/largo")->assertStatus(200);

$this->beGlobalAdmin();
$this->get("volumes/{$id}/largo")->assertStatus(200);
}

public function testIndexProject()
Expand All @@ -48,5 +54,8 @@ public function testIndexProject()
$volume->media_type_id = MediaType::videoId();
$volume->save();
$this->get("projects/{$id}/largo")->assertStatus(200);

$this->beGlobalAdmin();
$this->get("projects/{$id}/largo")->assertStatus(200);
}
}

0 comments on commit 3fd350e

Please sign in to comment.