Skip to content

Commit

Permalink
Restrict authorization of global admins to prevent data corruption
Browse files Browse the repository at this point in the history
References biigle/core#331
  • Loading branch information
mzur committed Mar 19, 2021
1 parent d2ea40b commit 0fb0c33
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/Policies/AnnotationCandidatePolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class AnnotationCandidatePolicy extends CachedPolicy
*/
public function before($user, $ability)
{
if ($user->can('sudo')) {
$only = ['access'];

if ($user->can('sudo') && in_array($ability, $only)) {
return true;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Policies/MaiaJobPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class MaiaJobPolicy extends CachedPolicy
*/
public function before($user, $ability)
{
if ($user->can('sudo')) {
$except = ['update'];

if ($user->can('sudo') && !in_array($ability, $except)) {
return true;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Policies/TrainingProposalPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class TrainingProposalPolicy extends CachedPolicy
*/
public function before($user, $ability)
{
if ($user->can('sudo')) {
$only = ['access'];

if ($user->can('sudo') && in_array($ability, $only)) {
return true;
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Policies/AnnotationCandidatePolicyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testUpdate()
$this->assertTrue($this->editor()->can('update', $this->annotation));
$this->assertTrue($this->expert()->can('update', $this->annotation));
$this->assertTrue($this->admin()->can('update', $this->annotation));
$this->assertTrue($this->globalAdmin()->can('update', $this->annotation));
$this->assertFalse($this->globalAdmin()->can('update', $this->annotation));
}

public function testAttachLabel()
Expand Down Expand Up @@ -70,8 +70,8 @@ public function testAttachLabel()
$this->assertFalse($this->admin()->can('attach-label', [$this->annotation, $disallowedLabel]));
$this->assertFalse($this->admin()->can('attach-label', [$this->annotation, $otherDisallowedLabel]));

$this->assertTrue($this->globalAdmin()->can('attach-label', [$this->annotation, $allowedLabel]));
$this->assertTrue($this->globalAdmin()->can('attach-label', [$this->annotation, $disallowedLabel]));
$this->assertTrue($this->globalAdmin()->can('attach-label', [$this->annotation, $otherDisallowedLabel]));
$this->assertFalse($this->globalAdmin()->can('attach-label', [$this->annotation, $allowedLabel]));
$this->assertFalse($this->globalAdmin()->can('attach-label', [$this->annotation, $disallowedLabel]));
$this->assertFalse($this->globalAdmin()->can('attach-label', [$this->annotation, $otherDisallowedLabel]));
}
}
2 changes: 1 addition & 1 deletion tests/Policies/MaiaJobPolicyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testUpdate()
$this->assertTrue($this->editor()->can('update', $this->job));
$this->assertTrue($this->expert()->can('update', $this->job));
$this->assertTrue($this->admin()->can('update', $this->job));
$this->assertTrue($this->globalAdmin()->can('update', $this->job));
$this->assertFalse($this->globalAdmin()->can('update', $this->job));
}

public function testDestroy()
Expand Down
2 changes: 1 addition & 1 deletion tests/Policies/TrainingProposalPolicyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public function testUpdate()
$this->assertTrue($this->editor()->can('update', $this->annotation));
$this->assertTrue($this->expert()->can('update', $this->annotation));
$this->assertTrue($this->admin()->can('update', $this->annotation));
$this->assertTrue($this->globalAdmin()->can('update', $this->annotation));
$this->assertFalse($this->globalAdmin()->can('update', $this->annotation));
}
}

0 comments on commit 0fb0c33

Please sign in to comment.