From 7137b973736cc4ee935fd3e93c478e162befc639 Mon Sep 17 00:00:00 2001 From: Felix Pahlow <felix.pahlow@itz.uni-halle.de> Date: Sat, 15 Jul 2023 16:16:00 +0000 Subject: [PATCH] Add unlock log action, closes #2903 Closes #2903 Merge request studip/studip!1956 --- db/migrations/5.4.13_add_unlock_action.php | 33 ++++++++++++++++++++++ lib/models/User.class.php | 24 ++++++++++------ 2 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 db/migrations/5.4.13_add_unlock_action.php diff --git a/db/migrations/5.4.13_add_unlock_action.php b/db/migrations/5.4.13_add_unlock_action.php new file mode 100644 index 00000000000..d3834a12d41 --- /dev/null +++ b/db/migrations/5.4.13_add_unlock_action.php @@ -0,0 +1,33 @@ +<?php + +final class AddUnlockAction extends Migration +{ + public function description() + { + return 'add an unlock action'; + } + + public function up() + { + DBManager::get()->exec(" + INSERT IGNORE INTO `log_actions` + SET `action_id` = MD5('USER_UNLOCK'), + `name` = 'USER_UNLOCK', + `description` = 'Nutzer wird entsperrt', + `info_template` = '%user entsperrt %user(%affected) (%info)', + `active` = '1', + `expires` = '0' + "); + } + + public function down() + { + $actions = ['USER_UNLOCK']; + + DBManager::get()->execute( + "DELETE `log_events` FROM `log_events` JOIN `log_actions` USING (`action_id`) WHERE `name` IN (?)", + [$actions] + ); + DBManager::get()->execute("DELETE FROM `log_actions` WHERE `name` IN (?)", [$actions]); + } +} diff --git a/lib/models/User.class.php b/lib/models/User.class.php index 47ad6f63d78..780c7fca9ad 100644 --- a/lib/models/User.class.php +++ b/lib/models/User.class.php @@ -231,15 +231,21 @@ class User extends AuthUserMd5 implements Range, PrivacyObject protected function cbStudipLog($type) { if ($type == 'before_store' && !$this->isNew()) { - if ($this->isFieldDirty('locked') && $this->isFieldDirty('lock_comment') && (int)$this->locked === 1) { - StudipLog::log('USER_LOCK', - $this->user_id, - null, - sprintf( - 'Kommentar: %s', - $this->lock_comment - ) - ); + if ($this->isFieldDirty('locked') && $this->isFieldDirty('lock_comment')) { + if ((int)$this->locked === 1) { + StudipLog::log('USER_LOCK', + $this->user_id, + null, + sprintf( + 'Kommentar: %s', + $this->lock_comment + ) + ); + } else { + StudipLog::log('USER_UNLOCK', + $this->user_id + ); + } } } } -- GitLab