Skip to content

Commit ffe4011

Browse files
chore: replace the otlp interface with abstractFactory
feat: add the user context to the formatters
1 parent 5aa92b4 commit ffe4011

3 files changed

Lines changed: 133 additions & 28 deletions

File tree

app/Audit/ConcreteFormatters/PresentationTrackChairRatingTypeAuditLogFormatter.php

Lines changed: 44 additions & 9 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\Events\Presentations\TrackChairs\PresentationTrackChairRatingType;
621
use Illuminate\Support\Facades\Log;
722

8-
class PresentationTrackChairRatingTypeAuditLogFormatter implements IAuditLogFormatter
23+
class PresentationTrackChairRatingTypeAuditLogFormatter 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 PresentationTrackChairRatingType) {
@@ -28,9 +60,10 @@ public function format($subject, array $change_set): ?string
2860
switch ($this->event_type) {
2961
case IAuditStrategy::EVENT_ENTITY_CREATION:
3062
return sprintf(
31-
"Track Chair Rating Type '%s' created for Selection Plan '%s'",
63+
"Track Chair Rating Type '%s' created for Selection Plan '%s' by user %s",
3264
$name,
33-
$plan_name
65+
$plan_name,
66+
$this->getUserInfo()
3467
);
3568

3669
case IAuditStrategy::EVENT_ENTITY_UPDATE:
@@ -41,16 +74,18 @@ public function format($subject, array $change_set): ?string
4174

4275
$fields_str = !empty($changed_fields) ? implode(', ', $changed_fields) : 'properties';
4376
return sprintf(
44-
"Track Chair Rating Type '%s' updated (%s changed)",
77+
"Track Chair Rating Type '%s' updated (%s changed) by user %s",
4578
$name,
46-
$fields_str
79+
$fields_str,
80+
$this->getUserInfo()
4781
);
4882

4983
case IAuditStrategy::EVENT_ENTITY_DELETION:
5084
return sprintf(
51-
"Track Chair Rating Type '%s' deleted from Selection Plan '%s'",
85+
"Track Chair Rating Type '%s' deleted from Selection Plan '%s' by user %s",
5286
$name,
53-
$plan_name
87+
$plan_name,
88+
$this->getUserInfo()
5489
);
5590
}
5691
} catch (\Exception $ex) {

app/Audit/ConcreteFormatters/PresentationTrackChairScoreTypeAuditLogFormatter.php

Lines changed: 44 additions & 9 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\Events\Presentations\TrackChairs\PresentationTrackChairScoreType;
621
use Illuminate\Support\Facades\Log;
722

8-
class PresentationTrackChairScoreTypeAuditLogFormatter implements IAuditLogFormatter
23+
class PresentationTrackChairScoreTypeAuditLogFormatter 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 PresentationTrackChairScoreType) {
@@ -29,10 +61,11 @@ public function format($subject, array $change_set): ?string
2961
switch ($this->event_type) {
3062
case IAuditStrategy::EVENT_ENTITY_CREATION:
3163
return sprintf(
32-
"Score Type '%s' (value: %s) added to Rating Type '%s'",
64+
"Score Type '%s' (value: %s) added to Rating Type '%s' by user %s",
3365
$label,
3466
$score,
35-
$rating_type_name
67+
$rating_type_name,
68+
$this->getUserInfo()
3669
);
3770

3871
case IAuditStrategy::EVENT_ENTITY_UPDATE:
@@ -46,16 +79,18 @@ public function format($subject, array $change_set): ?string
4679

4780
$fields_str = !empty($changed_fields) ? implode(', ', $changed_fields) : 'properties';
4881
return sprintf(
49-
"Score Type '%s' updated (%s changed)",
82+
"Score Type '%s' updated (%s changed) by user %s",
5083
$label,
51-
$fields_str
84+
$fields_str,
85+
$this->getUserInfo()
5286
);
5387

5488
case IAuditStrategy::EVENT_ENTITY_DELETION:
5589
return sprintf(
56-
"Score Type '%s' removed from Rating Type '%s'",
90+
"Score Type '%s' removed from Rating Type '%s' by user %s",
5791
$label,
58-
$rating_type_name
92+
$rating_type_name,
93+
$this->getUserInfo()
5994
);
6095
}
6196
} catch (\Exception $ex) {

app/Audit/ConcreteFormatters/SummitTrackChairAuditLogFormatter.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\SummitTrackChair;
621
use Illuminate\Support\Facades\Log;
722

8-
class SummitTrackChairAuditLogFormatter implements IAuditLogFormatter
23+
class SummitTrackChairAuditLogFormatter 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 SummitTrackChair) {
@@ -33,10 +65,11 @@ public function format($subject, array $change_set): ?string
3365
}
3466
$tracks_list = !empty($categories) ? implode(', ', $categories) : 'No tracks assigned';
3567
return sprintf(
36-
"Track Chair '%s' (%d) assigned with tracks: %s",
68+
"Track Chair '%s' (%d) assigned with tracks: %s by user %s",
3769
$member_name,
3870
$member_id,
39-
$tracks_list
71+
$tracks_list,
72+
$this->getUserInfo()
4073
);
4174

4275
case IAuditStrategy::EVENT_ENTITY_UPDATE:
@@ -55,19 +88,21 @@ public function format($subject, array $change_set): ?string
5588
$new_str = !empty($new_names) ? implode(', ', $new_names) : 'None';
5689

5790
return sprintf(
58-
"Track Chair '%s' tracks changed: [%s] → [%s]",
91+
"Track Chair '%s' tracks changed: [%s] → [%s] by user %s",
5992
$member_name,
6093
$old_str,
61-
$new_str
94+
$new_str,
95+
$this->getUserInfo()
6296
);
6397
}
64-
return sprintf("Track Chair '%s' updated", $member_name);
98+
return sprintf("Track Chair '%s' updated by user %s", $member_name, $this->getUserInfo());
6599

66100
case IAuditStrategy::EVENT_ENTITY_DELETION:
67101
return sprintf(
68-
"Track Chair '%s' (%d) removed from summit",
102+
"Track Chair '%s' (%d) removed from summit by user %s",
69103
$member_name,
70-
$member_id
104+
$member_id,
105+
$this->getUserInfo()
71106
);
72107
}
73108
} catch (\Exception $ex) {

0 commit comments

Comments
 (0)