-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathRemoveExpiredGitHubAccess.php
More file actions
50 lines (39 loc) · 1.53 KB
/
RemoveExpiredGitHubAccess.php
File metadata and controls
50 lines (39 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace App\Console\Commands;
use App\Models\User;
use App\Support\GitHubOAuth;
use Illuminate\Console\Command;
class RemoveExpiredGitHubAccess extends Command
{
protected $signature = 'github:remove-expired-access';
protected $description = 'Remove GitHub repository access for users whose Max licenses have expired';
public function handle(): int
{
$github = GitHubOAuth::make();
$removed = 0;
// Find users with GitHub access granted
$users = User::query()
->whereNotNull('mobile_repo_access_granted_at')
->whereNotNull('github_username')
->get();
foreach ($users as $user) {
// Check if user still qualifies for mobile repo access
if (! $user->hasMobileRepoAccess()) {
// Remove from repository
$success = $github->removeFromMobileRepo($user->github_username);
if ($success) {
// Clear the access timestamp
$user->update([
'mobile_repo_access_granted_at' => null,
]);
$this->info("Removed access for user: {$user->email} (@{$user->github_username})");
$removed++;
} else {
$this->error("Failed to remove access for user: {$user->email} (@{$user->github_username})");
}
}
}
$this->info("Total users with access removed: {$removed}");
return Command::SUCCESS;
}
}