fix: access team's github apps only

This commit is contained in:
Andras Bacsai
2024-10-24 13:28:31 +02:00
parent 23f7932964
commit bdf9b98596
3 changed files with 54 additions and 41 deletions

View File

@@ -93,11 +93,10 @@ class Change extends Component
// } // }
public function mount() public function mount()
{ {
try {
$github_app_uuid = request()->github_app_uuid; $github_app_uuid = request()->github_app_uuid;
$this->github_app = GithubApp::where('uuid', $github_app_uuid)->first(); $this->github_app = GithubApp::ownedByCurrentTeam()->whereUuid($github_app_uuid)->firstOrFail();
if (! $this->github_app) {
return redirect()->route('source.all');
}
$this->applications = $this->github_app->applications; $this->applications = $this->github_app->applications;
$settings = instanceSettings(); $settings = instanceSettings();
$this->github_app->makeVisible('client_secret')->makeVisible('webhook_secret'); $this->github_app->makeVisible('client_secret')->makeVisible('webhook_secret');
@@ -139,6 +138,10 @@ class Change extends Component
$this->webhook_endpoint = $this->ipv4; $this->webhook_endpoint = $this->ipv4;
$this->is_system_wide = $this->github_app->is_system_wide; $this->is_system_wide = $this->github_app->is_system_wide;
} }
} catch (\Throwable $e) {
return handleError($e, $this);
}
} }
public function submit() public function submit()

View File

@@ -31,6 +31,11 @@ class GithubApp extends BaseModel
}); });
} }
public static function ownedByCurrentTeam()
{
return GithubApp::whereTeamId(currentTeam()->id);
}
public static function public() public static function public()
{ {
return GithubApp::whereTeamId(currentTeam()->id)->whereisPublic(true)->whereNotNull('app_id')->get(); return GithubApp::whereTeamId(currentTeam()->id)->whereisPublic(true)->whereNotNull('app_id')->get();

View File

@@ -9,6 +9,11 @@ class GitlabApp extends BaseModel
'app_secret', 'app_secret',
]; ];
public static function ownedByCurrentTeam()
{
return GitlabApp::whereTeamId(currentTeam()->id);
}
public function applications() public function applications()
{ {
return $this->morphMany(Application::class, 'source'); return $this->morphMany(Application::class, 'source');