Skip to content

Commit 196c76c

Browse files
chore: Replace the otlp interface with abstractFactory. Add the user context to the formatters.
1 parent 4bbd5ab commit 196c76c

8 files changed

Lines changed: 328 additions & 84 deletions

app/Audit/ConcreteFormatters/FeaturedSpeakerAuditLogFormatter.php

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
<?php namespace App\Audit\ConcreteFormatters;
1+
<?php
22

3-
use App\Audit\IAuditLogFormatter;
3+
namespace App\Audit\ConcreteFormatters;
4+
5+
/**
6+
* Copyright 2025 OpenStack Foundation
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
**/
17+
18+
use App\Audit\AbstractAuditLogFormatter;
419
use App\Audit\Interfaces\IAuditStrategy;
520
use App\Models\Foundation\Summit\Speakers\FeaturedSpeaker;
621
use Illuminate\Support\Facades\Log;
722

8-
class FeaturedSpeakerAuditLogFormatter implements IAuditLogFormatter
23+
class FeaturedSpeakerAuditLogFormatter extends AbstractAuditLogFormatter
924
{
1025
private string $event_type;
1126

@@ -14,6 +29,23 @@ public function __construct(string $event_type)
1429
$this->event_type = $event_type;
1530
}
1631

32+
private function getUserInfo(): string
33+
{
34+
if (!$this->ctx) {
35+
return 'Unknown (unknown)';
36+
}
37+
38+
$user_name = 'Unknown';
39+
if ($this->ctx->userFirstName || $this->ctx->userLastName) {
40+
$user_name = trim(sprintf("%s %s", $this->ctx->userFirstName ?? '', $this->ctx->userLastName ?? '')) ?: 'Unknown';
41+
} elseif ($this->ctx->userEmail) {
42+
$user_name = $this->ctx->userEmail;
43+
}
44+
45+
$user_id = $this->ctx->userId ?? 'unknown';
46+
return sprintf("%s (%s)", $user_name, $user_id);
47+
}
48+
1749
public function format($subject, array $change_set): ?string
1850
{
1951
if (!$subject instanceof FeaturedSpeaker) {
@@ -22,7 +54,7 @@ public function format($subject, array $change_set): ?string
2254

2355
try {
2456
$speaker = $subject->getSpeaker();
25-
$speaker_email = $speaker ? ($speaker->getEmail() ?? 'unknown@example.com') : 'unknown@example.com';
57+
$speaker_email = $speaker ? ($speaker->getEmail() ?? 'unknown') : 'unknown';
2658
$speaker_name = $speaker ? sprintf("%s %s", $speaker->getFirstName() ?? '', $speaker->getLastName() ?? '') : 'Unknown';
2759
$speaker_name = trim($speaker_name) ?: $speaker_name;
2860
$speaker_id = $speaker ? ($speaker->getId() ?? 'unknown') : 'unknown';
@@ -35,11 +67,12 @@ public function format($subject, array $change_set): ?string
3567
switch ($this->event_type) {
3668
case IAuditStrategy::EVENT_ENTITY_CREATION:
3769
return sprintf(
38-
"Speaker '%s' (%s) added as featured speaker for Summit '%s' with display order %d",
70+
"Speaker '%s' (%s) added as featured speaker for Summit '%s' with display order %d by user %s",
3971
$speaker_name,
4072
$speaker_id,
4173
$summit_name,
42-
$order
74+
$order,
75+
$this->getUserInfo()
4376
);
4477

4578
case IAuditStrategy::EVENT_ENTITY_UPDATE:
@@ -56,18 +89,20 @@ public function format($subject, array $change_set): ?string
5689

5790
$fields_str = !empty($changed_fields) ? implode(', ', $changed_fields) : 'properties';
5891
return sprintf(
59-
"Featured speaker '%s' (%s) updated (%s changed)",
92+
"Featured speaker '%s' (%s) updated (%s changed) by user %s",
6093
$speaker_name,
6194
$speaker_id,
62-
$fields_str
95+
$fields_str,
96+
$this->getUserInfo()
6397
);
6498

6599
case IAuditStrategy::EVENT_ENTITY_DELETION:
66100
return sprintf(
67-
"Speaker '%s' (%s) removed from featured speakers list of Summit '%s'",
101+
"Speaker '%s' (%s) removed from featured speakers list of Summit '%s' by user %s",
68102
$speaker_name,
69103
$speaker_id,
70-
$summit_name
104+
$summit_name,
105+
$this->getUserInfo()
71106
);
72107
}
73108
} catch (\Exception $ex) {

app/Audit/ConcreteFormatters/PresentationSpeakerAuditLogFormatter.php

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
<?php namespace App\Audit\ConcreteFormatters;
1+
<?php
22

3-
use App\Audit\IAuditLogFormatter;
3+
namespace App\Audit\ConcreteFormatters;
4+
5+
/**
6+
* Copyright 2025 OpenStack Foundation
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
**/
17+
18+
use App\Audit\AbstractAuditLogFormatter;
419
use App\Audit\Interfaces\IAuditStrategy;
520
use models\summit\PresentationSpeaker;
621
use Illuminate\Support\Facades\Log;
722

8-
class PresentationSpeakerAuditLogFormatter implements IAuditLogFormatter
23+
class PresentationSpeakerAuditLogFormatter extends AbstractAuditLogFormatter
924
{
1025
private string $event_type;
1126

@@ -14,6 +29,23 @@ public function __construct(string $event_type)
1429
$this->event_type = $event_type;
1530
}
1631

32+
private function getUserInfo(): string
33+
{
34+
if (!$this->ctx) {
35+
return 'Unknown (unknown)';
36+
}
37+
38+
$user_name = 'Unknown';
39+
if ($this->ctx->userFirstName || $this->ctx->userLastName) {
40+
$user_name = trim(sprintf("%s %s", $this->ctx->userFirstName ?? '', $this->ctx->userLastName ?? '')) ?: 'Unknown';
41+
} elseif ($this->ctx->userEmail) {
42+
$user_name = $this->ctx->userEmail;
43+
}
44+
45+
$user_id = $this->ctx->userId ?? 'unknown';
46+
return sprintf("%s (%s)", $user_name, $user_id);
47+
}
48+
1749
public function format($subject, array $change_set): ?string
1850
{
1951
if (!$subject instanceof PresentationSpeaker) {
@@ -22,18 +54,19 @@ public function format($subject, array $change_set): ?string
2254

2355
try {
2456
$full_name = sprintf("%s %s", $subject->getFirstName() ?? 'Unknown', $subject->getLastName() ?? 'Unknown');
25-
$email = $subject->getEmail() ?? 'unknown@example.com';
57+
$email = $subject->getEmail() ?? 'unknown';
2658
$speaker_id = $subject->getId() ?? 'unknown';
2759

2860
switch ($this->event_type) {
2961
case IAuditStrategy::EVENT_ENTITY_CREATION:
3062
$bio = $subject->getBio() ? sprintf(" - Bio: %s", mb_substr($subject->getBio(), 0, 50)) : '';
3163
return sprintf(
32-
"Speaker '%s' (%s) created with email '%s'%s",
64+
"Speaker '%s' (%s) created with email '%s'%s by user %s",
3365
$full_name,
3466
$speaker_id,
3567
$email,
36-
$bio
68+
$bio,
69+
$this->getUserInfo()
3770
);
3871

3972
case IAuditStrategy::EVENT_ENTITY_UPDATE:
@@ -66,18 +99,20 @@ public function format($subject, array $change_set): ?string
6699

67100
$fields_str = !empty($changed_fields) ? implode(', ', $changed_fields) : 'properties';
68101
return sprintf(
69-
"Speaker '%s' (%s) updated (%s changed)",
102+
"Speaker '%s' (%s) updated (%s changed) by user %s",
70103
$full_name,
71104
$speaker_id,
72-
$fields_str
105+
$fields_str,
106+
$this->getUserInfo()
73107
);
74108

75109
case IAuditStrategy::EVENT_ENTITY_DELETION:
76110
return sprintf(
77-
"Speaker '%s' (%s) with email '%s' was deleted",
111+
"Speaker '%s' (%s) with email '%s' was deleted by user %s",
78112
$full_name,
79113
$speaker_id,
80-
$email
114+
$email,
115+
$this->getUserInfo()
81116
);
82117
}
83118
} catch (\Exception $ex) {

app/Audit/ConcreteFormatters/PresentationSubmissionAuditLogFormatter.php

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
<?php namespace App\Audit\ConcreteFormatters;
1+
<?php
22

3-
use App\Audit\IAuditLogFormatter;
3+
namespace App\Audit\ConcreteFormatters;
4+
5+
/**
6+
* Copyright 2025 OpenStack Foundation
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
**/
17+
18+
use App\Audit\AbstractAuditLogFormatter;
419
use App\Audit\Interfaces\IAuditStrategy;
520
use models\summit\Presentation;
621
use Illuminate\Support\Facades\Log;
722

8-
class PresentationSubmissionAuditLogFormatter implements IAuditLogFormatter
23+
class PresentationSubmissionAuditLogFormatter extends AbstractAuditLogFormatter
924
{
1025
private string $event_type;
1126

@@ -14,6 +29,23 @@ public function __construct(string $event_type)
1429
$this->event_type = $event_type;
1530
}
1631

32+
private function getUserInfo(): string
33+
{
34+
if (!$this->ctx) {
35+
return 'Unknown (unknown)';
36+
}
37+
38+
$user_name = 'Unknown';
39+
if ($this->ctx->userFirstName || $this->ctx->userLastName) {
40+
$user_name = trim(sprintf("%s %s", $this->ctx->userFirstName ?? '', $this->ctx->userLastName ?? '')) ?: 'Unknown';
41+
} elseif ($this->ctx->userEmail) {
42+
$user_name = $this->ctx->userEmail;
43+
}
44+
45+
$user_id = $this->ctx->userId ?? 'unknown';
46+
return sprintf("%s (%s)", $user_name, $user_id);
47+
}
48+
1749
public function format($subject, array $change_set): ?string
1850
{
1951
if (!$subject instanceof Presentation) {
@@ -34,12 +66,13 @@ public function format($subject, array $change_set): ?string
3466
switch ($this->event_type) {
3567
case IAuditStrategy::EVENT_ENTITY_CREATION:
3668
return sprintf(
37-
"Presentation '%s' (%d) submitted by '%s' to track '%s' (Plan: %s)",
69+
"Presentation '%s' (%d) submitted by '%s' to track '%s' (Plan: %s) by user %s",
3870
$title,
3971
$id,
4072
$creator_name,
4173
$category_name,
42-
$plan_name
74+
$plan_name,
75+
$this->getUserInfo()
4376
);
4477

4578
case IAuditStrategy::EVENT_ENTITY_UPDATE:
@@ -79,29 +112,32 @@ public function format($subject, array $change_set): ?string
79112

80113
if ($old_status && $new_status) {
81114
return sprintf(
82-
"Presentation '%s' (%d) status changed: %s → %s (%s changed)",
115+
"Presentation '%s' (%d) status changed: %s → %s (%s changed) by user %s",
83116
$title,
84117
$id,
85118
strtoupper($old_status),
86119
strtoupper($new_status),
87-
$fields_str
120+
$fields_str,
121+
$this->getUserInfo()
88122
);
89123
}
90124

91125
return sprintf(
92-
"Presentation '%s' (%d) updated (%s changed)",
126+
"Presentation '%s' (%d) updated (%s changed) by user %s",
93127
$title,
94128
$id,
95-
$fields_str
129+
$fields_str,
130+
$this->getUserInfo()
96131
);
97132

98133
case IAuditStrategy::EVENT_ENTITY_DELETION:
99134
return sprintf(
100-
"Presentation '%s' (%d) submitted by '%s' to track '%s' was deleted",
135+
"Presentation '%s' (%d) submitted by '%s' to track '%s' was deleted by user %s",
101136
$title,
102137
$id,
103138
$creator_name,
104-
$category_name
139+
$category_name,
140+
$this->getUserInfo()
105141
);
106142
}
107143
} catch (\Exception $ex) {

0 commit comments

Comments
 (0)