feat: extended oauth2 user info and refactored authenticator
This commit is contained in:
@@ -16,13 +16,14 @@ class CrmAttributesResponseParser
|
||||
private const BPN_CRM_ID_ADMIN = 1292;
|
||||
private const BPN_CRM_ID_MANAGER = 1293;
|
||||
private const BPN_CRM_ID_TEAMER = 1070;
|
||||
private const BPN_DEFAULT_HOTEL_CODE = 'SSL';
|
||||
|
||||
public function parse(Crawler $result): CrmAttributes
|
||||
{
|
||||
$groups = [];
|
||||
$actions = [];
|
||||
$roles = [];
|
||||
$hotelCode = null;
|
||||
$hotelCodes = [];
|
||||
|
||||
$result
|
||||
->filterXPath('//selektionsmerkmale/selektionsgruppe')
|
||||
@@ -35,7 +36,7 @@ class CrmAttributesResponseParser
|
||||
|
||||
$node
|
||||
->filterXPath('//selektion')
|
||||
->each(function (Crawler $node) use (&$attributes, &$roles, &$hotelCode) {
|
||||
->each(function (Crawler $node) use (&$attributes, &$roles, &$hotelCodes) {
|
||||
$attribute = new CrmSelection();
|
||||
$attribute->id = (int) $node->attr('id');
|
||||
$attribute->label = $node->attr('bezeichnung');
|
||||
@@ -44,10 +45,11 @@ class CrmAttributesResponseParser
|
||||
|
||||
if (1 === preg_match('/^Hausleitung ([A-Z0-9]+)$/', $attribute->label, $matches) && true === $attribute->selected) {
|
||||
$roles[] = 'ROLE_HOUSE_MANAGER';
|
||||
$hotelCode = $matches[1];
|
||||
$hotelCodes[] = $matches[1];
|
||||
}
|
||||
if (static::BPN_CRM_ID_ADMIN === $attribute->id && true === $attribute->selected) {
|
||||
$roles[] = 'ROLE_ADMIN';
|
||||
$roles[] = 'ROLE_HOUSE_MANAGER';
|
||||
}
|
||||
if (static::BPN_CRM_ID_MANAGER === $attribute->id && true === $attribute->selected) {
|
||||
$roles[] = 'ROLE_MANAGER';
|
||||
@@ -65,6 +67,13 @@ class CrmAttributesResponseParser
|
||||
})
|
||||
;
|
||||
|
||||
$roles = array_unique($roles);
|
||||
|
||||
// Assign default role if none could be resolved
|
||||
if (0 === count($roles)) {
|
||||
$roles = ['ROLE_CUSTOMER'];
|
||||
}
|
||||
|
||||
$result
|
||||
->filterXPath('//crmaktionen/crmaktion')
|
||||
->each(function (Crawler $node) use (&$actions) {
|
||||
@@ -80,15 +89,15 @@ class CrmAttributesResponseParser
|
||||
})
|
||||
;
|
||||
|
||||
if (true === in_array('ROLE_ADMIN', $roles, true)) {
|
||||
$hotelCodes[] = static::BPN_DEFAULT_HOTEL_CODE;
|
||||
}
|
||||
|
||||
$response = new CrmAttributes();
|
||||
$response->selectionGroups = $groups;
|
||||
$response->crmActions = $actions;
|
||||
$response->roles = $roles;
|
||||
$response->admin = in_array('ROLE_ADMIN', $roles);
|
||||
$response->manager = in_array('ROLE_MANAGER', $roles);
|
||||
$response->houseManager = in_array('ROLE_HOUSE_MANAGER', $roles);
|
||||
$response->teamer = in_array('ROLE_TEAMER', $roles);
|
||||
$response->hotelCode = $hotelCode;
|
||||
$response->hotelCodes = $hotelCodes;
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user