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

[5.3][com_actionlogs] exclude self from mail notification #44640

Open
wants to merge 11 commits into
base: 5.3-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ protected function sendNotificationEmails($messages, $username, $context)
'INNER',
$db->quoteName('#__action_logs_users', 'l') . ' ON ( ' . $db->quoteName('l.notify') . ' = 1 AND '
. $db->quoteName('l.user_id') . ' = ' . $db->quoteName('u.id') . ')'
);
)
->where($db->quoteName('l.exclude_self') . ' = 0');

$db->setQuery($query);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `#__action_logs_users` ADD COLUMN `exclude_self` tinyint NOT NULL DEFAULT 0;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "#__action_logs_users" ADD COLUMN "exclude_self" integer DEFAULT 0 NOT NULL;
1 change: 1 addition & 0 deletions administrator/language/en-GB/plg_system_actionlogs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ PLG_SYSTEM_ACTIONLOGS_INFO_LABEL="Information"
PLG_SYSTEM_ACTIONLOGS_JOOMLA_ACTIONLOG_DISABLED="Action Log - Joomla"
PLG_SYSTEM_ACTIONLOGS_JOOMLA_ACTIONLOG_DISABLED_REDIRECT="The %s plugin is disabled."
PLG_SYSTEM_ACTIONLOGS_NOTIFICATIONS="Email Notifications"
PLG_SYSTEM_ACTIONLOGS_NOTIFICATIONS_EXCLUDE="Exclude Self"
PLG_SYSTEM_ACTIONLOGS_OPTIONS="User Actions Log Options"
PLG_SYSTEM_ACTIONLOGS_XML_DESCRIPTION="Records the actions of users on the site so they can be reviewed if required."
; Common content type log messages
Expand Down
1 change: 1 addition & 0 deletions installation/sql/mysql/extensions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ CREATE TABLE IF NOT EXISTS `#__action_logs_users` (
`user_id` int UNSIGNED NOT NULL,
`notify` tinyint UNSIGNED NOT NULL,
`extensions` text NOT NULL,
`exclude_self` tinyint UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (`user_id`),
KEY `idx_notify` (`notify`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;
Expand Down
1 change: 1 addition & 0 deletions installation/sql/postgresql/extensions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ CREATE TABLE "#__action_logs_users" (
"user_id" integer NOT NULL,
"notify" integer NOT NULL,
"extensions" text NOT NULL,
"exclude_self" integer NOT NULL DEFAULT 0,
PRIMARY KEY ("user_id")
);

Expand Down
13 changes: 13 additions & 0 deletions plugins/system/actionlogs/forms/actionlogs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@
showon="actionlogsNotify:1"
default="com_content"
/>
<field
name="actionlogsExcludeSelf"
type="radio"
label="PLG_SYSTEM_ACTIONLOGS_NOTIFICATIONS_EXCLUDE"
layout="joomla.form.field.radio.switcher"
showon="actionlogsNotify:1"
default="0"
filter="integer"
required="true"
alikon marked this conversation as resolved.
Show resolved Hide resolved
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
</fields>
</fieldset>
</form>
43 changes: 34 additions & 9 deletions plugins/system/actionlogs/src/Extension/ActionLogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function onContentPrepareData($context, $data)
$id = (int) $data->id;

$query = $db->getQuery(true)
->select($db->quoteName(['notify', 'extensions']))
->select($db->quoteName(['notify', 'extensions', 'exclude_self']))
->from($db->quoteName('#__action_logs_users'))
->where($db->quoteName('user_id') . ' = :userid')
->bind(':userid', $id, ParameterType::INTEGER);
Expand All @@ -169,9 +169,10 @@ public function onContentPrepareData($context, $data)
// Load plugin language files.
$this->loadLanguage();

$data->actionlogs = new \stdClass();
$data->actionlogs->actionlogsNotify = $values->notify;
$data->actionlogs->actionlogsExtensions = $values->extensions;
$data->actionlogs = new \stdClass();
$data->actionlogs->actionlogsNotify = $values->notify;
$data->actionlogs->actionlogsExtensions = $values->extensions;
$data->actionlogs->actionlogsExcludeSelf = $values->exclude_self;

if (!HTMLHelper::isRegistered('users.actionlogsNotify')) {
HTMLHelper::register('users.actionlogsNotify', [__CLASS__, 'renderActionlogsNotify']);
Expand All @@ -181,6 +182,10 @@ public function onContentPrepareData($context, $data)
HTMLHelper::register('users.actionlogsExtensions', [__CLASS__, 'renderActionlogsExtensions']);
}

if (!HTMLHelper::isRegistered('users.actionlogsExcludeSelf')) {
HTMLHelper::register('users.actionlogsExcludeSelf', [__CLASS__, 'renderActionlogsExcludeSelf']);
}

return true;
}

Expand Down Expand Up @@ -226,10 +231,11 @@ public function onUserAfterSave($user, $isNew, $success, $msg): void

// If preferences don't exist, insert.
if (!$exists && $authorised && isset($user['actionlogs'])) {
$notify = (int) $user['actionlogs']['actionlogsNotify'];
$values = [':userid', ':notify'];
$bind = [$userid, $notify];
$columns = ['user_id', 'notify'];
$notify = (int) $user['actionlogs']['actionlogsNotify'];
$exclude = (int) $user['actionlogs']['actionlogsExcludeSelf'];
$values = [':userid', ':notify', ':exclude'];
$bind = [$userid, $notify, $exclude];
$columns = ['user_id', 'notify', 'exclude_self'];

$query->bind($values, $bind, ParameterType::INTEGER);

Expand All @@ -250,6 +256,11 @@ public function onUserAfterSave($user, $isNew, $success, $msg): void

$query->bind(':notify', $notify, ParameterType::INTEGER);

$exclude = (int) $user['actionlogs']['actionlogsExcludeSelf'];
$values[] = $db->quoteName('exclude_self') . ' = :exclude';

$query->bind(':exclude', $exclude, ParameterType::INTEGER);

if (isset($user['actionlogs']['actionlogsExtensions'])) {
$values[] = $db->quoteName('extensions') . ' = :extension';
$extension = json_encode($user['actionlogs']['actionlogsExtensions']);
Expand Down Expand Up @@ -324,6 +335,20 @@ public static function renderActionlogsNotify($value)
return Text::_($value ? 'JYES' : 'JNO');
}

/**
* Method to render a value.
*
* @param integer|string $value The value (0 or 1).
*
* @return string The rendered value.
*
* @since __DEPLOY_VERSION_
*/
public static function renderActionlogsExcludeSelf($value)
{
return Text::_($value ? 'JYES' : 'JNO');
}

/**
* Method to render a list of extensions.
*
Expand Down Expand Up @@ -373,7 +398,7 @@ public function onExtensionAfterSave($context, $table, $isNew): void
$db = $this->getDatabase();

$query = $db->getQuery(true)
->select($db->quoteName(['user_id', 'notify', 'extensions']))
->select($db->quoteName(['user_id', 'notify', 'extensions', 'exclude_self']))
->from($db->quoteName('#__action_logs_users'));

try {
Expand Down