Skip to content

Commit e147182

Browse files
feat: add new formatters for badges
1 parent a87252f commit e147182

8 files changed

+885
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace App\Audit\ConcreteFormatters;
4+
5+
/**
6+
* Copyright 2026 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;
19+
use App\Audit\Interfaces\IAuditStrategy;
20+
use models\summit\SummitAccessLevelType;
21+
use Illuminate\Support\Facades\Log;
22+
23+
class SummitAccessLevelTypeAuditLogFormatter extends AbstractAuditLogFormatter
24+
{
25+
public function format($subject, array $change_set): ?string
26+
{
27+
if (!$subject instanceof SummitAccessLevelType) {
28+
return null;
29+
}
30+
31+
try {
32+
$name = $subject->getName() ?? 'Unknown Access Level Type';
33+
$id = $subject->getId() ?? 'unknown';
34+
$summit = $subject->getSummit();
35+
$summit_name = $summit ? ($summit->getName() ?? 'Unknown Summit') : 'Unknown Summit';
36+
37+
switch ($this->event_type) {
38+
case IAuditStrategy::EVENT_ENTITY_CREATION:
39+
return sprintf(
40+
"Access Level Type '%s' (%s) created in Summit '%s' by user %s",
41+
$name,
42+
$id,
43+
$summit_name,
44+
$this->getUserInfo()
45+
);
46+
47+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
48+
$change_details = $this->buildChangeDetails($change_set);
49+
return sprintf(
50+
"Access Level Type '%s' (%s) in Summit '%s' updated: %s by user %s",
51+
$name,
52+
$id,
53+
$summit_name,
54+
$change_details,
55+
$this->getUserInfo()
56+
);
57+
58+
case IAuditStrategy::EVENT_ENTITY_DELETION:
59+
return sprintf(
60+
"Access Level Type '%s' (%s) from Summit '%s' was deleted by user %s",
61+
$name,
62+
$id,
63+
$summit_name,
64+
$this->getUserInfo()
65+
);
66+
}
67+
} catch (\Exception $ex) {
68+
Log::warning("SummitAccessLevelTypeAuditLogFormatter error: " . $ex->getMessage());
69+
}
70+
71+
return null;
72+
}
73+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace App\Audit\ConcreteFormatters;
4+
5+
/**
6+
* Copyright 2026 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;
19+
use App\Audit\Interfaces\IAuditStrategy;
20+
use models\summit\SummitBadgeFeatureType;
21+
use Illuminate\Support\Facades\Log;
22+
23+
class SummitBadgeFeatureTypeAuditLogFormatter extends AbstractAuditLogFormatter
24+
{
25+
public function format($subject, array $change_set): ?string
26+
{
27+
if (!$subject instanceof SummitBadgeFeatureType) {
28+
return null;
29+
}
30+
31+
try {
32+
$name = $subject->getName() ?? 'Unknown Badge Feature Type';
33+
$id = $subject->getId() ?? 'unknown';
34+
$summit = $subject->getSummit();
35+
$summit_name = $summit ? ($summit->getName() ?? 'Unknown Summit') : 'Unknown Summit';
36+
37+
switch ($this->event_type) {
38+
case IAuditStrategy::EVENT_ENTITY_CREATION:
39+
return sprintf(
40+
"Badge Feature Type '%s' (%s) created in Summit '%s' by user %s",
41+
$name,
42+
$id,
43+
$summit_name,
44+
$this->getUserInfo()
45+
);
46+
47+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
48+
$change_details = $this->buildChangeDetails($change_set);
49+
return sprintf(
50+
"Badge Feature Type '%s' (%s) in Summit '%s' updated: %s by user %s",
51+
$name,
52+
$id,
53+
$summit_name,
54+
$change_details,
55+
$this->getUserInfo()
56+
);
57+
58+
case IAuditStrategy::EVENT_ENTITY_DELETION:
59+
return sprintf(
60+
"Badge Feature Type '%s' (%s) from Summit '%s' was deleted by user %s",
61+
$name,
62+
$id,
63+
$summit_name,
64+
$this->getUserInfo()
65+
);
66+
}
67+
} catch (\Exception $ex) {
68+
Log::warning("SummitBadgeFeatureTypeAuditLogFormatter error: " . $ex->getMessage());
69+
}
70+
71+
return null;
72+
}
73+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace App\Audit\ConcreteFormatters;
4+
5+
/**
6+
* Copyright 2026 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;
19+
use App\Audit\Interfaces\IAuditStrategy;
20+
use models\summit\SummitBadgeType;
21+
use Illuminate\Support\Facades\Log;
22+
23+
class SummitBadgeTypeAuditLogFormatter extends AbstractAuditLogFormatter
24+
{
25+
public function format($subject, array $change_set): ?string
26+
{
27+
if (!$subject instanceof SummitBadgeType) {
28+
return null;
29+
}
30+
31+
try {
32+
$name = $subject->getName() ?? 'Unknown Badge Type';
33+
$id = $subject->getId() ?? 'unknown';
34+
$summit = $subject->getSummit();
35+
$summit_name = $summit ? ($summit->getName() ?? 'Unknown Summit') : 'Unknown Summit';
36+
37+
switch ($this->event_type) {
38+
case IAuditStrategy::EVENT_ENTITY_CREATION:
39+
return sprintf(
40+
"Badge Type '%s' (%s) created in Summit '%s' by user %s",
41+
$name,
42+
$id,
43+
$summit_name,
44+
$this->getUserInfo()
45+
);
46+
47+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
48+
$change_details = $this->buildChangeDetails($change_set);
49+
return sprintf(
50+
"Badge Type '%s' (%s) in Summit '%s' updated: %s by user %s",
51+
$name,
52+
$id,
53+
$summit_name,
54+
$change_details,
55+
$this->getUserInfo()
56+
);
57+
58+
case IAuditStrategy::EVENT_ENTITY_DELETION:
59+
return sprintf(
60+
"Badge Type '%s' (%s) from Summit '%s' was deleted by user %s",
61+
$name,
62+
$id,
63+
$summit_name,
64+
$this->getUserInfo()
65+
);
66+
}
67+
} catch (\Exception $ex) {
68+
Log::warning("SummitBadgeTypeAuditLogFormatter error: " . $ex->getMessage());
69+
}
70+
71+
return null;
72+
}
73+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace App\Audit\ConcreteFormatters;
4+
5+
/**
6+
* Copyright 2026 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;
19+
use App\Audit\Interfaces\IAuditStrategy;
20+
use models\summit\SummitBadgeViewType;
21+
use Illuminate\Support\Facades\Log;
22+
23+
class SummitBadgeViewTypeAuditLogFormatter extends AbstractAuditLogFormatter
24+
{
25+
public function format($subject, array $change_set): ?string
26+
{
27+
if (!$subject instanceof SummitBadgeViewType) {
28+
return null;
29+
}
30+
31+
try {
32+
$name = $subject->getName() ?? 'Unknown Badge View Type';
33+
$id = $subject->getId() ?? 'unknown';
34+
$summit = $subject->getSummit();
35+
$summit_name = $summit ? ($summit->getName() ?? 'Unknown Summit') : 'Unknown Summit';
36+
37+
switch ($this->event_type) {
38+
case IAuditStrategy::EVENT_ENTITY_CREATION:
39+
return sprintf(
40+
"Badge View Type '%s' (%s) created in Summit '%s' by user %s",
41+
$name,
42+
$id,
43+
$summit_name,
44+
$this->getUserInfo()
45+
);
46+
47+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
48+
$change_details = $this->buildChangeDetails($change_set);
49+
return sprintf(
50+
"Badge View Type '%s' (%s) in Summit '%s' updated: %s by user %s",
51+
$name,
52+
$id,
53+
$summit_name,
54+
$change_details,
55+
$this->getUserInfo()
56+
);
57+
58+
case IAuditStrategy::EVENT_ENTITY_DELETION:
59+
return sprintf(
60+
"Badge View Type '%s' (%s) from Summit '%s' was deleted by user %s",
61+
$name,
62+
$id,
63+
$summit_name,
64+
$this->getUserInfo()
65+
);
66+
}
67+
} catch (\Exception $ex) {
68+
Log::warning("SummitBadgeViewTypeAuditLogFormatter error: " . $ex->getMessage());
69+
}
70+
71+
return null;
72+
}
73+
}

0 commit comments

Comments
 (0)