Skip to content

Commit 58e0e01

Browse files
Feature: add new formatters for SelectionPlan (#482)
* feat: add new formatters for SelectionPlan * chore: Add auditlog config relation to entity <=> formatter Signed-off-by: Matias Perrone <github@matiasperrone.com> --------- Signed-off-by: Matias Perrone <github@matiasperrone.com> Co-authored-by: Matias Perrone <github@matiasperrone.com>
1 parent 0d4b93e commit 58e0e01

6 files changed

Lines changed: 390 additions & 0 deletions
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
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;
19+
use App\Audit\Interfaces\IAuditStrategy;
20+
use App\Models\Foundation\Summit\ExtraQuestions\AssignedSelectionPlanExtraQuestionType;
21+
use Illuminate\Support\Facades\Log;
22+
23+
class AssignedSelectionPlanExtraQuestionTypeAuditLogFormatter extends AbstractAuditLogFormatter
24+
{
25+
public function format($subject, array $change_set): ?string
26+
{
27+
if (!$subject instanceof AssignedSelectionPlanExtraQuestionType) {
28+
return null;
29+
}
30+
31+
try {
32+
$id = $subject->getId() ?? 'unknown';
33+
34+
switch ($this->event_type) {
35+
case IAuditStrategy::EVENT_ENTITY_CREATION:
36+
$question_type = $subject->getQuestionType();
37+
$question_label = $question_type ? ($question_type->getLabel() ?? 'Unknown Question') : 'Unknown Question';
38+
$selection_plan = $subject->getSelectionPlan();
39+
$selection_plan_id = $selection_plan ? ($selection_plan->getId() ?? 'unknown') : 'unknown';
40+
$selection_plan_name = $selection_plan ? ($selection_plan->getName() ?? 'Unknown') : 'Unknown';
41+
$is_editable = $subject->isEditable() ? 'editable' : 'not editable';
42+
return sprintf(
43+
"Assigned Selection Plan Extra Question (%s) '%s' created for selection plan %s '%s' as %s by user %s",
44+
$id,
45+
$question_label,
46+
$selection_plan_id,
47+
$selection_plan_name,
48+
$is_editable,
49+
$this->getUserInfo()
50+
);
51+
52+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
53+
$question_type = $subject->getQuestionType();
54+
$question_label = $question_type ? ($question_type->getLabel() ?? 'Unknown Question') : 'Unknown Question';
55+
$change_details = $this->buildChangeDetails($change_set);
56+
return sprintf(
57+
"Assigned Selection Plan Extra Question (%s) '%s' updated: %s by user %s",
58+
$id,
59+
$question_label,
60+
$change_details,
61+
$this->getUserInfo()
62+
);
63+
64+
case IAuditStrategy::EVENT_ENTITY_DELETION:
65+
$question_type = $subject->getQuestionType();
66+
$question_label = $question_type ? ($question_type->getLabel() ?? 'Unknown Question') : 'Unknown Question';
67+
return sprintf(
68+
"Assigned Selection Plan Extra Question (%s) '%s' was deleted by user %s",
69+
$id,
70+
$question_label,
71+
$this->getUserInfo()
72+
);
73+
}
74+
} catch (\Exception $ex) {
75+
Log::warning("AssignedSelectionPlanExtraQuestionTypeAuditLogFormatter error: " . $ex->getMessage());
76+
}
77+
78+
return null;
79+
}
80+
}
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 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;
19+
use App\Audit\Interfaces\IAuditStrategy;
20+
use App\Models\Foundation\Summit\SelectionPlanAllowedEditablePresentationQuestion;
21+
use Illuminate\Support\Facades\Log;
22+
23+
class SelectionPlanAllowedEditablePresentationQuestionAuditLogFormatter extends AbstractAuditLogFormatter
24+
{
25+
public function format($subject, array $change_set): ?string
26+
{
27+
if (!$subject instanceof SelectionPlanAllowedEditablePresentationQuestion) {
28+
return null;
29+
}
30+
31+
try {
32+
$id = $subject->getId() ?? 'unknown';
33+
$type = $subject->getType() ?? 'Unknown Question Type';
34+
35+
switch ($this->event_type) {
36+
case IAuditStrategy::EVENT_ENTITY_CREATION:
37+
$selection_plan = $subject->getSelectionPlan();
38+
$selection_plan_id = $selection_plan ? ($selection_plan->getId() ?? 'unknown') : 'unknown';
39+
$selection_plan_name = $selection_plan ? ($selection_plan->getName() ?? 'Unknown') : 'Unknown';
40+
return sprintf(
41+
"Selection Plan Allowed Editable Presentation Question (%s) type '%s' created for selection plan %s '%s' by user %s",
42+
$id,
43+
$type,
44+
$selection_plan_id,
45+
$selection_plan_name,
46+
$this->getUserInfo()
47+
);
48+
49+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
50+
$change_details = $this->buildChangeDetails($change_set);
51+
return sprintf(
52+
"Selection Plan Allowed Editable Presentation Question (%s) type '%s' updated: %s by user %s",
53+
$id,
54+
$type,
55+
$change_details,
56+
$this->getUserInfo()
57+
);
58+
59+
case IAuditStrategy::EVENT_ENTITY_DELETION:
60+
return sprintf(
61+
"Selection Plan Allowed Editable Presentation Question (%s) type '%s' was deleted by user %s",
62+
$id,
63+
$type,
64+
$this->getUserInfo()
65+
);
66+
}
67+
} catch (\Exception $ex) {
68+
Log::warning("SelectionPlanAllowedEditablePresentationQuestionAuditLogFormatter 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 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;
19+
use App\Audit\Interfaces\IAuditStrategy;
20+
use App\Models\Foundation\Summit\SelectionPlanAllowedPresentationQuestion;
21+
use Illuminate\Support\Facades\Log;
22+
23+
class SelectionPlanAllowedPresentationQuestionAuditLogFormatter extends AbstractAuditLogFormatter
24+
{
25+
public function format($subject, array $change_set): ?string
26+
{
27+
if (!$subject instanceof SelectionPlanAllowedPresentationQuestion) {
28+
return null;
29+
}
30+
31+
try {
32+
$id = $subject->getId() ?? 'unknown';
33+
$type = $subject->getType() ?? 'Unknown Question Type';
34+
35+
switch ($this->event_type) {
36+
case IAuditStrategy::EVENT_ENTITY_CREATION:
37+
$selection_plan = $subject->getSelectionPlan();
38+
$selection_plan_id = $selection_plan ? ($selection_plan->getId() ?? 'unknown') : 'unknown';
39+
$selection_plan_name = $selection_plan ? ($selection_plan->getName() ?? 'Unknown') : 'Unknown';
40+
return sprintf(
41+
"Selection Plan Allowed Presentation Question (%s) type '%s' created for selection plan %s '%s' by user %s",
42+
$id,
43+
$type,
44+
$selection_plan_id,
45+
$selection_plan_name,
46+
$this->getUserInfo()
47+
);
48+
49+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
50+
$change_details = $this->buildChangeDetails($change_set);
51+
return sprintf(
52+
"Selection Plan Allowed Presentation Question (%s) type '%s' updated: %s by user %s",
53+
$id,
54+
$type,
55+
$change_details,
56+
$this->getUserInfo()
57+
);
58+
59+
case IAuditStrategy::EVENT_ENTITY_DELETION:
60+
return sprintf(
61+
"Selection Plan Allowed Presentation Question (%s) type '%s' was deleted by user %s",
62+
$id,
63+
$type,
64+
$this->getUserInfo()
65+
);
66+
}
67+
} catch (\Exception $ex) {
68+
Log::warning("SelectionPlanAllowedPresentationQuestionAuditLogFormatter error: " . $ex->getMessage());
69+
}
70+
71+
return null;
72+
}
73+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
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;
19+
use App\Audit\Interfaces\IAuditStrategy;
20+
use models\summit\SummitBookableVenueRoomAttributeType;
21+
use Illuminate\Support\Facades\Log;
22+
23+
class SummitBookableVenueRoomAttributeTypeAuditLogFormatter extends AbstractAuditLogFormatter
24+
{
25+
public function format($subject, array $change_set): ?string
26+
{
27+
if (!$subject instanceof SummitBookableVenueRoomAttributeType) {
28+
return null;
29+
}
30+
31+
try {
32+
$id = $subject->getId() ?? 'unknown';
33+
$type = $subject->getType() ?? 'Unknown Type';
34+
35+
switch ($this->event_type) {
36+
case IAuditStrategy::EVENT_ENTITY_CREATION:
37+
$summit_id = $subject->getSummitId() ?? 'unknown';
38+
return sprintf(
39+
"Summit Bookable Venue Room Attribute Type (%s) '%s' created for summit %s by user %s",
40+
$id,
41+
$type,
42+
$summit_id,
43+
$this->getUserInfo()
44+
);
45+
46+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
47+
$change_details = $this->buildChangeDetails($change_set);
48+
return sprintf(
49+
"Summit Bookable Venue Room Attribute Type (%s) '%s' updated: %s by user %s",
50+
$id,
51+
$type,
52+
$change_details,
53+
$this->getUserInfo()
54+
);
55+
56+
case IAuditStrategy::EVENT_ENTITY_DELETION:
57+
return sprintf(
58+
"Summit Bookable Venue Room Attribute Type (%s) '%s' was deleted by user %s",
59+
$id,
60+
$type,
61+
$this->getUserInfo()
62+
);
63+
}
64+
} catch (\Exception $ex) {
65+
Log::warning("SummitBookableVenueRoomAttributeTypeAuditLogFormatter error: " . $ex->getMessage());
66+
}
67+
68+
return null;
69+
}
70+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
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;
19+
use App\Audit\Interfaces\IAuditStrategy;
20+
use App\Models\Foundation\Summit\Registration\SummitRegistrationFeedMetadata;
21+
use Illuminate\Support\Facades\Log;
22+
23+
class SummitRegistrationFeedMetadataAuditLogFormatter extends AbstractAuditLogFormatter
24+
{
25+
public function format($subject, array $change_set): ?string
26+
{
27+
if (!$subject instanceof SummitRegistrationFeedMetadata) {
28+
return null;
29+
}
30+
31+
try {
32+
$id = $subject->getId() ?? 'unknown';
33+
34+
switch ($this->event_type) {
35+
case IAuditStrategy::EVENT_ENTITY_CREATION:
36+
$key = $subject->getKey() ?? 'Unknown Key';
37+
$value = $subject->getValue() ?? 'Unknown Value';
38+
$summit_id = $subject->getSummitId() ?? 'unknown';
39+
return sprintf(
40+
"Summit Registration Feed Metadata (%s) key '%s' value '%s' created for summit %s by user %s",
41+
$id,
42+
$key,
43+
$value,
44+
$summit_id,
45+
$this->getUserInfo()
46+
);
47+
48+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
49+
$key = $subject->getKey() ?? 'Unknown Key';
50+
$change_details = $this->buildChangeDetails($change_set);
51+
return sprintf(
52+
"Summit Registration Feed Metadata (%s) key '%s' updated: %s by user %s",
53+
$id,
54+
$key,
55+
$change_details,
56+
$this->getUserInfo()
57+
);
58+
59+
case IAuditStrategy::EVENT_ENTITY_DELETION:
60+
$key = $subject->getKey() ?? 'Unknown Key';
61+
return sprintf(
62+
"Summit Registration Feed Metadata (%s) key '%s' was deleted by user %s",
63+
$id,
64+
$key,
65+
$this->getUserInfo()
66+
);
67+
}
68+
} catch (\Exception $ex) {
69+
Log::warning("SummitRegistrationFeedMetadataAuditLogFormatter error: " . $ex->getMessage());
70+
}
71+
72+
return null;
73+
}
74+
}

0 commit comments

Comments
 (0)