-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #352 from silinternational/feature/idp-1176-add-gr…
…oups-external-field [IDP-1176] Add `groups_external` field to User
- Loading branch information
Showing
9 changed files
with
219 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
application/console/migrations/m240813_155757_add_groups_external_field_to_user.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
use yii\db\Migration; | ||
|
||
/** | ||
* Class m240813_155757_add_groups_external_field_to_user | ||
*/ | ||
class m240813_155757_add_groups_external_field_to_user extends Migration | ||
{ | ||
public function safeUp() | ||
{ | ||
$this->addColumn( | ||
'{{user}}', | ||
'groups_external', | ||
$this->string()->notNull()->defaultValue('')->after('groups') | ||
); | ||
} | ||
|
||
public function safeDown() | ||
{ | ||
$this->dropColumn('{{user}}', 'groups_external'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
application/features/bootstrap/GroupsExternalContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
|
||
namespace Sil\SilIdBroker\Behat\Context; | ||
|
||
use Behat\Gherkin\Node\TableNode; | ||
use common\models\User; | ||
use FeatureContext; | ||
use Webmozart\Assert\Assert; | ||
|
||
class GroupsExternalContext extends FeatureContext | ||
{ | ||
private User $user; | ||
private string $userEmailAddress = '[email protected]'; | ||
private string $userPassword = 'dummy-password-#1'; | ||
|
||
/** | ||
* @Given a user exists | ||
*/ | ||
public function aUserExists() | ||
{ | ||
$this->deleteThatTestUser(); | ||
$this->createTestUser(); | ||
$this->setThatUsersPassword($this->userPassword); | ||
} | ||
|
||
private function deleteThatTestUser() | ||
{ | ||
$user = User::findByEmail($this->userEmailAddress); | ||
if ($user !== null) { | ||
$didDeleteUser = $user->delete(); | ||
Assert::notFalse($didDeleteUser, sprintf( | ||
'Failed to delete existing test user: %s', | ||
join("\n", $user->getFirstErrors()) | ||
)); | ||
} | ||
} | ||
|
||
private function createTestUser() | ||
{ | ||
$user = new User([ | ||
'email' => $this->userEmailAddress, | ||
'employee_id' => '11111', | ||
'first_name' => 'John', | ||
'last_name' => 'Smith', | ||
'username' => 'john_smith', | ||
]); | ||
$user->scenario = User::SCENARIO_NEW_USER; | ||
|
||
$createdNewUser = $user->save(); | ||
Assert::true($createdNewUser, sprintf( | ||
'Failed to create test user: %s', | ||
join("\n", $user->getFirstErrors()) | ||
)); | ||
$user->refresh(); | ||
|
||
$this->user = $user; | ||
} | ||
|
||
private function setThatUsersPassword(string $password) | ||
{ | ||
$this->user->scenario = User::SCENARIO_UPDATE_PASSWORD; | ||
$this->user->password = $password; | ||
|
||
Assert::true($this->user->save(), sprintf( | ||
"Failed to set the test user's password: %s", | ||
join("\n", $this->user->getFirstErrors()) | ||
)); | ||
} | ||
|
||
/** | ||
* @Given that user's list of groups is :commaSeparatedGroups | ||
*/ | ||
public function thatUsersListOfGroupsIs($commaSeparatedGroups) | ||
{ | ||
$this->user->groups = $commaSeparatedGroups; | ||
$this->user->scenario = User::SCENARIO_UPDATE_USER; | ||
|
||
$savedChanges = $this->user->save(); | ||
Assert::true($savedChanges, sprintf( | ||
'Failed to set list of `groups` on test user: %s', | ||
join("\n", $this->user->getFirstErrors()) | ||
)); | ||
} | ||
|
||
/** | ||
* @Given that user's list of external groups is :commaSeparatedExternalGroups | ||
*/ | ||
public function thatUsersListOfExternalGroupsIs($commaSeparatedExternalGroups) | ||
{ | ||
$this->user->groups_external = $commaSeparatedExternalGroups; | ||
$this->user->scenario = User::SCENARIO_UPDATE_USER; | ||
|
||
$savedChanges = $this->user->save(); | ||
Assert::true($savedChanges, sprintf( | ||
'Failed to set list of `groups_external` on test user: %s', | ||
join("\n", $this->user->getFirstErrors()) | ||
)); | ||
} | ||
|
||
/** | ||
* @When I sign in as that user | ||
*/ | ||
public function iSignInAsThatUser() | ||
{ | ||
$dataForTableNode = [ | ||
['property', 'value'], | ||
['username', $this->user->username], | ||
['password', $this->userPassword], | ||
]; | ||
$this->iProvideTheFollowingValidData(new TableNode($dataForTableNode)); | ||
$this->iRequestTheResourceBe('/authentication', 'created'); | ||
$this->theResponseStatusCodeShouldBe(200); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Feature: Incorporating custom (external) groups in a User's `members` list | ||
|
||
Background: | ||
Given the requester is authorized | ||
|
||
# Scenarios that belong here in ID Broker: | ||
|
||
Scenario: Include external groups in a User's `members` list | ||
Given a user exists | ||
And that user's list of groups is "one,two" | ||
And that user's list of external groups is "app-three,app-four" | ||
When I sign in as that user | ||
Then the response should contain a member array with only these elements: | ||
| element | | ||
| one | | ||
| two | | ||
| app-three | | ||
| app-four | | ||
| {idpName} | | ||
|
||
Scenario: Gracefully handle an empty list of groups in a User's `members` list | ||
Given a user exists | ||
And that user's list of groups is "" | ||
And that user's list of external groups is "app-three,app-four" | ||
When I sign in as that user | ||
Then the response should contain a member array with only these elements: | ||
| element | | ||
| app-three | | ||
| app-four | | ||
| {idpName} | | ||
|
||
Scenario: Gracefully handle an empty list of external groups in a User's `members` list | ||
Given a user exists | ||
And that user's list of groups is "one,two" | ||
And that user's list of external groups is "" | ||
When I sign in as that user | ||
Then the response should contain a member array with only these elements: | ||
| element | | ||
| one | | ||
| two | | ||
| {idpName} | | ||
|
||
# Scenario: Update a user's `groups_external` list, given a group prefix and list of groups | ||
|
||
# # Scenarios that belong in the new "groups_external" sync: | ||
# Scenario: Send 1 notification email if sync finds group(s) for a user not in this IDP | ||
# Scenario: Add entries in the synced Google Sheet to the `groups_external` field | ||
# Scenario: Remove entries not in the synced Google Sheet from the `groups_external` field | ||
# Scenario: Only use entries from the synced Google Sheet that specify this IDP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters