mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-10-31 20:06:52 +01:00 
			
		
		
		
	 da195fd2fe
			
		
	
	
		da195fd2fe
		
			
		
	
	
	
	
		
			
			* Not found property rule * Make these “better” * Day 1 * Day 2 * Day 3 * Dat 4 * Remove disabled check * Day 4 continued * Run pint * Final changes hopefully * Pint fixes * Fix again * Reset these * Update app/Filament/Admin/Pages/Health.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> * Update app/Traits/CheckMigrationsTrait.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> --------- Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
		
			
				
	
	
		
			63 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Services\Subusers;
 | |
| 
 | |
| use App\Facades\Activity;
 | |
| use App\Models\Permission;
 | |
| use App\Models\Server;
 | |
| use App\Models\Subuser;
 | |
| use App\Repositories\Daemon\DaemonServerRepository;
 | |
| use Illuminate\Http\Client\ConnectionException;
 | |
| 
 | |
| class SubuserUpdateService
 | |
| {
 | |
|     public function __construct(
 | |
|         private DaemonServerRepository $serverRepository,
 | |
|     ) {}
 | |
| 
 | |
|     /**
 | |
|      * @param  string[]  $permissions
 | |
|      */
 | |
|     public function handle(Subuser $subuser, Server $server, array $permissions): void
 | |
|     {
 | |
|         $cleanedPermissions = collect($permissions)
 | |
|             ->unique()
 | |
|             ->filter(fn ($permission) => $permission === Permission::ACTION_WEBSOCKET_CONNECT || auth()->user()->can($permission, $server))
 | |
|             ->sort()
 | |
|             ->values()
 | |
|             ->all();
 | |
| 
 | |
|         $current = $subuser->permissions;
 | |
|         sort($current);
 | |
| 
 | |
|         $log = Activity::event('server:subuser.update')
 | |
|             ->subject($subuser->user)
 | |
|             ->property([
 | |
|                 'email' => $subuser->user->email,
 | |
|                 'old' => $current,
 | |
|                 'new' => $cleanedPermissions,
 | |
|                 'revoked' => true,
 | |
|             ]);
 | |
| 
 | |
|         // Only update the database and hit up the daemon instance to invalidate JTI's if the permissions
 | |
|         // have actually changed for the user.
 | |
|         if ($cleanedPermissions !== $current) {
 | |
|             $log->transaction(function ($instance) use ($subuser, $cleanedPermissions, $server) {
 | |
|                 $subuser->update(['permissions' => $cleanedPermissions]);
 | |
| 
 | |
|                 try {
 | |
|                     $this->serverRepository->setServer($server)->revokeUserJTI($subuser->user_id);
 | |
|                 } catch (ConnectionException $exception) {
 | |
|                     // Don't block this request if we can't connect to the daemon instance. Chances are it is
 | |
|                     // offline and the token will be invalid once daemon boots back.
 | |
|                     logger()->warning($exception, ['user_id' => $subuser->user_id, 'server_id' => $server->id]);
 | |
| 
 | |
|                     $instance->property('revoked', false);
 | |
|                 }
 | |
|             });
 | |
|         }
 | |
| 
 | |
|         $log->reset();
 | |
|     }
 | |
| }
 |