Skip to content

Commit 389ddae

Browse files
authored
[5.3][com_actionlogs] exclude self from mail notification (#44640)
1 parent 03f5e88 commit 389ddae

File tree

8 files changed

+55
-9
lines changed

8 files changed

+55
-9
lines changed

administrator/components/com_actionlogs/src/Model/ActionlogModel.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected function sendNotificationEmails($messages, $username, $context)
126126
$query = $db->getQuery(true);
127127

128128
$query
129-
->select($db->quoteName(['u.email', 'l.extensions']))
129+
->select($db->quoteName(['u.email', 'u.username', 'l.extensions', 'l.exclude_self']))
130130
->from($db->quoteName('#__users', 'u'))
131131
->where($db->quoteName('u.block') . ' = 0')
132132
->join(
@@ -142,6 +142,10 @@ protected function sendNotificationEmails($messages, $username, $context)
142142
$recipients = [];
143143

144144
foreach ($users as $user) {
145+
if ($user->username === $this->getCurrentUser()->username && $user->exclude_self) {
146+
continue;
147+
}
148+
145149
$extensions = json_decode($user->extensions, true);
146150

147151
if ($extensions && \in_array(strtok($context, '.'), $extensions)) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE `#__action_logs_users` ADD COLUMN `exclude_self` tinyint NOT NULL DEFAULT 0;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "#__action_logs_users" ADD COLUMN "exclude_self" integer DEFAULT 0 NOT NULL;

administrator/language/en-GB/plg_system_actionlogs.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ PLG_SYSTEM_ACTIONLOGS_INFO_LABEL="Information"
1010
PLG_SYSTEM_ACTIONLOGS_JOOMLA_ACTIONLOG_DISABLED="Action Log - Joomla"
1111
PLG_SYSTEM_ACTIONLOGS_JOOMLA_ACTIONLOG_DISABLED_REDIRECT="The %s plugin is disabled."
1212
PLG_SYSTEM_ACTIONLOGS_NOTIFICATIONS="Email Notifications"
13+
PLG_SYSTEM_ACTIONLOGS_NOTIFICATIONS_EXCLUDE="Exclude Self"
1314
PLG_SYSTEM_ACTIONLOGS_OPTIONS="User Actions Log Options"
1415
PLG_SYSTEM_ACTIONLOGS_XML_DESCRIPTION="Records the actions of users on the site so they can be reviewed if required."
1516
; Common content type log messages

installation/sql/mysql/extensions.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@ CREATE TABLE IF NOT EXISTS `#__action_logs_users` (
887887
`user_id` int UNSIGNED NOT NULL,
888888
`notify` tinyint UNSIGNED NOT NULL,
889889
`extensions` text NOT NULL,
890+
`exclude_self` tinyint UNSIGNED NOT NULL DEFAULT 0,
890891
PRIMARY KEY (`user_id`),
891892
KEY `idx_notify` (`notify`)
892893
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;

installation/sql/postgresql/extensions.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ CREATE TABLE "#__action_logs_users" (
848848
"user_id" integer NOT NULL,
849849
"notify" integer NOT NULL,
850850
"extensions" text NOT NULL,
851+
"exclude_self" integer NOT NULL DEFAULT 0,
851852
PRIMARY KEY ("user_id")
852853
);
853854

plugins/system/actionlogs/forms/actionlogs.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@
2424
showon="actionlogsNotify:1"
2525
default="com_content"
2626
/>
27+
<field
28+
name="actionlogsExcludeSelf"
29+
type="radio"
30+
label="PLG_SYSTEM_ACTIONLOGS_NOTIFICATIONS_EXCLUDE"
31+
layout="joomla.form.field.radio.switcher"
32+
showon="actionlogsNotify:1"
33+
default="0"
34+
filter="integer"
35+
>
36+
<option value="0">JNO</option>
37+
<option value="1">JYES</option>
38+
</field>
2739
</fields>
2840
</fieldset>
2941
</form>

plugins/system/actionlogs/src/Extension/ActionLogs.php

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function onContentPrepareData($context, $data)
151151
$id = (int) $data->id;
152152

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

172-
$data->actionlogs = new \stdClass();
173-
$data->actionlogs->actionlogsNotify = $values->notify;
174-
$data->actionlogs->actionlogsExtensions = $values->extensions;
172+
$data->actionlogs = new \stdClass();
173+
$data->actionlogs->actionlogsNotify = $values->notify;
174+
$data->actionlogs->actionlogsExtensions = $values->extensions;
175+
$data->actionlogs->actionlogsExcludeSelf = $values->exclude_self;
175176

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

185+
if (!HTMLHelper::isRegistered('users.actionlogsExcludeSelf')) {
186+
HTMLHelper::register('users.actionlogsExcludeSelf', [__CLASS__, 'renderActionlogsExcludeSelf']);
187+
}
188+
184189
return true;
185190
}
186191

@@ -227,9 +232,10 @@ public function onUserAfterSave($user, $isNew, $success, $msg): void
227232
// If preferences don't exist, insert.
228233
if (!$exists && $authorised && isset($user['actionlogs'])) {
229234
$notify = (int) $user['actionlogs']['actionlogsNotify'];
230-
$values = [':userid', ':notify'];
231-
$bind = [$userid, $notify];
232-
$columns = ['user_id', 'notify'];
235+
$exclude = (int) $user['actionlogs']['actionlogsExcludeSelf'];
236+
$values = [':userid', ':notify', ':exclude'];
237+
$bind = [$userid, $notify, $exclude];
238+
$columns = ['user_id', 'notify', 'exclude_self'];
233239

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

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

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

259+
$exclude = (int) $user['actionlogs']['actionlogsExcludeSelf'];
260+
$values[] = $db->quoteName('exclude_self') . ' = :exclude';
261+
262+
$query->bind(':exclude', $exclude, ParameterType::INTEGER);
263+
253264
if (isset($user['actionlogs']['actionlogsExtensions'])) {
254265
$values[] = $db->quoteName('extensions') . ' = :extension';
255266
$extension = json_encode($user['actionlogs']['actionlogsExtensions']);
@@ -324,6 +335,20 @@ public static function renderActionlogsNotify($value)
324335
return Text::_($value ? 'JYES' : 'JNO');
325336
}
326337

338+
/**
339+
* Method to render a value.
340+
*
341+
* @param integer|string $value The value (0 or 1).
342+
*
343+
* @return string The rendered value.
344+
*
345+
* @since __DEPLOY_VERSION_
346+
*/
347+
public static function renderActionlogsExcludeSelf($value)
348+
{
349+
return Text::_($value ? 'JYES' : 'JNO');
350+
}
351+
327352
/**
328353
* Method to render a list of extensions.
329354
*
@@ -373,7 +398,7 @@ public function onExtensionAfterSave($context, $table, $isNew): void
373398
$db = $this->getDatabase();
374399

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

379404
try {

0 commit comments

Comments
 (0)