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

Add shared-device role to allow accounts to bypass authentication checks #4801

Merged
merged 3 commits into from
Sep 10, 2024
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
5 changes: 3 additions & 2 deletions app/Nova/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function fields(NovaRequest $request): array
return [
Hidden::make('Has Ever Logged In')
->showOnCreating()
->default(static fn (Request $r): bool => false),
->default(static fn (Request $r): int => 0),

Text::make('Username', 'uid')
->sortable()
Expand Down Expand Up @@ -413,7 +413,8 @@ public function fields(NovaRequest $request): array
->hideFromDetail(static fn (NovaRequest $r, AppModelsUser $u): bool => $u->is_service_account),

HasMany::make('Access Cards')
->canSee(static fn (Request $request): bool => $request->user()->hasRole('admin')),
->canSee(static fn (Request $request): bool => $request->user()->hasRole('admin'))
->hideFromDetail(static fn (NovaRequest $r, AppModelsUser $u): bool => $u->is_service_account),

HasMany::make('Attendance')
->canSee(static function (Request $request): bool {
Expand Down
6 changes: 6 additions & 0 deletions app/Util/CasUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public static function createOrUpdate(): User
Cas::setAttributes($masq_attrs);
}

$existing_user = User::where('uid', Cas::user())->first();

if ($existing_user !== null && $existing_user->hasRole('shared-device')) {
return $existing_user;
}

if (config('features.sandbox-mode') !== true) {
foreach ($attrs as $attr) {
if (
Expand Down
42 changes: 42 additions & 0 deletions database/migrations/2024_09_08_203808_add_shared_device_role.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
app()['cache']->forget('spatie.permission.cache');

$create_attendance = Permission::firstOrCreate(['name' => 'create-attendance']);
$read_events = Permission::firstOrCreate(['name' => 'read-events']);
$read_teams = Permission::firstOrCreate(['name' => 'read-teams']);
$read_teams_hidden = Permission::firstOrCreate(['name' => 'read-teams-hidden']);
$read_users = Permission::firstOrCreate(['name' => 'read-users']);

$shared_device = Role::firstOrCreate(['name' => 'shared-device']);

$shared_device->givePermissionTo($create_attendance);
$shared_device->givePermissionTo($read_events);
$shared_device->givePermissionTo($read_teams);
$shared_device->givePermissionTo($read_teams_hidden);
$shared_device->givePermissionTo($read_users);
}

/**
* Reverse the migrations.
*/
public function down(): void
{
app()['cache']->forget('spatie.permission.cache');

Role::where('name', 'shared-device')->delete();
}
};