mirror of
https://github.com/OPSnet/Gazelle.git
synced 2026-01-16 18:04:34 -05:00
drop historical user admin comments
This commit is contained in:
@@ -160,7 +160,6 @@ class User extends BaseObject {
|
||||
um.updated,
|
||||
um.Visible,
|
||||
um.ipcc,
|
||||
ui.AdminComment,
|
||||
ui.BanDate,
|
||||
ui.NavItems,
|
||||
ui.RatioWatchEnds,
|
||||
@@ -585,10 +584,6 @@ class User extends BaseObject {
|
||||
return $this->info()['slogan'];
|
||||
}
|
||||
|
||||
public function staffNotes(): string {
|
||||
return $this->info()['AdminComment'] ?? '';
|
||||
}
|
||||
|
||||
public function title(): string {
|
||||
return preg_replace_callback(
|
||||
'/src=("?)(http.+?)(["\s>])/',
|
||||
@@ -1044,7 +1039,7 @@ class User extends BaseObject {
|
||||
$now[] = "{$this->clearField($field)} = now()";
|
||||
}
|
||||
}
|
||||
foreach (['AdminComment', 'BanDate', 'BanReason', 'PermittedForums', 'RestrictedForums', 'RatioWatchDownload', 'RatioWatchEnds'] as $field) {
|
||||
foreach (['BanDate', 'BanReason', 'PermittedForums', 'RestrictedForums', 'RatioWatchDownload', 'RatioWatchEnds'] as $field) {
|
||||
if ($this->field($field) !== null || $this->nullField($field)) {
|
||||
$userInfo["$field = ?"] = $this->clearField($field);
|
||||
}
|
||||
|
||||
@@ -101,41 +101,6 @@ class AuditTrail extends \Gazelle\BaseUser {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate the old users_info.AdminComments to the new audit trail.
|
||||
* Returns 0 if the user has already been migrated, otherwise
|
||||
* returns the id_user_audit_trail value
|
||||
*/
|
||||
public function migrate(\Gazelle\Manager\User $manager): int {
|
||||
if ($this->hasEvent(UserAuditEvent::historical)) {
|
||||
return 0;
|
||||
}
|
||||
$prevDate = false;
|
||||
$lastEvent = 0;
|
||||
// split the legacy staff notes into separate entries
|
||||
$historical = preg_split("/\r?\n\r?\n/", $this->user->staffNotes());
|
||||
if ($historical) {
|
||||
foreach (array_reverse($historical) as $entry) {
|
||||
if (preg_match('/^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) - (.*)/s', $entry, $match)) {
|
||||
$date = $match[1];
|
||||
$note = $match[2];
|
||||
} else {
|
||||
// this note is not prefixed with a timestamp. If this is the
|
||||
// first note, use the date the user was created, otherwise
|
||||
// use the timestamp of the previous event.
|
||||
$date = $prevDate === false ? $this->user->created() : $prevDate;
|
||||
$note = $entry;
|
||||
}
|
||||
$lastEvent = $this->addHistoricalEvent($date, $note, $manager);
|
||||
$prevDate = $date;
|
||||
}
|
||||
}
|
||||
if ($lastEvent === 0) {
|
||||
$lastEvent = $this->addEvent(UserAuditEvent::historical, "no prior staff notes");
|
||||
}
|
||||
return $lastEvent;
|
||||
}
|
||||
|
||||
public function removeEvent(int $eventId): int {
|
||||
return $this->pg()->prepared_query("
|
||||
delete from user_audit_trail
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
use Phinx\Db\Adapter\MysqlAdapter;
|
||||
|
||||
final class DropUserAdminComment extends AbstractMigration {
|
||||
public function up(): void {
|
||||
$this->table('users_info')
|
||||
->removeColumn('AdminComment')
|
||||
->save();
|
||||
}
|
||||
|
||||
public function down(): void {
|
||||
$this->table('users_info')
|
||||
->addColumn('AdminComment', 'text', ['limit' => 65536, 'null' => true])
|
||||
->save();
|
||||
}
|
||||
}
|
||||
@@ -274,11 +274,6 @@ if (empty($_GET)) {
|
||||
$Args[] = trim($_GET['tracker_ip']);
|
||||
}
|
||||
|
||||
if (!empty($_GET['comment'])) {
|
||||
$Where[] = $m->matchField('ui1.AdminComment');
|
||||
$Args[] = $_GET['comment'];
|
||||
}
|
||||
|
||||
if (!empty($_GET['lastfm'])) {
|
||||
$Distinct = true;
|
||||
$Join['lfm'] = 'INNER JOIN lastfm_users AS lfm ON (lfm.ID = um1.ID)';
|
||||
|
||||
@@ -14,7 +14,6 @@ $user = $userMan->findById((int)($_GET['id'] ?? 0));
|
||||
if (is_null($user)) {
|
||||
Error404::error();
|
||||
}
|
||||
$user->auditTrail()->migrate($userMan);
|
||||
|
||||
echo $Twig->render('user/audit.twig', [
|
||||
'edit' => isset($_GET['edit']),
|
||||
|
||||
@@ -594,13 +594,8 @@ if ($editSummary) {
|
||||
if ($reason) {
|
||||
$summary .= "\nReason: $reason";
|
||||
}
|
||||
$user->setField(
|
||||
'AdminComment',
|
||||
Time::sqlTime() . ' - ' . ucfirst($summary) . "\n\n$adminComment"
|
||||
);
|
||||
$user->auditTrail()->addEvent(UserAuditEvent::staffNote, ucfirst($summary), $Viewer);
|
||||
} elseif ($adminComment !== $cur['admincomment']) {
|
||||
$user->setField('AdminComment', $adminComment);
|
||||
$user->auditTrail()->addEvent(UserAuditEvent::staffNote, $adminComment, $Viewer);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,4 @@
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
<div class="head">Historical notes <a href="#" id="historical-notes" class="brackets">View</a></div>
|
||||
<div id="historical-view" class="pad hidden">
|
||||
{{ user.staffNotes|bb_format }}
|
||||
</div>
|
||||
|
||||
{{ footer() }}
|
||||
|
||||
@@ -47,64 +47,26 @@ class UserAuditTrailTest extends TestCase {
|
||||
$this->assertFalse($this->user->auditTrail()->hasEvent(UserAuditEvent::mfa), 'uat-event-absent');
|
||||
}
|
||||
|
||||
public function testAuditTrailMigrate(): void {
|
||||
$this->user = Helper::makeUser('uat.' . randomString(10), 'uat');
|
||||
$staffNoteList = [
|
||||
'2033-03-03 03:03:03 - three',
|
||||
'2022-02-02 02:02:02 - two',
|
||||
'2021-01-01 01:01:01 - one',
|
||||
];
|
||||
$this->user->setField('AdminComment', implode("\n\n", $staffNoteList))->modify();
|
||||
|
||||
$auditTrail = $this->user->auditTrail();
|
||||
$this->assertFalse($this->user->auditTrail()->hasEvent(UserAuditEvent::historical), 'uat-not-yet-migrated');
|
||||
$this->assertGreaterThan(0, $auditTrail->migrate(new \Gazelle\Manager\User()), 'uat-migrate');
|
||||
$this->assertTrue($this->user->auditTrail()->hasEvent(UserAuditEvent::historical), 'uat-migrated');
|
||||
|
||||
$eventList = $auditTrail->fullEventList();
|
||||
$this->assertCount(4, $eventList, 'uat-migrated-event-list');
|
||||
$this->assertEquals('three', $eventList[0]['note'], 'uat-event-list-0-note');
|
||||
$this->assertEquals('two', $eventList[2]['note'], 'uat-event-list-1-note');
|
||||
$this->assertEquals('2022-02-02 02:02:02+00', $eventList[2]['created'], 'uat-event-list-r-created');
|
||||
}
|
||||
|
||||
public function testAuditTrailStaffNote(): void {
|
||||
$this->user = Helper::makeUser('uat.' . randomString(10), 'uat');
|
||||
$auditTrail = $this->user->auditTrail();
|
||||
$this->assertFalse($this->user->auditTrail()->hasEvent(UserAuditEvent::historical), 'uat-not-staff-note-migrated');
|
||||
|
||||
$this->user->addStaffNote('admin comment')->modify();
|
||||
$this->assertGreaterThan(0, $auditTrail->migrate(new \Gazelle\Manager\User()), 'uat-staff-note-migrated');
|
||||
$this->assertEquals(0, $auditTrail->migrate(new \Gazelle\Manager\User()), 'uat-already-migrated');
|
||||
|
||||
// one for the creation, one for the staff note
|
||||
$eventList = $auditTrail->fullEventList();
|
||||
$this->assertCount(3, $eventList, 'uat-migrated-staff-note-list');
|
||||
$this->assertCount(2, $eventList, 'uat-migrated-staff-note-list');
|
||||
$this->assertCount(
|
||||
2,
|
||||
$auditTrail->eventList([
|
||||
$eventList[0]['id_user_audit_trail'],
|
||||
$eventList[1]['id_user_audit_trail'],
|
||||
$eventList[2]['id_user_audit_trail'],
|
||||
]),
|
||||
'uat-partial-event-list'
|
||||
);
|
||||
}
|
||||
|
||||
public function testAuditTrailCreatorStaffNote(): void {
|
||||
$this->user = Helper::makeUser('uat.' . randomString(10), 'uat');
|
||||
$this->admin = Helper::makeUser('uat.adm.' . randomString(10), 'uat');
|
||||
$this->user->auditTrail()->resetAuditTrail();
|
||||
|
||||
$this->user->setField('AdminComment', date('Y-m-d H:m:s') . " - One by {$this->admin->username()}")->modify();
|
||||
$this->assertGreaterThan(0, $this->user->auditTrail()->migrate(new \Gazelle\Manager\User()), 'uat-staff-note-migrated');
|
||||
$this->assertEquals("One.", $this->user->auditTrail()->fullEventList()[0]['note'], 'uat-staff-note-one');
|
||||
|
||||
$this->user->auditTrail()->resetAuditTrail();
|
||||
$this->user->setField('AdminComment', date('Y-m-d H:m:s') . " - Two by {$this->admin->username()}\nReason: Out on the weekend")->modify();
|
||||
$this->assertGreaterThan(0, $this->user->auditTrail()->migrate(new \Gazelle\Manager\User()), 'uat-staff-multinote-migrated');
|
||||
$this->assertEquals("Two.\nReason: Out on the weekend", $this->user->auditTrail()->fullEventList()[0]['note'], 'uat-staff-note-two');
|
||||
}
|
||||
|
||||
public function testAuditTrailModify(): void {
|
||||
$this->user = Helper::makeUser('uat.' . randomString(10), 'uat');
|
||||
$auditTrail = $this->user->auditTrail();
|
||||
|
||||
@@ -222,11 +222,6 @@ class UserTest extends TestCase {
|
||||
'utest-staff-note'
|
||||
);
|
||||
|
||||
$notes = $this->user->staffNotes();
|
||||
$new = "\n" . randomString(20);
|
||||
$this->assertTrue($this->user->setField('AdminComment', $notes . $new)->modify());
|
||||
$this->assertEquals($notes . $new, $this->user->staffNotes());
|
||||
|
||||
$this->assertFalse($this->user->setTitle(str_repeat('x', USER_TITLE_LENGTH + 1)), 'utest-title-too-long');
|
||||
$this->assertTrue($this->user->setTitle('custom title'), 'utest-set-title');
|
||||
$this->user->modify();
|
||||
|
||||
Reference in New Issue
Block a user