Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-verify user permissions periodically #538

Merged
merged 1 commit into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions app/Console/Commands/ReverifyAllUsersCommand.php

This file was deleted.

34 changes: 34 additions & 0 deletions app/Console/Commands/Scheduled/ReverifyAllUsersCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Console\Commands\Scheduled;

use App\Models\User;
use Illuminate\Console\Command;

class ReverifyAllUsersCommand extends Command
{
protected $signature = 'utrs-jobs:reverify-user-permissions';
protected $description = 'Re-verifies permissions of users that have not been verified recently';

/** @var int All users should be re-verified every this many days. */
protected $targetReverifyInterval = 14;

public function handle()
{
$limit = (int) ceil(User::count() / $this->targetReverifyInterval) + 1;

$this->info("Finding max $limit users");
$users = User::limit($limit)
->orderBy('last_permission_check_at')
->cursor();

foreach ($users as $user) {
/** @var User $user */
$this->info("Re-verifying user $user->username (ID $user->id)...");
$user->queuePermissionChecks();
}

$this->info('Done.');
return 0;
}
}
3 changes: 3 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ protected function schedule(Schedule $schedule)

// Close expired NOTFOUND appeals
$schedule->command('utrs-jobs:close-expired-notfound')->everyFourHours();

// Permission updates
$schedule->command('utrs-jobs:reverify-user-permissions')->daily()->at('14:00');
}

/**
Expand Down