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

Removing Lockdown-Accounts from import #4

Open
wants to merge 2 commits into
base: ilias7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions classes/communication/interface_models/EventoUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class EventoUser extends ApiDataModelBase
const JSON_EMAIL_2 = 'email2';
const JSON_EMAIL_3 = 'email3';
const JSON_ROLES = 'roles';
const JSON_IS_LOCKDOWN_ACCOUNT = 'isLockdownAccount';

private ?int $evento_id;
private ?string $last_name;
Expand All @@ -21,6 +22,7 @@ class EventoUser extends ApiDataModelBase
private ?string $login_name;
private ?array $email_list;
private ?array $roles;
private ?bool $is_lockdown_account;

public function __construct(array $data_set)
{
Expand All @@ -31,6 +33,7 @@ public function __construct(array $data_set)
$this->login_name = $this->validateAndReturnString($data_set, self::JSON_LOGIN_NAME);
$this->email_list = $this->validateCombineAndReturnListOfNonEmptyStrings($data_set, [self::JSON_EMAIL, self::JSON_EMAIL_2, self::JSON_EMAIL_3], false);
$this->roles = $this->validateAndReturnArray($data_set, self::JSON_ROLES);
$this->is_lockdown_account = $this->validateAndReturnBoolean($data_set, self::JSON_IS_LOCKDOWN_ACCOUNT, false, false) ?? false;

$this->decoded_api_data = $data_set;
$this->checkErrorsAndMaybeThrowException();
Expand Down Expand Up @@ -71,6 +74,11 @@ public function getRoles() : array
return $this->roles;
}

public function isLockdownAccount() : bool
{
return $this->is_lockdown_account;
}

public function getDecodedApiData() : array
{
return $this->decoded_api_data;
Expand Down
12 changes: 4 additions & 8 deletions classes/communication/interface_models/JSONDataValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,12 @@ protected function validateAndReturnString(array $data_array, string $key) : ?st
return $data_array[$key];
}

/**
* @param array $data_array
* @param string $key
* @param bool $as_string_possible
* @return bool|null
*/
protected function validateAndReturnBoolean(array $data_array, string $key, bool $as_string_possible = false) : ?bool
protected function validateAndReturnBoolean(array $data_array, string $key, bool $as_string_possible = false, bool $is_mandatory = true) : ?bool
{
if (!isset($data_array[$key])) {
$this->key_errors[$key] = 'Value not set';
if ($is_mandatory) {
$this->key_errors[$key] = 'Value not set';
}
return null;
}

Expand Down
4 changes: 4 additions & 0 deletions classes/import/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ class Logger
const CREVENTO_USR_UPDATED = 302;
const CREVENTO_USR_RENAMED = 303;
const CREVENTO_USR_CONVERTED = 304;
const CREVENTO_USR_LOCKDOWN = 305;


const CREVENTO_USR_NOTICE_CONFLICT = 313;

const CREVENTO_USR_ERROR_ERROR = 324;

const TABLE_LOG_USERS = 'crevento_log_users';
Expand Down
25 changes: 23 additions & 2 deletions classes/import/UserImportTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ private function importNextUserPage() : void
try {
$evento_user = new EventoUser($data_set);

$action = $this->user_import_action_decider->determineImportAction($evento_user);
$action->executeAction();
if ($evento_user->isLockdownAccount()) {
$this->handleDeliveredLockdownAccount($evento_user);
} else {
$action = $this->user_import_action_decider->determineImportAction($evento_user);
$action->executeAction();
}
} catch (\ilEventoImportApiDataException $e) {
$data = $e->getApiData();
if (isset($data[EventoUser::JSON_ID])) {
Expand All @@ -88,6 +92,23 @@ private function importNextUserPage() : void
}
}

private function handleDeliveredLockdownAccount(EventoUser $evento_user)
{
$ilias_user_id = $this->evento_user_repo->getIliasUserIdByEventoId($evento_user->getEventoId());
$this->evento_user_repo->deleteEventoIliasUserConnectionByEventoId($evento_user->getEventoId());

if (!is_null($ilias_user_id)) {
$ilias_user_obj = $this->ilias_user_service->getExistingIliasUserObjectById($ilias_user_id);
$this->ilias_user_service->deactivateUserAccount($ilias_user_obj);
}
$this->evento_logger->logUserImport(
Logger::CREVENTO_USR_LOCKDOWN,
$evento_user->getEventoId(),
$evento_user->getLoginName(),
['api_data' => $evento_user->getDecodedApiData()]
);
}

/**
* User accounts which are deleted by evento should either be converted to a local account (students) or deactivate (staff)
* Since there is no "getDeletedAccounts"-Method anymore, this Plugin has to find those "not anymore imported"-users
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,17 @@ private function setUserTimeLimitsBelowThresholdToGivenValue(int $min_threshold_
. " WHERE DATEDIFF(FROM_UNIXTIME(time_limit_until),create_date)< " . $this->db->quote($min_threshold_in_days, \ilDBConstants::T_INTEGER);
$this->db->manipulate($q);
}

public function deactivateUserAccount(\ilObjUser $ilias_user)
{
// Deassign user from HSLU roles
foreach ($this->user_settings->getEventoCodeToIliasRoleMapping() as $evento_role_code => $ilias_role_id) {
$this->deassignUserFromRole($ilias_user->getId, $ilias_role_id);
}

// Set user auth mode to default (local auth) and set expiration date to now
$ilias_user->setAuthMode('local');
$ilias_user->setTimeLimitUntil($this->user_settings->getNow()->getTimestamp()); // Set user expiration date to now
$ilias_user->update();
}
}