-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
68a486a
feat: add news formatter for Event site and Event
andrestejerina97 4c408d1
feat: add user context and id for generic entities
andrestejerina97 292800e
fix: refactor for old formatters
andrestejerina97 5606861
feat: add new formatters
andrestejerina97 a58c130
feat: add placeholder for process by jobs
andrestejerina97 3e19826
fix: change event_type name
andrestejerina97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
app/Audit/ConcreteFormatters/ChildEntityFormatters/RSVPAnswerAuditLogFormatter.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
app/Audit/ConcreteFormatters/PresentationCategoryAuditLogFormatter.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| { | ||
smarcet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public function format($subject, array $change_set): ?string | ||
| { | ||
| if (!$subject instanceof PresentationCategory) { | ||
| return null; | ||
| } | ||
|
|
||
| try { | ||
| $title = $subject->getTitle() ?? 'Unknown Category'; | ||
| $code = $subject->getCode() ?? 'N/A'; | ||
| $id = $subject->getId() ?? 'unknown'; | ||
| $summit = $subject->getSummit(); | ||
| $summit_name = $summit ? ($summit->getName() ?? 'Unknown Summit') : 'Unknown Summit'; | ||
|
|
||
| switch ($this->event_type) { | ||
| case IAuditStrategy::EVENT_ENTITY_CREATION: | ||
| return sprintf( | ||
| "Presentation Category '%s' (%s) (%d) created for Summit '%s' by user %s", | ||
| $title, | ||
| $code, | ||
| $id, | ||
| $summit_name, | ||
| $this->getUserInfo() | ||
| ); | ||
|
|
||
| case IAuditStrategy::EVENT_ENTITY_UPDATE: | ||
| $change_details = $this->buildChangeDetails($change_set); | ||
| return sprintf( | ||
| "Presentation Category '%s' (%s) (%d) for Summit '%s' updated: %s by user %s", | ||
| $title, | ||
| $code, | ||
| $id, | ||
| $summit_name, | ||
| $change_details, | ||
| $this->getUserInfo() | ||
| ); | ||
|
|
||
| case IAuditStrategy::EVENT_ENTITY_DELETION: | ||
| return sprintf( | ||
| "Presentation Category '%s' (%s) (%d) for Summit '%s' was deleted by user %s", | ||
| $title, | ||
| $code, | ||
| $id, | ||
| $summit_name, | ||
| $this->getUserInfo() | ||
| ); | ||
| } | ||
| } catch (\Exception $ex) { | ||
| Log::warning("PresentationCategoryAuditLogFormatter error: " . $ex->getMessage()); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.