Skip to content

Commit

Permalink
Delete unused checkUserPolicy() function (#1522)
Browse files Browse the repository at this point in the history
#1510 removed the last reference to the `checkUserPolicy()` function.
Gates are now the preferred access control method, so
`checkUserPolicy()` has been eliminated.
  • Loading branch information
williamjallen committed Jun 28, 2023
1 parent 149911e commit ae056e2
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 52 deletions.
42 changes: 0 additions & 42 deletions app/cdash/include/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,48 +343,6 @@ function setVersion(): void
$db->execute($stmt, $version);
}

/**
* TODO: (williamjallen) This function's return type is excessively complex and makes it
* difficult to handle.
*
* Return true if the user is allowed to see the page
*/
function checkUserPolicy($projectid, $onlyreturn = 0): bool|RedirectResponse|Response
{
if (!is_numeric($projectid)) {
return response('Insufficient data to determine access');
}

// If the projectid is 0 only admin can access the page.
if ($projectid == 0) {
if (Auth::check()) {
$user = Auth::user();
if ($user->IsAdmin()) {
return true;
}
}
} else {
$project = new Project();
$project->Id = $projectid;
$project->Fill();

if (Gate::allows('view-project', $project)) {
return true;
}
}

if ($onlyreturn) {
return false;
}

if (!Auth::check()) {
session(['url.intended' => url()->current()]);
return redirect()->route('login');
}

return response('You cannot access this project');
}

/**
* Get the build id from stamp, name and buildname
*/
Expand Down
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -11931,16 +11931,6 @@ parameters:
count: 1
path: app/cdash/include/common.php

-
message: "#^Function checkUserPolicy\\(\\) has parameter \\$onlyreturn with no type specified\\.$#"
count: 1
path: app/cdash/include/common.php

-
message: "#^Function checkUserPolicy\\(\\) has parameter \\$projectid with no type specified\\.$#"
count: 1
path: app/cdash/include/common.php

-
message: "#^Function compute_percentcoverage\\(\\) has no return type specified\\.$#"
count: 1
Expand Down

0 comments on commit ae056e2

Please sign in to comment.