Skip to content

Commit

Permalink
Merge pull request #112 from silinternational/develop
Browse files Browse the repository at this point in the history
Release 4.1.1
  • Loading branch information
briskt authored Feb 17, 2021
2 parents 72a9c46 + 27fc73f commit c4a252e
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 104 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [4.1.1] - 2021-02-17
### Fixed
- Included more detail in sync error messages
- Demoted "lacked an email address" log messages from warning to info level

## [4.1.0] - 2021-02-10
### Added
- Added `queryConditions` config variable on Sage People component
Expand Down Expand Up @@ -195,7 +200,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- First release.

[Unreleased]: https://github.com/silinternational/idp-id-sync/compare/4.1.0...develop
[Unreleased]: https://github.com/silinternational/idp-id-sync/compare/4.1.1...develop
[4.1.1]: https://github.com/silinternational/idp-id-sync/compare/4.1.0...4.1.1
[4.1.0]: https://github.com/silinternational/idp-id-sync/compare/4.0.5...4.1.0
[4.0.5]: https://github.com/silinternational/idp-id-sync/compare/4.0.2...4.0.5
[4.0.2]: https://github.com/silinternational/idp-id-sync/compare/4.0.1...4.0.2
Expand Down
60 changes: 37 additions & 23 deletions application/common/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class User
* @var array<string,mixed>
*/
private $values = [];

/**
* Create a new User model from the given user info, which must be an
* associative array with keys matching this class's constants and which
Expand All @@ -37,20 +37,20 @@ public function __construct($userInfo = [])
if (empty($userInfo[self::EMPLOYEE_ID])) {
throw new InvalidArgumentException('Employee ID cannot be empty.', 1493733219);
}

// Set all of the provided fields, taking whatever value was given.
foreach (self::getAllFieldNames() as $fieldName) {
if (array_key_exists($fieldName, $userInfo)) {
$this->values[$fieldName] = $userInfo[$fieldName];
}
}

// Ensure fields with stricter constraints have valid values.
$this->values[self::EMPLOYEE_ID] = (string)$userInfo[self::EMPLOYEE_ID];
$this->setLocked($userInfo[self::LOCKED] ?? null);
$this->setRequireMfa($userInfo[self::REQUIRE_MFA] ?? null);
}

/**
* Get the list of all of the field names supported by this User model.
*
Expand All @@ -73,87 +73,87 @@ public static function getAllFieldNames()
self::USERNAME,
];
}

/**
* @return string
*/
public function getEmployeeId()
{
return $this->values[self::EMPLOYEE_ID];
}

/**
* @return null|string
*/
public function getFirstName()
{
return $this->values[self::FIRST_NAME] ?? null;
}

/**
* @return null|string
*/
public function getLastName()
{
return $this->values[self::LAST_NAME] ?? null;
}

/**
* @return null|string
*/
public function getDisplayName()
{
return $this->values[self::DISPLAY_NAME] ?? null;
}

/**
* @return null|string
*/
public function getUsername()
{
return $this->values[self::USERNAME] ?? null;
}

/**
* @return null|string
*/
public function getEmail()
{
return $this->values[self::EMAIL] ?? null;
}

/**
* @return null|string
*/
public function getActive()
{
return $this->values[self::ACTIVE] ?? null;
}

/**
* @return null|string
*/
public function getLocked()
{
return $this->values[self::LOCKED] ?? null;
}

/**
* @return null|string
*/
public function getManagerEmail()
{
return $this->values[self::MANAGER_EMAIL] ?? null;
}

/**
* @return null|string
*/
public function getRequireMfa()
{
return $this->values[self::REQUIRE_MFA] ?? null;
}

/**
* @return null|string
*/
Expand All @@ -170,42 +170,56 @@ public function getGroups()
return $this->values[self::GROUPS] ?? null;
}

/**
* @return string
*/
public function getStringForLogMessage()
{
return sprintf(
'ID: "%s" username: "%s" email: "%s"',
// use var_export so null becomes "NULL"
var_export($this->getEmployeeId(), true),
var_export($this->getUsername(), true),
var_export($this->getEmail(), true)
);
}

public function __toString()
{
return \json_encode($this->toArray(), JSON_PRETTY_PRINT);
}

protected function isAffirmative($value)
{
if ($value === null) {
return false;
} elseif (is_bool($value)) {
return $value;
}

$lowercasedValue = strtolower(trim($value));

return in_array($lowercasedValue, ['true', 'yes', '1'], true);
}

protected function setLocked($input)
{
if ($input === null) {
return;
}

$this->values[self::LOCKED] = $this->isAffirmative($input) ? 'yes' : 'no';
}

protected function setRequireMfa($input)
{
if ($input === null) {
return;
}

$this->values[self::REQUIRE_MFA] = $this->isAffirmative($input) ? 'yes' : 'no';
}

/**
* Get this User object's data as an associative array.
*
Expand Down
Loading

0 comments on commit c4a252e

Please sign in to comment.