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
28 changes: 28 additions & 0 deletions app/Audit/AbstractAuditLogFormatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Audit;

/**
* 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.
**/

abstract class AbstractAuditLogFormatter implements IAuditLogFormatter
{
protected AuditContext $ctx;

final public function setContext(AuditContext $ctx): void
{
$this->ctx = $ctx;
}

abstract public function format($subject, array $change_set): ?string;
}
3 changes: 2 additions & 1 deletion app/Audit/AuditLogFormatterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getStrategyClass(object $subject, string $event_type): ?IAuditLo
return !is_null($cls) ? new $cls($event_type):null;
}

public function make($subject, $eventType): ?IAuditLogFormatter
public function make(AuditContext $ctx, $subject, $eventType): ?IAuditLogFormatter
{
$formatter = null;
switch ($eventType) {
Expand Down Expand Up @@ -72,6 +72,7 @@ public function make($subject, $eventType): ?IAuditLogFormatter
}
break;
}
$formatter->setContext($ctx);
return $formatter;
}
}
2 changes: 1 addition & 1 deletion app/Audit/AuditLogOtlpStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function audit($subject, array $change_set, string $event_type, AuditCon
return;
}
Log::debug("AuditLogOtlpStrategy::audit current user", ["user_id" => $ctx->userId, "user_email" => $ctx->userEmail]);
$formatter = $this->formatterFactory->make($subject, $event_type);
$formatter = $this->formatterFactory->make($ctx, $subject, $event_type);
if(is_null($formatter)) {
Log::warning("AuditLogOtlpStrategy::audit formatter not found");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Audit\ConcreteFormatters;

use App\Audit\ConcreteFormatters\ChildEntityFormatters\IChildEntityAuditLogFormatter;
use App\Audit\IAuditLogFormatter;
use App\Audit\AbstractAuditLogFormatter;
use Illuminate\Support\Facades\Log;
use ReflectionException;

Expand All @@ -25,7 +25,7 @@
* Class EntityCollectionUpdateAuditLogFormatter
* @package App\Audit\ConcreteFormatters
*/
class EntityCollectionUpdateAuditLogFormatter implements IAuditLogFormatter
class EntityCollectionUpdateAuditLogFormatter extends AbstractAuditLogFormatter
{
/**
* @var IChildEntityAuditLogFormatter
Expand Down Expand Up @@ -66,4 +66,5 @@ public function format($subject, $change_set): ?string {
return null;
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Audit\ConcreteFormatters;

use App\Audit\IAuditLogFormatter;
use App\Audit\AbstractAuditLogFormatter;
use ReflectionClass;

/**
Expand All @@ -23,7 +23,7 @@
* Class EntityCreationAuditLogFormatter
* @package App\Audit\ConcreteFormatters
*/
class EntityCreationAuditLogFormatter implements IAuditLogFormatter
class EntityCreationAuditLogFormatter extends AbstractAuditLogFormatter
{
protected function getCreationIgnoredEntities(): array {
return [
Expand All @@ -41,4 +41,4 @@ public function format($subject, $change_set): ?string {
if (in_array($class_name, $ignored_entities)) return null;
return "{$class_name} created";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
* limitations under the License.
**/

use App\Audit\AbstractAuditLogFormatter;
use App\Audit\ConcreteFormatters\ChildEntityFormatters\IChildEntityAuditLogFormatter;
use App\Audit\IAuditLogFormatter;
use models\summit\SummitAttendeeBadgePrint;
use ReflectionClass;

/**
* Class EntityDeletionAuditLogFormatter
* @package App\Audit\ConcreteFormatters
*/
class EntityDeletionAuditLogFormatter implements IAuditLogFormatter
class EntityDeletionAuditLogFormatter extends AbstractAuditLogFormatter
{
/**
* @var IChildEntityAuditLogFormatter
Expand Down Expand Up @@ -58,4 +58,4 @@ public function format($subject, $change_set): ?string {

return "{$class_name} deleted";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* limitations under the License.
**/

use App\Audit\AbstractAuditLogFormatter;
use App\Audit\ConcreteFormatters\ChildEntityFormatters\IChildEntityAuditLogFormatter;
use App\Audit\IAuditLogFormatter;
use App\Models\Foundation\Summit\SelectionPlan;
use App\Models\Utils\BaseEntity;
use DateTime;
Expand All @@ -30,7 +30,7 @@
* Class EntityUpdateAuditLogFormatter
* @package App\Audit\ConcreteFormatters
*/
class EntityUpdateAuditLogFormatter implements IAuditLogFormatter
class EntityUpdateAuditLogFormatter extends AbstractAuditLogFormatter
{
/**
* @var IChildEntityAuditLogFormatter
Expand Down Expand Up @@ -159,4 +159,4 @@ public function format($subject, $change_set): ?string

return join("|", $res);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Audit\IAuditLogFormatter;

use App\Audit\AbstractAuditLogFormatter;
use App\Audit\Interfaces\IAuditStrategy;
use models\main\SummitMemberSchedule;

class SummitMemberScheduleAuditLogFormatter implements IAuditLogFormatter
class SummitMemberScheduleAuditLogFormatter extends AbstractAuditLogFormatter
{

private string $event_type;
Expand Down
6 changes: 6 additions & 0 deletions app/Audit/IAuditLogFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
*/
interface IAuditLogFormatter
{
/**
* @param $ctx
* @return void
*/
public function setContext(AuditContext $ctx): void;

/**
* @param $subject
* @param array $change_set
Expand Down
2 changes: 1 addition & 1 deletion app/Audit/IAuditLogFormatterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

interface IAuditLogFormatterFactory
{
public function make($subject, $eventType): ?IAuditLogFormatter;
public function make(AuditContext $ctx, $subject, $eventType): ?IAuditLogFormatter;
}