Skip to content

Commit 7e917ca

Browse files
committed
User: Prepare the addition of the "predeleted" active state of users - refs #5097
1 parent aaa5ed7 commit 7e917ca

File tree

7 files changed

+27
-7
lines changed

7 files changed

+27
-7
lines changed

public/main/inc/lib/api.lib.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
define('LOG_MESSAGE_DELETE', 'msg_deleted');
200200

201201
define('LOG_USER_DELETE', 'user_deleted');
202+
define('LOG_USER_PREDELETE', 'user_predeleted');
202203
define('LOG_USER_CREATE', 'user_created');
203204
define('LOG_USER_UPDATE', 'user_updated');
204205
define('LOG_USER_PASSWORD_UPDATE', 'user_password_updated');
@@ -1620,7 +1621,7 @@ function api_get_user_info_from_entity(
16201621
$result['phone'] = $user->getPhone();
16211622
$result['address'] = $user->getAddress();
16221623
$result['official_code'] = $user->getOfficialCode();
1623-
$result['active'] = $user->getActive();
1624+
$result['active'] = $user->isActive();
16241625
$result['auth_source'] = $user->getAuthSource();
16251626
$result['language'] = $user->getLocale();
16261627
$result['creator_id'] = $user->getCreatorId();

public/main/inc/lib/message.lib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public static function send_message(
158158
}
159159

160160
// Disabling messages for inactive users.
161-
if (!$userRecipient->getActive()) {
161+
if (!$userRecipient->isActive()) {
162162
return false;
163163
}
164164

public/main/inc/lib/usermanager.lib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ public static function update_user(
10471047
}
10481048

10491049
$change_active = 0;
1050-
$isUserActive = $user->getActive();
1050+
$isUserActive = $user->isActive();
10511051
if ($isUserActive != $active) {
10521052
$change_active = 1;
10531053
}

public/main/inc/lib/webservices/Rest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,17 @@ public function updateUserFromUserName($parameters)
19031903
// see UserManager::update_user() usermanager.lib.php:1205
19041904
if ($user->getActive() != $value) {
19051905
$user->setActive($value);
1906-
Event::addEvent($value ? LOG_USER_ENABLE : LOG_USER_DISABLE, LOG_USER_ID, $userId);
1906+
switch ($value) {
1907+
case 1:
1908+
Event::addEvent(LOG_USER_ENABLE, LOG_USER_ID, $userId);
1909+
break;
1910+
case 0:
1911+
Event::addEvent(LOG_USER_DISABLE, LOG_USER_ID, $userId);
1912+
break;
1913+
case -1:
1914+
Event::addEvent(LOG_USER_PREDELETE, LOG_USER_ID, $userId);
1915+
break;
1916+
}
19071917
}
19081918
break;
19091919
case 'openid':

public/main/webservices/cm_webservice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function verifyUserPass($username, $pass)
135135
// Check the user's password
136136
if ($passwordEncoded == $uData->getPassword() && (trim($login) == $uData->getUsername())) {
137137
// Check if the account is active (not locked)
138-
if ($uData->getActive()) {
138+
if ($uData->isActive()) {
139139
// Check if the expiration date has not been reached
140140
$now = new DateTime();
141141
if ($uData->getExpirationDate() > $now || !$uData->getExpirationDate()) {

src/CoreBundle/Entity/User.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,9 +935,18 @@ public function setCurriculumItems(array $items): self
935935
936936
return $this;
937937
}*/
938+
939+
/**
940+
* Get a bool on whether the user is active or not. Active can be "-1" which means pre-deleted, and is returned as false (not active)
941+
* @return bool True if active = 1, false in any other case (0 = inactive, -1 = predeleted)
942+
*/
938943
public function getIsActive(): bool
939944
{
940-
return $this->active;
945+
if ($this->active == 1) {
946+
return true;
947+
} else {
948+
return false;
949+
}
941950
}
942951

943952
public function isEnabled(): bool

src/CoreBundle/EventSubscriber/AnonymousUserSubscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function onKernelRequest(RequestEvent $event): void
7676
'official_code' => $user->getOfficialCode(),
7777
'picture_uri' => $user->getPictureUri(),
7878
'status' => $user->getStatus(),
79-
'active' => $user->getActive(),
79+
'active' => $user->isActive(),
8080
'auth_source' => $user->getAuthSource(),
8181
'theme' => $user->getTheme(),
8282
'language' => $user->getLocale(),

0 commit comments

Comments
 (0)