-
Notifications
You must be signed in to change notification settings - Fork 2
Feature| New Formatters for activities #477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
68a486a
4c408d1
292800e
5606861
a58c130
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| <?php | ||
|
|
||
| namespace App\Audit\ConcreteFormatters\ChildEntityFormatters; | ||
|
|
||
| /** | ||
| * Copyright 2025 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| use models\summit\RSVPAnswer; | ||
|
|
||
| class RSVPAnswerAuditLogFormatter implements IChildEntityAuditLogFormatter | ||
| { | ||
| public function format($subject, string $child_entity_action_type, ?string $additional_info = ""): ?string | ||
| { | ||
| if (!$subject instanceof RSVPAnswer) { | ||
| return null; | ||
| } | ||
|
|
||
| try { | ||
| $questionId = $subject->getQuestionId(); | ||
| $value = $subject->getValue(); | ||
| $question = $subject->getQuestion(); | ||
| $questionLabel = $question?->getLabel() ?? sprintf("Question #%d", $questionId); | ||
|
|
||
| switch ($child_entity_action_type) { | ||
| case IChildEntityAuditLogFormatter::CHILD_ENTITY_CREATION: | ||
| return sprintf( | ||
| "RSVP Answer added for question '%s' with value '%s'", | ||
| $questionLabel, | ||
| $value | ||
| ); | ||
|
|
||
| case IChildEntityAuditLogFormatter::CHILD_ENTITY_UPDATE: | ||
| if (!empty($additional_info)) { | ||
| return sprintf( | ||
| "RSVP Answer for question '%s' updated: %s", | ||
| $questionLabel, | ||
| $additional_info | ||
| ); | ||
| } | ||
| return sprintf( | ||
| "RSVP Answer for question '%s' updated to '%s'", | ||
| $questionLabel, | ||
| $value | ||
| ); | ||
|
|
||
| case IChildEntityAuditLogFormatter::CHILD_ENTITY_DELETION: | ||
| return sprintf( | ||
| "RSVP Answer removed for question '%s' (had value '%s')", | ||
| $questionLabel, | ||
| $value | ||
| ); | ||
| } | ||
| } catch (\Exception $ex) { | ||
| return null; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| <?php | ||
|
|
||
| namespace App\Audit\ConcreteFormatters; | ||
|
|
||
| /** | ||
| * Copyright 2025 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| use App\Audit\AbstractAuditLogFormatter; | ||
| use App\Audit\Interfaces\IAuditStrategy; | ||
| use models\main\Company; | ||
| use Illuminate\Support\Facades\Log; | ||
|
|
||
| class CompanyAuditLogFormatter extends AbstractAuditLogFormatter | ||
| { | ||
| public function format($subject, array $change_set): ?string | ||
| { | ||
| if (!$subject instanceof Company) { | ||
| return null; | ||
| } | ||
|
|
||
| try { | ||
| $name = $subject->getName() ?? 'Unknown Company'; | ||
| $id = $subject->getId() ?? 'unknown'; | ||
| $city = $subject->getCity() ?? 'N/A'; | ||
| $country = $subject->getCountry() ?? 'N/A'; | ||
| $display_on_site = $subject->isDisplayOnSite() ? 'yes' : 'no'; | ||
|
|
||
| switch ($this->event_type) { | ||
| case IAuditStrategy::EVENT_ENTITY_CREATION: | ||
| return sprintf( | ||
| "Company '%s' (%d) created located in %s, %s, display on site: %s by user %s", | ||
| $name, | ||
| $id, | ||
| $city, | ||
| $country, | ||
| $display_on_site, | ||
| $this->getUserInfo() | ||
| ); | ||
|
|
||
| case IAuditStrategy::EVENT_ENTITY_UPDATE: | ||
| $change_details = $this->buildChangeDetails($change_set); | ||
| return sprintf( | ||
| "Company '%s' (%d) updated: %s by user %s", | ||
| $name, | ||
| $id, | ||
| $change_details, | ||
| $this->getUserInfo() | ||
| ); | ||
|
|
||
| case IAuditStrategy::EVENT_ENTITY_DELETION: | ||
| return sprintf( | ||
| "Company '%s' (%d) located in %s, %s was deleted by user %s", | ||
| $name, | ||
| $id, | ||
| $city, | ||
| $country, | ||
| $this->getUserInfo() | ||
| ); | ||
| } | ||
| } catch (\Exception $ex) { | ||
| Log::warning("CompanyAuditLogFormatter error: " . $ex->getMessage()); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -25,6 +25,11 @@ | |||||||||||||
| */ | ||||||||||||||
| class EntityCreationAuditLogFormatter extends AbstractAuditLogFormatter | ||||||||||||||
| { | ||||||||||||||
| public function __construct() | ||||||||||||||
| { | ||||||||||||||
| parent::__construct('entity_creation'); | ||||||||||||||
|
Comment on lines
+28
to
+30
|
||||||||||||||
| public function __construct() | |
| { | |
| parent::__construct('entity_creation'); | |
| public function __construct(string $event_type = 'entity_creation') | |
| { | |
| parent::__construct($event_type); |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,77 @@ | ||||||||||||||
| <?php | ||||||||||||||
|
|
||||||||||||||
| namespace App\Audit\ConcreteFormatters; | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Copyright 2025 OpenStack Foundation | ||||||||||||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||
| * you may not use this file except in compliance with the License. | ||||||||||||||
| * You may obtain a copy of the License at | ||||||||||||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||
| * Unless required by applicable law or agreed to in writing, software | ||||||||||||||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||
| * See the License for the specific language governing permissions and | ||||||||||||||
| * limitations under the License. | ||||||||||||||
| **/ | ||||||||||||||
|
|
||||||||||||||
| use App\Audit\AbstractAuditLogFormatter; | ||||||||||||||
| use App\Audit\Interfaces\IAuditStrategy; | ||||||||||||||
| use models\summit\PresentationCategory; | ||||||||||||||
| use Illuminate\Support\Facades\Log; | ||||||||||||||
|
|
||||||||||||||
| class PresentationCategoryAuditLogFormatter extends AbstractAuditLogFormatter | ||||||||||||||
| { | ||||||||||||||
|
||||||||||||||
| { | |
| { | |
| public function __construct(string $event_type) | |
| { | |
| parent::__construct($event_type); | |
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,78 @@ | ||||||||||||||
| <?php | ||||||||||||||
|
|
||||||||||||||
| namespace App\Audit\ConcreteFormatters; | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Copyright 2025 OpenStack Foundation | ||||||||||||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||
| * you may not use this file except in compliance with the License. | ||||||||||||||
| * You may obtain a copy of the License at | ||||||||||||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||
| * Unless required by applicable law or agreed to in writing, software | ||||||||||||||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||
| * See the License for the specific language governing permissions and | ||||||||||||||
| * limitations under the License. | ||||||||||||||
| **/ | ||||||||||||||
|
|
||||||||||||||
| use App\Audit\AbstractAuditLogFormatter; | ||||||||||||||
| use App\Audit\Interfaces\IAuditStrategy; | ||||||||||||||
| use models\summit\PresentationCategoryGroup; | ||||||||||||||
| use Illuminate\Support\Facades\Log; | ||||||||||||||
|
|
||||||||||||||
| class PresentationCategoryGroupAuditLogFormatter extends AbstractAuditLogFormatter | ||||||||||||||
| { | ||||||||||||||
|
||||||||||||||
| { | |
| { | |
| public function __construct(string $event_type) | |
| { | |
| parent::__construct($event_type); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing constructor. All audit log formatters must define a constructor that accepts an event_type parameter and passes it to the parent class. The factory instantiates formatters with
new $strategy_class($event_type). Add a constructor like: