Skip to content

Commit f2f375c

Browse files
committed
Autorize repository
1 parent 2752332 commit f2f375c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Http/Requests/InteractWithRepositories.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function repository($key = null)
4343
]), 404);
4444
}
4545

46-
if (! $repository::authorizedToShowAny($this)) {
46+
if (! $repository::authorizedToShowRepository($this)) {
4747
throw new UnauthorizedException(__('Unauthorized to view repository :name.', [
4848
'name' => $repository,
4949
]), 403);

src/Traits/AuthorizableModels.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ public static function authorizedToShowAny(Request $request)
6969
: true;
7070
}
7171

72+
/**
73+
* Determine if the repository url is available
74+
*
75+
* @param \Illuminate\Http\Request $request
76+
* @return bool
77+
*/
78+
public static function authorizedToShowRepository(Request $request)
79+
{
80+
if (! static::authorizable()) {
81+
return true;
82+
}
83+
84+
return method_exists(Gate::getPolicyFor(static::newModel()), 'showRepository')
85+
? Gate::check('showRepository', get_class(static::newModel()))
86+
: true;
87+
}
88+
7289
/**
7390
* Determine if the current user can view the given resource or throw.
7491
*

0 commit comments

Comments
 (0)