-
Notifications
You must be signed in to change notification settings - Fork 2
fix(audit): track chair score entries show chair, score and one row per change #606
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
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
33 changes: 33 additions & 0 deletions
33
...udit/ConcreteFormatters/ChildEntityFormatters/IChildEntityCollectionAuditLogFormatter.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,33 @@ | ||
| <?php | ||
|
|
||
| namespace App\Audit\ConcreteFormatters\ChildEntityFormatters; | ||
|
|
||
| /** | ||
| * Copyright 2026 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 Doctrine\ORM\PersistentCollection; | ||
|
|
||
| /** | ||
| * Implemented by child formatters that need to see the whole collection diff at once | ||
| * (e.g. to render a delete + insert pair as a single "changed" entry) instead of | ||
| * formatting each inserted / deleted element on its own. | ||
| * @package App\Audit\ConcreteFormatters\ChildEntityFormatters | ||
| */ | ||
| interface IChildEntityCollectionAuditLogFormatter | ||
| { | ||
| /** | ||
| * @param PersistentCollection $collection | ||
| * @return string|null | ||
| */ | ||
| public function formatCollection(PersistentCollection $collection): ?string; | ||
| } |
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
101 changes: 101 additions & 0 deletions
101
tests/OpenTelemetry/AuditLogOtlpStrategySkippedCollectionTest.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,101 @@ | ||
| <?php | ||
|
|
||
| namespace Tests\OpenTelemetry; | ||
|
|
||
| /** | ||
| * Copyright 2026 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\AuditContext; | ||
| use App\Audit\AuditLogOtlpStrategy; | ||
| use App\Audit\IAuditLogFormatterFactory; | ||
| use App\Audit\Interfaces\IAuditStrategy; | ||
| use App\Models\Foundation\Summit\Events\Presentations\TrackChairs\PresentationTrackChairScore; | ||
| use Doctrine\Common\Collections\ArrayCollection; | ||
| use Doctrine\ORM\EntityManagerInterface; | ||
| use Doctrine\ORM\Mapping\ClassMetadata; | ||
| use Doctrine\ORM\Mapping\OneToManyAssociationMapping; | ||
| use Doctrine\ORM\PersistentCollection; | ||
| use Illuminate\Support\Facades\Queue; | ||
| use Mockery; | ||
| use models\summit\Presentation; | ||
| use models\summit\SummitTrackChair; | ||
|
|
||
| /** | ||
| * Every track chair score lives in both Presentation::track_chairs_scores and | ||
| * SummitTrackChair::scores; only the track chair side may be audited or each score is | ||
| * logged twice. | ||
| */ | ||
| class AuditLogOtlpStrategySkippedCollectionTest extends OpenTelemetryTestCase | ||
| { | ||
| protected function tearDown(): void | ||
| { | ||
| Mockery::close(); | ||
| parent::tearDown(); | ||
| } | ||
|
|
||
| private function buildStrategy(IAuditLogFormatterFactory $factory): AuditLogOtlpStrategy | ||
| { | ||
| $strategy = new AuditLogOtlpStrategy($factory); | ||
| $enabled = (new \ReflectionClass($strategy))->getProperty('enabled'); | ||
| $enabled->setAccessible(true); | ||
| $enabled->setValue($strategy, true); | ||
| return $strategy; | ||
| } | ||
|
|
||
| private function buildCollection(object $owner, string $field, string $mapped_by): PersistentCollection | ||
| { | ||
| $collection = new PersistentCollection( | ||
| $this->createMock(EntityManagerInterface::class), | ||
| new ClassMetadata(PresentationTrackChairScore::class), | ||
| new ArrayCollection() | ||
| ); | ||
| $collection->setOwner($owner, OneToManyAssociationMapping::fromMappingArray([ | ||
| 'fieldName' => $field, | ||
| 'sourceEntity' => get_class($owner), | ||
| 'targetEntity' => PresentationTrackChairScore::class, | ||
| 'mappedBy' => $mapped_by, | ||
| 'isOwningSide' => false, | ||
| ])); | ||
| return $collection; | ||
| } | ||
|
|
||
| public function testPresentationTrackChairScoresCollectionIsNotAudited(): void | ||
| { | ||
| $factory = $this->createMock(IAuditLogFormatterFactory::class); | ||
| $factory->expects($this->never())->method('make'); | ||
|
|
||
| Queue::fake(); | ||
|
|
||
| $this->buildStrategy($factory)->audit( | ||
| $this->buildCollection(Mockery::mock(Presentation::class), 'track_chairs_scores', 'presentation'), | ||
| [], | ||
| IAuditStrategy::EVENT_COLLECTION_UPDATE, | ||
| new AuditContext() | ||
| ); | ||
|
|
||
| Queue::assertNothingPushed(); | ||
| } | ||
|
|
||
| public function testTrackChairScoresCollectionIsAudited(): void | ||
| { | ||
| $factory = $this->createMock(IAuditLogFormatterFactory::class); | ||
| $factory->expects($this->once())->method('make')->willReturn(null); | ||
|
|
||
| $this->buildStrategy($factory)->audit( | ||
| $this->buildCollection(Mockery::mock(SummitTrackChair::class), 'scores', 'reviewer'), | ||
| [], | ||
| IAuditStrategy::EVENT_COLLECTION_UPDATE, | ||
| new AuditContext() | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
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.
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.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Guard against a null track chair member, and catch
\Throwable.getChairName()guards against a null chair. It does not guard against a null member.SummitTrackChair::getMember()declares aMemberreturn type.SummitTrackChair::$memberusesonDelete: 'SET NULL', andclearMember()exists.getMember()throwsTypeError. The?? 'Unknown Chair'fallback on line 83 never runs.TypeErrorextends\Error, not\Exception. None of the handlers on this path catches it:catch (\Exception)blocks on Line 63 and Line 128ReflectionExceptioncatch inEntityCollectionUpdateAuditLogFormatter::format\Exceptioncatch inAuditLogOtlpStrategy::auditAs a result, the error escapes the audit listener and can fail the score write. The comment on Lines 100-101 has the same gap: typed getters throw
TypeError, so the current catch blocks never handled them.🐛 Proposed fix
private function getChairName(PresentationTrackChairScore $score, $owner): string { $chair = $owner instanceof SummitTrackChair ? $owner : ($score->hasReviewer() ? $score->getReviewer() : null); - return is_null($chair) ? 'Unknown Chair' : ($chair->getMember()->getFullName() ?? 'Unknown Chair'); + if (is_null($chair) || $chair->getMemberId() === 0) { + return 'Unknown Chair'; + } + return $chair->getMember()->getFullName() ?? 'Unknown Chair'; }Apply the same change to both handlers (Line 63 and Line 128):
📝 Committable suggestion
🤖 Prompt for AI Agents