Skip to content

Commit 47c1a9a

Browse files
alikonHLeithnerrichard67QuyTon
authored
[5] Action Log: Block/Unblock user (#41377)
* log-user-block-unblock * cs * cs * cs * onUserAfterSave * onUserAfterSave * onUserAfterSave * alreadythere * simplify * simplify * cs * add log msg when block/unblock on save * lang * cs * Fix wrong Factory call * Fix system test failing due to Factory call. * Update plugins/actionlog/joomla/src/Extension/Joomla.php Co-authored-by: Quy <[email protected]> * Update plugins/actionlog/joomla/src/Extension/Joomla.php Co-authored-by: Quy <[email protected]> --------- Co-authored-by: Harald Leithner <[email protected]> Co-authored-by: Richard Fath <[email protected]> Co-authored-by: Quy <[email protected]>
1 parent d7a0022 commit 47c1a9a

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

administrator/language/en-GB/plg_actionlog_joomla.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ PLG_ACTIONLOG_JOOMLA_USER_REMIND="User <a href='{accountlink}'>{username}</a> re
5252
PLG_ACTIONLOG_JOOMLA_USER_RESET_COMPLETE="User <a href='{accountlink}'>{username}</a> completed the password reset for their account"
5353
PLG_ACTIONLOG_JOOMLA_USER_RESET_REQUEST="User <a href='{accountlink}'>{username}</a> requested a password reset for their account"
5454
PLG_ACTIONLOG_JOOMLA_USER_UPDATE="User <a href='{accountlink}'>{username}</a> updated Joomla from {oldversion} to {version}"
55+
PLG_ACTIONLOG_JOOMLA_USER_BLOCK="User <a href='{accountlink}'>{username}</a> blocked user <a href='{itemlink}'>{title}</a>"
56+
PLG_ACTIONLOG_JOOMLA_USER_UNBLOCK="User <a href='{accountlink}'>{username}</a> unblocked user <a href='{itemlink}'>{title}</a>"
5557
; Component
5658
PLG_ACTIONLOG_JOOMLA_APPLICATION_CONFIG_UPDATED="User <a href='{accountlink}'>{username}</a> changed settings of the application configuration"
5759
PLG_ACTIONLOG_JOOMLA_COMPONENT_CONFIG_UPDATED="User <a href='{accountlink}'>{username}</a> changed settings of the component {extension_name}"

plugins/actionlog/joomla/src/Extension/Joomla.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,31 @@ public function onUserAfterSave($user, $isnew, $success, $msg): void
619619
'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $userId,
620620
];
621621

622+
// Check if block / unblock comes from Actions on list
623+
if ($task === 'block' || $task === 'unblock') {
624+
$messageLanguageKey = $task === 'block' ? 'PLG_ACTIONLOG_JOOMLA_USER_BLOCK' : 'PLG_ACTIONLOG_JOOMLA_USER_UNBLOCK';
625+
$message['action'] = $task;
626+
}
627+
622628
$this->addLog([$message], $messageLanguageKey, $context, $userId);
629+
630+
// Check if on save a block / unblock has changed
631+
if ($action === 'update') {
632+
$session = $this->getApplication()->getSession();
633+
$data = $session->get('block', null);
634+
635+
if ($data !== null) {
636+
$messageLanguageKey = 'PLG_ACTIONLOG_JOOMLA_USER_UNBLOCK';
637+
$action = 'unblock';
638+
if ($data === 'block') {
639+
$messageLanguageKey = 'PLG_ACTIONLOG_JOOMLA_USER_BLOCK';
640+
$action = 'block';
641+
}
642+
643+
$message['action'] = $action;
644+
$this->addLog([$message], $messageLanguageKey, $context, $userId);
645+
}
646+
}
623647
}
624648

625649
/**
@@ -1183,4 +1207,28 @@ public function onUserAfterResetComplete($user)
11831207

11841208
$this->addLog([$message], 'PLG_ACTIONLOG_JOOMLA_USER_RESET_COMPLETE', $context, $user->id);
11851209
}
1210+
1211+
/**
1212+
* Method is called before user data is stored in the database
1213+
*
1214+
* @param array $user Holds the old user data.
1215+
* @param boolean $isNew True if a new user is stored.
1216+
* @param array $data Holds the new user data.
1217+
*
1218+
* @return void
1219+
*
1220+
* @since __DEPLOY_VERSION__
1221+
*/
1222+
public function onUserBeforeSave($user, $isnew, $new): void
1223+
{
1224+
$session = $this->getApplication()->getSession();
1225+
$session->set('block', null);
1226+
1227+
if ($user['block'] !== (int) $new['block']) {
1228+
$blockunblock = $new['block'] === '1' ? 'block' : 'unblock';
1229+
$session->set('block', $blockunblock);
1230+
}
1231+
1232+
return;
1233+
}
11861234
}

0 commit comments

Comments
 (0)