From 8d538f6e9219c2ae67667064a62c1280e505be09 Mon Sep 17 00:00:00 2001 From: Rich Lott / Artful Robot Date: Fri, 30 Jun 2023 11:45:35 +0100 Subject: [PATCH] standalone: civilint --- .../Civi/Standalone/Security.php | 2 +- .../phpunit/Civi/Standalone/SecurityTest.php | 22 +++++++++---------- .../init/StandaloneUsers.civi-setup.php | 9 ++++---- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/ext/standaloneusers/Civi/Standalone/Security.php b/ext/standaloneusers/Civi/Standalone/Security.php index 04b94c8470..c2f4e2cead 100644 --- a/ext/standaloneusers/Civi/Standalone/Security.php +++ b/ext/standaloneusers/Civi/Standalone/Security.php @@ -74,7 +74,7 @@ class Security { // @todo handle anonymous permissions! $roleIDs = \Civi\Api4\User::get(FALSE)->addWhere('id', '=', $userID) - ->addSelect('roles')->execute()->first()['roles']; + ->addSelect('roles')->execute()->first()['roles']; // artfulrobot: I think we should cache these per request, e.g. Civi::$statics? // except in testing permissions shouldn't change during a request. @todo diff --git a/ext/standaloneusers/tests/phpunit/Civi/Standalone/SecurityTest.php b/ext/standaloneusers/tests/phpunit/Civi/Standalone/SecurityTest.php index b37f5b0c97..97db8a5f90 100644 --- a/ext/standaloneusers/tests/phpunit/Civi/Standalone/SecurityTest.php +++ b/ext/standaloneusers/tests/phpunit/Civi/Standalone/SecurityTest.php @@ -75,22 +75,22 @@ class SecurityTest extends \PHPUnit\Framework\TestCase implements EndToEndInterf // Create a custom role $roleID = \Civi\Api4\OptionValue::create(FALSE) - ->setValues([ - 'option_group_id.name' => 'role', - 'name' => 'demo_role', - 'label' => 'demo_role', - ])->execute()->first()['value']; + ->setValues([ + 'option_group_id.name' => 'role', + 'name' => 'demo_role', + 'label' => 'demo_role', + ])->execute()->first()['value']; // Give our user this role only. \Civi\Api4\User::update(FALSE) - ->addValue('roles', [$roleID]) - ->addWhere('id', '=', $userID) - ->execute(); + ->addValue('roles', [$roleID]) + ->addWhere('id', '=', $userID) + ->execute(); $existingPermissions = \Civi\Api4\RolePermission::get(FALSE) - ->selectRowCount() - ->addWhere('role_id', '=', $demoRoleID) - ->execute()->count(); + ->selectRowCount() + ->addWhere('role_id', '=', $demoRoleID) + ->execute()->count(); $this->assertEquals(0, $existingPermissions); // Assign some permissions to the role. diff --git a/setup/plugins/init/StandaloneUsers.civi-setup.php b/setup/plugins/init/StandaloneUsers.civi-setup.php index 8c2e1395a2..692dc1b1b1 100644 --- a/setup/plugins/init/StandaloneUsers.civi-setup.php +++ b/setup/plugins/init/StandaloneUsers.civi-setup.php @@ -40,7 +40,8 @@ if (!defined('CIVI_SETUP')) { \Civi\Setup::log()->info(sprintf('[%s] Handle %s', basename(__FILE__), 'installDatabase')); - $roleID = 1; // admin should always be role 1 on install. + // admin should always be role 1 on install. + $roleID = 1; // @todo I expect there's a better way than this; this doesn't even bring in all the permissions. $records = [['permission' => 'authenticate with password']]; @@ -72,9 +73,9 @@ if (!defined('CIVI_SETUP')) { // Assign 'admin' role to user \Civi\Api4\User::update(FALSE) - ->addWhere('id', '=', $userID) - ->addValue('roles', [$roleID]) - ->execute(); + ->addWhere('id', '=', $userID) + ->addValue('roles', [$roleID]) + ->execute(); $message = "Created new user \"{$e->getModel()->extras['adminUser']}\" (user ID #$userID, contact ID #$contactID) with 'admin' role and "; $message .= empty($e->getModel()->extras['adminPassWasSpecified']) -- 2.25.1