Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
fb33038
Merge remote-tracking branch 'upstream/4.4-dev' into userdel/4.4-dev
degobbis Mar 24, 2023
dbca089
Add the configuration tab to com_users
degobbis Mar 25, 2023
69206e0
New user plugin for 'Cahneg user before delete'
degobbis Mar 25, 2023
095fc72
Merge remote-tracking branch 'upstream/5.0-dev' into userdel/5.0-dev
degobbis Apr 1, 2023
a7acab6
Remove obsolete file
degobbis Apr 1, 2023
e178ef5
Check if the extension is enabled before loading it.
degobbis Apr 1, 2023
932631c
Add field validation
degobbis Apr 1, 2023
766c8fe
Add as core extension
degobbis Apr 1, 2023
aba38fa
Some error handlings
degobbis Apr 2, 2023
9f993e7
Merge remote-tracking branch 'upstream/5.0-dev' into userdel/5.0-dev
degobbis Apr 2, 2023
61d3458
Merge remote-tracking branch 'upstream/5.0-dev' into userdel/5.0-dev
degobbis May 3, 2023
c48bedb
Merge remote-tracking branch 'joomla/5.0-dev' into userdel/5.0-dev
degobbis Jun 7, 2023
71dcacb
Merge remote-tracking branch 'joomla/5.0-dev' into userdel/5.0-dev
degobbis Jun 9, 2023
2de03e4
Typo
degobbis Jun 10, 2023
6011ca3
Fix - Alias was always entered
degobbis Jun 10, 2023
6485b7b
Added the verification if the fallback user exists any more
degobbis Jun 10, 2023
1dc1f42
Removed some unneeded code and typo
degobbis Jun 10, 2023
ef816a5
Merge remote-tracking branch 'upstream/5.0-dev' into userdel/5.0-dev
degobbis Jun 10, 2023
b4a2e08
Merge remote-tracking branch 'upstream/5.0-dev' into userdel/5.0-dev
degobbis Jun 11, 2023
1bd1ab6
Merge remote-tracking branch 'upstream/5.0-dev' into userdel/5.0-dev
degobbis Jun 11, 2023
5aa2ace
Completely reworked
degobbis Jun 25, 2023
4930cda
Merge remote-tracking branch 'upstream/5.0-dev' into userdel/5.0-dev
degobbis Jun 25, 2023
27c7ffb
Manifest values sorted
degobbis Jun 25, 2023
ebaaba1
Alpha sorted language strings
degobbis Jun 25, 2023
d5de820
Forgot to remove the old plugin entries from the SQL
degobbis Jun 25, 2023
49a5049
Updated every copyright year and unified the headers for the new files
degobbis Jun 25, 2023
800e115
Thx Brianteeman
degobbis Jun 25, 2023
27e0941
Corrections
degobbis Jun 26, 2023
c01f6e8
Corrections and drone fixes
degobbis Jun 26, 2023
2af28ee
typo deposited => inserted
degobbis Jun 26, 2023
2b51826
Fix phpcs
degobbis Jun 26, 2023
fc1ba90
Merge remote-tracking branch 'joomla/5.0-dev' into userdel/5.0-dev
degobbis Jun 26, 2023
dbfe377
Merge remote-tracking branch 'joomla/5.0-dev' into userdel/5.0-dev
degobbis Jun 26, 2023
73b2d6b
Merge branch '5.0-dev' into userdel/5.0-dev
degobbis Jun 26, 2023
d7eebd7
Merge branch '5.0-dev' into userdel/5.0-dev
degobbis Jun 29, 2023
69ea1a1
Merge remote-tracking branch 'upstream/5.0-dev' into userdel/5.0-dev
degobbis Jul 30, 2023
5e0d86b
Merge remote-tracking branch 'upstream/5.0-dev' into userdel/5.0-dev
degobbis Oct 27, 2023
4b24939
Merge remote-tracking branch 'upstream/5.1-dev' into userdel/5.0-dev
degobbis Oct 27, 2023
c710ce1
Merge remote-tracking branch 'upstream/5.1-dev' into userdel/5.0-dev
degobbis Feb 21, 2024
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
39 changes: 39 additions & 0 deletions administrator/components/com_users/forms/before_delete.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fieldset name="before_delete_user"
label="COM_USERS_BEFORE_DELETE_USER">
<field name="fallbackUserIdOnDelete"
type="sql"
label="COM_USERS_BEFORE_DELETE_USER_FIELD_FALLBACK_USER_LABEL"
description="COM_USERS_BEFORE_DELETE_USER_FIELD_FALLBACK_USER_DESC"
default="0"
query="SELECT id, concat( name, ' (', username, ')') AS name FROM #__users"
key_field="id"
value_field="name"
required="true"
>
<option value="">COM_USERS_BEFORE_DELETE_USER_FIELD_FALLBACK_USER_OPTION_EMPTY</option>
</field>
<field name="setAliasOnDelete"
type="radio"
label="COM_USERS_BEFORE_DELETE_USER_FIELD_SET_ALIAS_LABEL"
description="COM_USERS_BEFORE_DELETE_USER_FIELD_SET_ALIAS_DESC"
layout="joomla.form.field.radio.switcher"
default="1"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field name="overrideAliasOnDelete"
type="radio"
label="COM_USERS_BEFORE_DELETE_USER_FIELD_OVERRIDE_ALIAS_LABEL"
description="COM_USERS_BEFORE_DELETE_USER_FIELD_OVERRIDE_ALIAS_DESC"
layout="joomla.form.field.radio.switcher"
default="0"
showon="setAliasOnDelete:1"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
</fieldset>
</form>
100 changes: 100 additions & 0 deletions administrator/components/com_users/src/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
namespace Joomla\Component\Users\Administrator\Controller;

use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Factory;
use Joomla\CMS\Input\Input;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\AdminController;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\Response\JsonResponse;
use Joomla\CMS\Router\Route;
use Joomla\CMS\User\UserFactory;
use Joomla\CMS\User\UserFactoryAwareTrait;
use Joomla\Component\Users\Administrator\Model\UserModel;
use Joomla\Utilities\ArrayHelper;

// phpcs:disable PSR1.Files.SideEffects
Expand All @@ -30,6 +35,8 @@
*/
class UsersController extends AdminController
{
use UserFactoryAwareTrait;

/**
* @var string The prefix to use with controller messages.
* @since 1.6
Expand Down Expand Up @@ -170,4 +177,97 @@ public function getQuickiconContent()

echo new JsonResponse($result);
}

/**
* Removes an item.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function delete()
{
$error = false;

// Check for request forgeries
$this->checkToken();

// Get items to remove from the request.
$cid = (array) $this->input->get('cid', [], 'int');

// Remove zero values resulting from input filter
$cid = array_filter($cid);

if (empty($cid)) {
$this->app->getLogger()->warning(
Text::_($this->text_prefix . '_NO_ITEM_SELECTED'),
['category' => 'jerror']
);

$error = true;
}

$fallbackUserId = (int) $this->input->get('beforeDeleteUser')['fallbackUserIdOnDelete'] ?? 0;
$userFactory = Factory::getContainer()->get(UserFactory::class);
$isUserExists = $fallbackUserId && $userFactory->loadUserById($fallbackUserId)->id === $fallbackUserId;

if (!$error && empty($fallbackUserId)) {
$this->app->getLogger()->error(
Text::_('COM_USERS_BEFORE_DELETE_USER_ERROR_FALLBACK_USER_NOT_SET_MSG'),
['category' => 'jerror']
);

$error = true;
}

if (!$error && in_array($fallbackUserId, $cid)) {
$this->app->getLogger()->error(
Text::_('COM_USERS_BEFORE_DELETE_USER_ERROR_FALLBACK_USER_CONNECTED_MSG'),
['category' => 'jerror']
);

$error = true;
}

if (!$error && !$isUserExists) {
$this->app->getLogger()->error(
Text::sprintf(
'COM_USERS_BEFORE_DELETE_USER_ERROR_FALLBACK_USER_ID_NOT_EXISTS_MSG',
$fallbackUserId,
),
['category' => 'jerror']
);

$error = true;
}

if ($error) {
$this->app->getLogger()->error(
Text::_('COM_USERS_BEFORE_DELETE_USER_ERROR_USER_NOT_DELETED_MSG'),
['category' => 'jerror']
);
} else {
// Get the model.
/** @var UserModel $model */
$model = $this->getModel();

// Remove the items.
if ($model->delete($cid)) {
$this->setMessage(Text::plural($this->text_prefix . '_N_ITEMS_DELETED', \count($cid)));
} else {
$this->setMessage($model->getError(), 'error');
}

// Invoke the postDelete method to allow for the child class to access the model.
$this->postDeleteHook($model, $cid);
}

$this->setRedirect(
Route::_(
'index.php?option=' . $this->option . '&view=' . $this->view_list
. $this->getRedirectToListAppend(),
false
)
);
}
}
19 changes: 13 additions & 6 deletions administrator/components/com_users/src/Model/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Joomla\CMS\User\UserFactoryAwareTrait;
use Joomla\CMS\User\UserHelper;
use Joomla\Database\ParameterType;
use Joomla\Registry\Registry;
use Joomla\Utilities\ArrayHelper;

// phpcs:disable PSR1.Files.SideEffects
Expand Down Expand Up @@ -63,7 +64,7 @@ public function __construct($config = [], MVCFactoryInterface $factory = null)
'event_after_save' => 'onUserAfterSave',
'event_before_delete' => 'onUserBeforeDelete',
'event_before_save' => 'onUserBeforeSave',
'events_map' => ['save' => 'user', 'delete' => 'user', 'validate' => 'user'],
'events_map' => ['save' => 'user', 'beforeDelete' => 'beforedeleteuser', 'delete' => 'user', 'validate' => 'user'],
],
$config
);
Expand Down Expand Up @@ -304,13 +305,16 @@ public function save($data)
*/
public function delete(&$pks)
{
$user = $this->getCurrentUser();
$table = $this->getTable();
$pks = (array) $pks;
$app = Factory::getApplication();
$user = $this->getCurrentUser();
$table = $this->getTable();
$pks = (array) $pks;
$beforeDeleteUserParams = new Registry((array) $app->input->get('beforeDeleteUser'));

// Check if I am a Super Admin
$iAmSuperAdmin = $user->authorise('core.admin');

PluginHelper::importPlugin($this->events_map['beforeDelete']);
PluginHelper::importPlugin($this->events_map['delete']);

if (\in_array($user->id, $pks)) {
Expand All @@ -332,8 +336,11 @@ public function delete(&$pks)
// Get users data for the users to delete.
$user_to_delete = $this->getUserFactory()->loadUserById($pk);

$beforeDeleteUserParams->set('userId', $user_to_delete->id);
$beforeDeleteUserParams->set('userName', $user_to_delete->name);

// Fire the before delete event.
Factory::getApplication()->triggerEvent($this->event_before_delete, [$table->getProperties()]);
$app->triggerEvent($this->event_before_delete, [$table->getProperties(), $beforeDeleteUserParams]);

if (!$table->delete($pk)) {
$this->setError($table->getError());
Expand All @@ -346,7 +353,7 @@ public function delete(&$pks)
} else {
// Prune items that you can't change.
unset($pks[$i]);
Factory::getApplication()->enqueueMessage(Text::_('JERROR_CORE_DELETE_NOT_PERMITTED'), 'error');
$app->enqueueMessage(Text::_('JERROR_CORE_DELETE_NOT_PERMITTED'), 'error');
}
} else {
$this->setError($table->getError());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ protected function addToolbar()
}

if ($canDo->get('core.delete')) {
$childBar->delete('users.delete', 'JTOOLBAR_DELETE')
->message('JGLOBAL_CONFIRM_DELETE')
$childBar->popupButton('delete', 'JTOOLBAR_DELETE')
->selector('beforeDeleteModal')
->icon('icon-delete')
->listCheck(true);
}
}
Expand Down
12 changes: 12 additions & 0 deletions administrator/components/com_users/tmpl/users/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@
) : ?>
<template id="joomla-dialog-batch"><?php echo $this->loadTemplate('batch_body'); ?></template>
<?php endif; ?>
<?php
if ($this->canDo->get('core.delete')) : ?>
<?php echo HTMLHelper::_(
'bootstrap.renderModal',
'beforeDeleteModal',
[
'title' => Text::_('COM_USERS_BEFORE_DELETE_USER'),
'footer' => $this->loadTemplate('before_delete_footer'),
],
$this->loadTemplate('before_delete_body')
); ?>
<?php endif; ?>
<?php endif; ?>

<input type="hidden" name="task" value="">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* @package Joomla.Administrator
* @subpackage com_users
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormFactoryInterface;

/** @var \Joomla\CMS\Form\Form $form */
$form = Factory::getContainer()
->get(FormFactoryInterface::class)
->createForm('beforeDeleteUser', ['control' => 'beforeDeleteUser']);

$form->loadFile('before_delete');

?>

<div class="p-3">
<?php echo $form->renderFieldset('before_delete_user'); ?>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/**
* @package Joomla.Administrator
* @subpackage com_users
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Language\Text;

?>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<?php echo Text::_('JCANCEL'); ?>
</button>
<button type="submit" class="btn btn-success" onclick="Joomla.submitbutton('users.delete');return false;">
<?php echo Text::_('JGLOBAL_BATCH_PROCESS'); ?>
</button>
15 changes: 15 additions & 0 deletions administrator/language/en-GB/com_users.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ COM_USERS_BATCH_DELETE="Delete From Group"
COM_USERS_BATCH_GROUP="Select Group"
COM_USERS_BATCH_OPTIONS="Batch process the selected users"
COM_USERS_BATCH_SET="Move To Group"
COM_USERS_BEFORE_DELETE_USER="Before Delete User"
COM_USERS_BEFORE_DELETE_USER_CHANGED_FALLBACK_ALIAS_MSG="The author alias <code>%s</code> was inserted."
COM_USERS_BEFORE_DELETE_USER_CHANGED_FALLBACK_ALIAS_IF_NOT_EMPTY_MSG="The author alias <code>%s</code> was inserted, if the field was empty before."
COM_USERS_BEFORE_DELETE_USER_DELETED_MSG="%s: for the elements with the ID <code>%s</code>, the old user ID <code>%d</code> has been replaced with the ID <code>%d</code>. %s"
COM_USERS_BEFORE_DELETE_USER_ERROR_FALLBACK_USER_CONNECTED_MSG="You have tried to delete the fallback user. Please select another user as fallback."
COM_USERS_BEFORE_DELETE_USER_ERROR_FALLBACK_USER_ID_NOT_EXISTS_MSG="The fallback user with the ID <code>%d</code> no longer exists. Please select another user as fallback."
COM_USERS_BEFORE_DELETE_USER_ERROR_FALLBACK_USER_NOT_SET_MSG="The fallback user has not been set. Please select a fallback user to process the deleting."
COM_USERS_BEFORE_DELETE_USER_ERROR_USER_NOT_DELETED_MSG="No user was deleted!"
COM_USERS_BEFORE_DELETE_USER_FIELD_FALLBACK_USER_DESC="Select user to be put in place of the deleted user."
COM_USERS_BEFORE_DELETE_USER_FIELD_FALLBACK_USER_LABEL="Fallback User"
COM_USERS_BEFORE_DELETE_USER_FIELD_FALLBACK_USER_OPTION_EMPTY="Select user"
COM_USERS_BEFORE_DELETE_USER_FIELD_OVERRIDE_ALIAS_DESC="Overwrite the content in the 'Author alias' field with the name of the user to be deleted, if this is not empty."
COM_USERS_BEFORE_DELETE_USER_FIELD_OVERRIDE_ALIAS_LABEL="Overwrite Author Alias"
COM_USERS_BEFORE_DELETE_USER_FIELD_SET_ALIAS_DESC="Write the name of the user to be deleted in the 'Author alias' field if it is empty."
COM_USERS_BEFORE_DELETE_USER_FIELD_SET_ALIAS_LABEL="Enter Author Alias"
COM_USERS_CATEGORIES_TITLE="User Notes: Categories"
COM_USERS_CATEGORY_HEADING="Category"
COM_USERS_CONFIGURATION="Users: Options"
Expand Down
7 changes: 7 additions & 0 deletions administrator/language/en-GB/plg_beforedeleteuser_core.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; Joomla! Project
; (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
; License GNU General Public License version 2 or later; see LICENSE.txt
; Note : All ini files need to be saved as UTF-8

PLG_BEFOREDELETEUSER_CORE="Before delete user - Core"
PLG_BEFOREDELETEUSER_CORE_XML_DESCRIPTION="Changes user IDs in core, on deleting user."
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; Joomla! Project
; (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
; License GNU General Public License version 2 or later; see LICENSE.txt
; Note : All ini files need to be saved as UTF-8

PLG_BEFOREDELETEUSER_CORE="Before delete user - Core"
PLG_BEFOREDELETEUSER_CORE_XML_DESCRIPTION="Changes user IDs in core, on deleting user."
1 change: 1 addition & 0 deletions installation/sql/mysql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`,
(0, 'plg_authentication_cookie', 'plugin', 'cookie', 'authentication', 0, 1, 1, 0, 1, '', '', '', 1, 0),
(0, 'plg_authentication_joomla', 'plugin', 'joomla', 'authentication', 0, 1, 1, 1, 1, '', '', '', 2, 0),
(0, 'plg_authentication_ldap', 'plugin', 'ldap', 'authentication', 0, 0, 1, 0, 1, '', '{"host":"","port":"389","use_ldapV3":"0","negotiate_tls":"0","no_referrals":"0","auth_method":"bind","base_dn":"","search_string":"","users_dn":"","username":"admin","password":"bobby7","ldap_fullname":"fullName","ldap_email":"mail","ldap_uid":"uid"}', '', 3, 0),
(0, 'plg_beforedeleteuser_core', 'plugin', 'core', 'beforedeleteuser', 0, 1, 1, 1, 1, '', '', '', 1, 0),
(0, 'plg_behaviour_compat', 'plugin', 'compat', 'behaviour', 0, 1, 1, 0, 1, '', '{"classes_aliases":"1","es5_assets":"1"}', '', 1, 0),
(0, 'plg_behaviour_taggable', 'plugin', 'taggable', 'behaviour', 0, 1, 1, 0, 1, '', '{}', '', 2, 0),
(0, 'plg_behaviour_versionable', 'plugin', 'versionable', 'behaviour', 0, 1, 1, 0, 1, '', '{}', '', 3, 0),
Expand Down
1 change: 1 addition & 0 deletions installation/sql/postgresql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder",
(0, 'plg_authentication_cookie', 'plugin', 'cookie', 'authentication', 0, 1, 1, 0, 1, '', '', '', 1, 0),
(0, 'plg_authentication_joomla', 'plugin', 'joomla', 'authentication', 0, 1, 1, 1, 1, '', '', '', 2, 0),
(0, 'plg_authentication_ldap', 'plugin', 'ldap', 'authentication', 0, 0, 1, 0, 1, '', '{"host":"","port":"389","use_ldapV3":"0","negotiate_tls":"0","no_referrals":"0","auth_method":"bind","base_dn":"","search_string":"","users_dn":"","username":"admin","password":"bobby7","ldap_fullname":"fullName","ldap_email":"mail","ldap_uid":"uid"}', '', 3, 0),
(0, 'plg_beforedeleteuser_core', 'plugin', 'core', 'beforedeleteuser', 0, 1, 1, 1, 1, '', '', '', 1, 0),
(0, 'plg_behaviour_compat', 'plugin', 'compat', 'behaviour', 0, 1, 1, 0, 1, '', '{"classes_aliases":"1","es5_assets":"1"}', '', 1, 0),
(0, 'plg_behaviour_taggable', 'plugin', 'taggable', 'behaviour', 0, 1, 1, 0, 1, '', '{}', '', 2, 0),
(0, 'plg_behaviour_versionable', 'plugin', 'versionable', 'behaviour', 0, 1, 1, 0, 1, '', '{}', '', 3, 0),
Expand Down
3 changes: 3 additions & 0 deletions libraries/src/Extension/ExtensionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ class ExtensionHelper
['plugin', 'joomla', 'authentication', 0],
['plugin', 'ldap', 'authentication', 0],

// Core plugin extensions - beforedeleteuser
['plugin', 'core', 'beforedeleteuser', 0],

// Core plugin extensions - behaviour
['plugin', 'compat', 'behaviour', 0],
['plugin', 'taggable', 'behaviour', 0],
Expand Down
Loading