Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 13 additions & 22 deletions app/Audit/AuditLogFormatterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ public function __construct()
$this->config = config('audit_log', []);
}

public function getStrategyClass(object $subject, string $event_type): ?IAuditLogFormatter
{
$class = get_class($subject);
$cls = $this->config['entities'][$class]['strategy'] ?? null;
return !is_null($cls) ? new $cls($event_type):null;
}

public function make(AuditContext $ctx, $subject, $eventType): ?IAuditLogFormatter
{
$formatter = null;
Expand All @@ -53,28 +46,19 @@ public function make(AuditContext $ctx, $subject, $eventType): ?IAuditLogFormatt
break;
case IAuditStrategy::EVENT_ENTITY_CREATION:
$formatter = $this->getFormatterByContext($subject, $eventType, $ctx);
if (is_null($formatter)) {
$formatter = $this->getStrategyClass($subject, $eventType);
}
if(is_null($formatter)) {
$formatter = new EntityCreationAuditLogFormatter();
}
break;
case IAuditStrategy::EVENT_ENTITY_DELETION:
$formatter = $this->getFormatterByContext($subject, $eventType, $ctx);
if (is_null($formatter)) {
$formatter = $this->getStrategyClass($subject, $eventType);
}
if(is_null($formatter)) {
$child_entity_formatter = ChildEntityFormatterFactory::build($subject);
$formatter = new EntityDeletionAuditLogFormatter($child_entity_formatter);
}
break;
case IAuditStrategy::EVENT_ENTITY_UPDATE:
$formatter = $this->getFormatterByContext($subject, $eventType, $ctx);
if (is_null($formatter)) {
$formatter = $this->getStrategyClass($subject, $eventType);
}
if(is_null($formatter)) {
$child_entity_formatter = ChildEntityFormatterFactory::build($subject);
$formatter = new EntityUpdateAuditLogFormatter($child_entity_formatter);
Expand All @@ -90,17 +74,24 @@ private function getFormatterByContext(object $subject, string $event_type, Audi
$class = get_class($subject);
$entity_config = $this->config['entities'][$class] ?? null;

if (!$entity_config || !isset($entity_config['strategies'])) {
if (!$entity_config) {
return null;
}

foreach ($entity_config['strategies'] as $strategy) {
if (!$this->matchesStrategy($strategy, $ctx)) {
continue;
if (isset($entity_config['strategies'])) {
foreach ($entity_config['strategies'] as $strategy) {
if (!$this->matchesStrategy($strategy, $ctx)) {
continue;
}

$formatter_class = $strategy['formatter'] ?? null;
return $formatter_class ? new $formatter_class($event_type) : null;
}
}

$formatter_class = $strategy['formatter'] ?? null;
return $formatter_class ? new $formatter_class($event_type) : null;
if (isset($entity_config['strategy'])) {
$strategy_class = $entity_config['strategy'];
return new $strategy_class($event_type);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php namespace App\Audit\ConcreteFormatters\ChildEntityFormatters;

use App\Models\Foundation\Summit\Events\Presentations\TrackChairs\PresentationTrackChairScore;
use Illuminate\Support\Facades\Log;

class PresentationTrackChairScoreAuditLogFormatter implements IChildEntityAuditLogFormatter
{
public function format($subject, string $child_entity_action_type, ?string $additional_info = ""): ?string
{
if (!$subject instanceof PresentationTrackChairScore) {
return null;
}

try {
$score_type = $subject->getScoreType();
$score_label = $score_type ? $score_type->getLabel() : 'Unknown Score';

$presentation = $subject->getPresentation();
$presentation_title = $presentation ? $presentation->getTitle() : 'Unknown Presentation';

$created_by = $subject->getCreatedBy();
$chair_name = $created_by
? sprintf("%s %s", $created_by->getFirstName(), $created_by->getLastName())
: 'Unknown Chair';

switch ($child_entity_action_type) {
case self::CHILD_ENTITY_CREATION:
return sprintf(
"Track Chair '%s' scored '%s' on presentation '%s'",
$chair_name,
$score_label,
$presentation_title
);
case self::CHILD_ENTITY_DELETION:
return sprintf(
"Score removed for Track Chair '%s' from presentation '%s'",
$chair_name,
$presentation_title
);
case self::CHILD_ENTITY_UPDATE:
return sprintf(
"Track Chair '%s' score updated to '%s' on presentation '%s'",
$chair_name,
$score_label,
$presentation_title
);
}
} catch (\Exception $ex) {
Log::warning("PresentationTrackChairScoreAuditLogFormatter error: " . $ex->getMessage());
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?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 App\Models\Foundation\Summit\Events\Presentations\TrackChairs\PresentationTrackChairRatingType;
use Illuminate\Support\Facades\Log;

class PresentationTrackChairRatingTypeAuditLogFormatter extends AbstractAuditLogFormatter
{
private string $event_type;

public function __construct(string $event_type)
{
$this->event_type = $event_type;
}

public function format($subject, array $change_set): ?string
{
if (!$subject instanceof PresentationTrackChairRatingType) {
return null;
}

try {
$name = $subject->getName() ?? 'Unknown';
$selection_plan = $subject->getSelectionPlan();
$plan_name = $selection_plan ? $selection_plan->getName() : 'Unknown';

switch ($this->event_type) {
case IAuditStrategy::EVENT_ENTITY_CREATION:
return sprintf(
"Track Chair Rating Type '%s' created for Selection Plan '%s' by user %s",
$name,
$plan_name,
$this->getUserInfo()
);

case IAuditStrategy::EVENT_ENTITY_UPDATE:
$changed_fields = [];
if (isset($change_set['name'])) {
$changed_fields[] = "name";
}

$fields_str = !empty($changed_fields) ? implode(', ', $changed_fields) : 'properties';
return sprintf(
"Track Chair Rating Type '%s' updated (%s changed) by user %s",
$name,
$fields_str,
$this->getUserInfo()
);

case IAuditStrategy::EVENT_ENTITY_DELETION:
return sprintf(
"Track Chair Rating Type '%s' deleted from Selection Plan '%s' by user %s",
$name,
$plan_name,
$this->getUserInfo()
);
}
} catch (\Exception $ex) {
Log::warning("PresentationTrackChairRatingTypeAuditLogFormatter error: " . $ex->getMessage());
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?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 App\Models\Foundation\Summit\Events\Presentations\TrackChairs\PresentationTrackChairScoreType;
use Illuminate\Support\Facades\Log;

class PresentationTrackChairScoreTypeAuditLogFormatter extends AbstractAuditLogFormatter
{
private string $event_type;

public function __construct(string $event_type)
{
$this->event_type = $event_type;
}

public function format($subject, array $change_set): ?string
{
if (!$subject instanceof PresentationTrackChairScoreType) {
return null;
}

try {
$label = $subject->getLabel() ?? 'Unknown';
$score = $subject->getScore() ?? 'unknown';
$rating_type = $subject->getRatingType();
$rating_type_name = $rating_type ? $rating_type->getName() : 'Unknown';

switch ($this->event_type) {
case IAuditStrategy::EVENT_ENTITY_CREATION:
return sprintf(
"Score Type '%s' (value: %s) added to Rating Type '%s' by user %s",
$label,
$score,
$rating_type_name,
$this->getUserInfo()
);

case IAuditStrategy::EVENT_ENTITY_UPDATE:
$changed_fields = [];
if (isset($change_set['label'])) {
$changed_fields[] = "label";
}
if (isset($change_set['score'])) {
$changed_fields[] = "score";
}

$fields_str = !empty($changed_fields) ? implode(', ', $changed_fields) : 'properties';
return sprintf(
"Score Type '%s' updated (%s changed) by user %s",
$label,
$fields_str,
$this->getUserInfo()
);

case IAuditStrategy::EVENT_ENTITY_DELETION:
return sprintf(
"Score Type '%s' removed from Rating Type '%s' by user %s",
$label,
$rating_type_name,
$this->getUserInfo()
);
}
} catch (\Exception $ex) {
Log::warning("PresentationTrackChairScoreTypeAuditLogFormatter error: " . $ex->getMessage());
}

return null;
}
}
97 changes: 97 additions & 0 deletions app/Audit/ConcreteFormatters/SummitTrackChairAuditLogFormatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?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\SummitTrackChair;
use Illuminate\Support\Facades\Log;

class SummitTrackChairAuditLogFormatter extends AbstractAuditLogFormatter
{
private string $event_type;

public function __construct(string $event_type)
{
$this->event_type = $event_type;
}

public function format($subject, array $change_set): ?string
{
if (!$subject instanceof SummitTrackChair) {
return null;
}

try {
$member = $subject->getMember();
$member_name = $member ? sprintf("%s %s", $member->getFirstName(), $member->getLastName()) : 'Unknown';
$member_id = $member ? $member->getId() : 'unknown';

switch ($this->event_type) {
case IAuditStrategy::EVENT_ENTITY_CREATION:
$categories = [];
foreach ($subject->getCategories() as $category) {
$categories[] = $category->getTitle();
}
$tracks_list = !empty($categories) ? implode(', ', $categories) : 'No tracks assigned';
return sprintf(
"Track Chair '%s' (%d) assigned with tracks: %s by user %s",
$member_name,
$member_id,
$tracks_list,
$this->getUserInfo()
);

case IAuditStrategy::EVENT_ENTITY_UPDATE:
if (isset($change_set['categories'])) {
$old_cats = $change_set['categories'][0] ?? [];
$new_cats = $change_set['categories'][1] ?? [];

$old_names = is_array($old_cats)
? array_map(fn($c) => $c->getTitle() ?? 'Unknown', $old_cats)
: [];
$new_names = is_array($new_cats)
? array_map(fn($c) => $c->getTitle() ?? 'Unknown', $new_cats)
: [];

$old_str = !empty($old_names) ? implode(', ', $old_names) : 'None';
$new_str = !empty($new_names) ? implode(', ', $new_names) : 'None';

return sprintf(
"Track Chair '%s' tracks changed: [%s] → [%s] by user %s",
$member_name,
$old_str,
$new_str,
$this->getUserInfo()
);
}
return sprintf("Track Chair '%s' updated by user %s", $member_name, $this->getUserInfo());

case IAuditStrategy::EVENT_ENTITY_DELETION:
return sprintf(
"Track Chair '%s' (%d) removed from summit by user %s",
$member_name,
$member_id,
$this->getUserInfo()
);
}
} catch (\Exception $ex) {
Log::warning("SummitTrackChairAuditLogFormatter error: " . $ex->getMessage());
}

return null;
}
}
Loading