Skip to content
Open
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
4 changes: 3 additions & 1 deletion database/seeders/UserSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public function run(ClientRepository $clients)
]);

// Create client so we can generate tokens
$clients->createPersonalAccessGrantClient('PmApi');
$personalAccessClient = $clients->createPersonalAccessGrantClient('PmApi');
$personalAccessClient->user_id = $user->id;
$personalAccessClient->save();

// Create client OAuth (for 3-legged auth) - Authorization Code Grant for Swagger UI
$clients->createAuthorizationCodeGrantClient(
Expand Down
60 changes: 60 additions & 0 deletions upgrades/2026_05_07_212653_set_user_id_on_oauth_client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

use Illuminate\Support\Facades\DB;
use ProcessMaker\Upgrades\UpgradeMigration as Upgrade;

class SetUserIdOnOauthClient extends Upgrade
{
/**
* Run any validations/pre-run checks to ensure the environment, settings,
* packages installed, etc. are right correct to run this upgrade.
*
* Throw a \RuntimeException if the conditions are *NOT* correct for this
* upgrade migration to run. If this is not a required upgrade, then it
* will be skipped. Otherwise the exception thrown will be caught, noted,
* and will prevent the remaining migrations from continuing to run.
*
* Returning void or null denotes the checks were successful.
*
* @return void
*
* @throws RuntimeException
*/
public function preflightChecks()
{
//
}

/**
* Run the upgrade migration.
*
* @return void
*/
public function up()
{
$adminUserId = DB::table('users')
->where('is_administrator', true)
->orderBy('id')
->value('id');

if ($adminUserId === null) {
return;
}

DB::table('oauth_clients')
->where('name', 'PmApi')
->update(['user_id' => $adminUserId]);
}

/**
* Reverse the upgrade migration.
*
* @return void
*/
public function down()
{
DB::table('oauth_clients')
->where('name', 'PmApi')
->update(['user_id' => null]);
}
}
Loading