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

[IDP-1176] Add groups_external field to User #352

Merged
merged 22 commits into from
Aug 20, 2024

Conversation

forevermatt
Copy link
Contributor

IDP-1176 Add groups_external field to ID Broker's database


Added

  • Add groups_external field to User
  • Add phpMyAdmin container for testdb

Changed (non-breaking)

  • Include groups_external values in a User's member list during login

Feature PR Checklist

  • Documentation (README, local.env.dist, etc.)
  • Unit tests created or updated
  • Run make composershow
  • Run make psr2

Note:
This does not yet provide any mechanism for setting the new groups_external field. That will come in a subsequent PR.

@forevermatt forevermatt requested a review from a team August 19, 2024 18:31
@forevermatt
Copy link
Contributor Author

Fixing the bug (revealed by the tests) currently...

Copy link

sonarcloud bot commented Aug 19, 2024

Quality Gate Passed Quality Gate passed

Issues
1 New issue
1 Accepted issue

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@forevermatt
Copy link
Contributor Author

Fixed.

$this->addColumn(
'{{user}}',
'groups_external',
$this->string()->notNull()->defaultValue('')->after('groups')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Yii syntax is ugly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP syntax is ugly. 😛

Copy link

@mtompset mtompset left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference between internal and external groups is unclear to me, but I wouldn't be surprised if it is somehow related to a Google API somewhere.

@forevermatt
Copy link
Contributor Author

The difference between internal and external groups is unclear to me, but I wouldn't be surprised if it is somehow related to a Google API somewhere.

Thanks for mentioning that. The normal list of groups comes from the HR system, via ID Sync. This new groups_external field is for additional groups that need to be added from some other data source (e.g. a Google Sheet) that is external to the HR system.

Comment on lines 571 to 576
'member' => function (self $model) {
if (!empty($model->groups)) {
$member = explode(',', $model->groups);
} else {
$member = [];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the else added? Is there some sort of "strict" mode that would flag an error when assigning to a new array key on a yet-undefined variable (e.g. line 581 or 585). If so, then maybe this is better:

Suggested change
'member' => function (self $model) {
if (!empty($model->groups)) {
$member = explode(',', $model->groups);
} else {
$member = [];
}
'member' => function (self $model) {
$member = [];
if (!empty($model->groups)) {
$member = explode(',', $model->groups);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a variable without defining it (e.g. assigning something to an array on an uninitialized array, in PHP) seems like a code smell. I simply added the else to ensure that the array would exist and be in the desired state, regardless of which path through the logic was executed.

Initializing the array first, as you suggested, is another valid option, but since it would be replaced with a different array within the if-block, I decided to only set it to an empty array if needed, rather than every time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for discussing it, though 👍

$this->addColumn(
'{{user}}',
'groups_external',
$this->string()->notNull()->defaultValue('')->after('groups')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP syntax is ugly. 😛

@forevermatt forevermatt merged commit 747c877 into develop Aug 20, 2024
3 checks passed
@forevermatt forevermatt deleted the feature/idp-1176-add-groups-external-field branch August 20, 2024 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants