From ce2ddc553c3e30ffaa62d6e0f2e1220ca7f63f34 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Fri, 9 Nov 2018 17:36:29 +0000 Subject: [PATCH] Fixed populating created_by for user created by admin. --- WEB-INF/lib/ttRegistrator.class.php | 8 +++++--- WEB-INF/templates/footer.tpl | 2 +- admin_group_add.php | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/WEB-INF/lib/ttRegistrator.class.php b/WEB-INF/lib/ttRegistrator.class.php index 44841f50..c206881d 100644 --- a/WEB-INF/lib/ttRegistrator.class.php +++ b/WEB-INF/lib/ttRegistrator.class.php @@ -86,7 +86,7 @@ class ttRegistrator { global $i18n; global $user; - // Protection fom too many recent bot registrations from user IP. + // Protection from too many recent bot registrations from user IP. if (!$user->can('administer_site')) { // No problems for site admin. if ($this->registeredRecently()) { $this->err->add($i18n->get('error.access_denied')); @@ -121,7 +121,9 @@ class ttRegistrator { return false; } - if (!$this->setCreatedBy($this->user_id)) + // Set created_by appropriately (admin or self). + $created_by = $user->can('administer_site') ? $user->id : $this->user_id; + if (!$this->setCreatedBy($created_by)) return false; return true; @@ -189,7 +191,7 @@ class ttRegistrator { } // Update top manager. - $sql = "update tt_users set created_by = $user_id where id = $user_id and group_id = $this->group_id"; + $sql = "update tt_users set created_by = $user_id where id = $this->user_id and group_id = $this->group_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) { $this->err->add($i18n->get('error.db')); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 848425e0..67fbea43 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.12.4396 | Copyright © Anuko | +  Anuko Time Tracker 1.18.12.4397 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/admin_group_add.php b/admin_group_add.php index 21570a96..71dde8a0 100644 --- a/admin_group_add.php +++ b/admin_group_add.php @@ -106,7 +106,8 @@ if ($request->isPost()) { import('ttRegistrator'); $registrator = new ttRegistrator($fields, $err); $registrator->register(); - $registrator->setCreatedBy($user->id); // Override created_by to admin account. + // $registrator->setCreatedBy($user->id); // Override created_by to admin account. + // TODO: redo ttRegistrator class by passing in created_by_id in $fields to keep code straightforward. if ($err->no()) { header('Location: admin_groups.php'); exit(); -- 2.20.1