Skip to content
Open
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
73 changes: 73 additions & 0 deletions app/Audit/AbstractAuditLogFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,78 @@ protected function getUserInfo(): string
return sprintf("%s (%s)", $user_name, $user_id);
}


protected function getIgnoredFields(): array
{
return [
'last_created',
'last_updated',
'last_edited',
'created_by',
'updated_by'
];
}

protected function formatChangeValue($value): string
{
if (is_bool($value)) {
return $value ? 'true' : 'false';
}
if (is_null($value)) {
return 'null';
}
if ($value instanceof \DateTimeInterface) {
return $value->format('Y-m-d H:i:s');
}
if ($value instanceof \Doctrine\Common\Collections\Collection) {
$count = $value->count();
return sprintf('Collection[%d items]', $count);
}
if (is_object($value)) {
$className = get_class($value);
return sprintf('%s', $className);
}
if (is_array($value)) {
return sprintf('Array[%d items]', count($value));
}
return (string) $value;
}


protected function buildChangeDetails(array $change_set): string
{
$changed_fields = [];
$ignored_fields = $this->getIgnoredFields();

foreach ($change_set as $prop_name => $change_values) {
if (in_array($prop_name, $ignored_fields)) {
continue;
}

$old_value = $change_values[0] ?? null;
$new_value = $change_values[1] ?? null;

$formatted_change = $this->formatFieldChange($prop_name, $old_value, $new_value);
if ($formatted_change !== null) {
$changed_fields[] = $formatted_change;
}
}

if (empty($changed_fields)) {
return 'properties without changes registered';
}

$fields_summary = count($changed_fields) . ' field(s) modified: ';
return $fields_summary . implode(' | ', $changed_fields);
}

protected function formatFieldChange(string $prop_name, $old_value, $new_value): ?string
{
$old_display = $this->formatChangeValue($old_value);
$new_display = $this->formatChangeValue($new_value);

return sprintf("Property \"%s\" has changed from \"%s\" to \"%s\"", $prop_name, $old_display, $new_display);
}

abstract public function format($subject, array $change_set): ?string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(?IChildEntityAuditLogFormatter $child_entity_formatt
$this->child_entity_formatter = $child_entity_formatter;
}

protected function getIgnoredFields()
protected function getIgnoredFields(): array
{
return [
'last_created',
Expand Down
17 changes: 3 additions & 14 deletions app/Audit/ConcreteFormatters/FeaturedSpeakerAuditLogFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,12 @@ public function format($subject, array $change_set): ?string
);

case IAuditStrategy::EVENT_ENTITY_UPDATE:
$changed_fields = [];

if (isset($change_set['Order'])) {
$old_order = $change_set['Order'][0] ?? 'unknown';
$new_order = $change_set['Order'][1] ?? 'unknown';
$changed_fields[] = sprintf("display_order %s → %s", $old_order, $new_order);
}
if (isset($change_set['PresentationSpeakerID'])) {
$changed_fields[] = "speaker";
}

$fields_str = !empty($changed_fields) ? implode(', ', $changed_fields) : 'properties';
$change_details = $this->buildChangeDetails($change_set);
return sprintf(
"Featured speaker '%s' (%s) updated (%s changed) by user %s",
"Featured speaker '%s' (%s) updated: %s by user %s",
$speaker_name,
$speaker_id,
$fields_str,
$change_details,
$this->getUserInfo()
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace App\Audit\ConcreteFormatters\PresentationFormatters;

/**
* 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\PresentationActionType;
use Illuminate\Support\Facades\Log;

class PresentationActionTypeAuditLogFormatter 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 PresentationActionType) {
return null;
}

try {
$label = $subject->getLabel() ?? 'Unknown Action Type';
$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 Action Type '%s' (%d) created for Summit '%s' by user %s",
$label,
$id,
$summit_name,
$this->getUserInfo()
);

case IAuditStrategy::EVENT_ENTITY_UPDATE:
$change_details = $this->buildChangeDetails($change_set);
return sprintf(
"Presentation Action Type '%s' (%d) for Summit '%s' updated: %s by user %s",
$label,
$id,
$summit_name,
$change_details,
$this->getUserInfo()
);

case IAuditStrategy::EVENT_ENTITY_DELETION:
return sprintf(
"Presentation Action Type '%s' (%d) for Summit '%s' was deleted by user %s",
$label,
$id,
$summit_name,
$this->getUserInfo()
);
}
} catch (\Exception $ex) {
Log::warning("PresentationActionTypeAuditLogFormatter error: " . $ex->getMessage());
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace App\Audit\ConcreteFormatters\PresentationFormatters;

/**
* 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\PresentationLink;
use Illuminate\Support\Facades\Log;

class PresentationLinkAuditLogFormatter 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 PresentationLink) {
return null;
}

try {
$title = $subject->getName() ?? 'Unknown Link';
$id = $subject->getId() ?? 'unknown';
$class_name = $subject->getClassName();

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

switch ($this->event_type) {
case IAuditStrategy::EVENT_ENTITY_CREATION:
return sprintf(
"Presentation Link '%s' (%d) of type %s created for presentation '%s' by user %s",
$title,
$id,
$class_name,
$presentation_title,
$this->getUserInfo()
);

case IAuditStrategy::EVENT_ENTITY_UPDATE:
$change_details = $this->buildChangeDetails($change_set);
return sprintf(
"Presentation Link '%s' (%d) for presentation '%s' updated: %s by user %s",
$title,
$id,
$presentation_title,
$change_details,
$this->getUserInfo()
);

case IAuditStrategy::EVENT_ENTITY_DELETION:
return sprintf(
"Presentation Link '%s' (%d) of type %s for presentation '%s' was deleted by user %s",
$title,
$id,
$class_name,
$presentation_title,
$this->getUserInfo()
);
}
} catch (\Exception $ex) {
Log::warning("PresentationLinkAuditLogFormatter error: " . $ex->getMessage());
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace App\Audit\ConcreteFormatters\PresentationFormatters;

/**
* 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\PresentationMediaUpload;
use Illuminate\Support\Facades\Log;

class PresentationMediaUploadAuditLogFormatter 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 PresentationMediaUpload) {
return null;
}

try {
$title = $subject->getName() ?? 'Unknown Media';
$id = $subject->getId() ?? 'unknown';
$class_name = $subject->getClassName();

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


switch ($this->event_type) {
case IAuditStrategy::EVENT_ENTITY_CREATION:
return sprintf(
"Presentation Media Upload '%s' (%d) of type %s created for presentation '%s' by user %s",
$title,
$id,
$class_name,
$presentation_title,
$this->getUserInfo()
);

case IAuditStrategy::EVENT_ENTITY_UPDATE:
$change_details = $this->buildChangeDetails($change_set);
return sprintf(
"Presentation Media Upload '%s' (%d) for presentation '%s' updated: %s by user %s",
$title,
$id,
$presentation_title,
$change_details,
$this->getUserInfo()
);

case IAuditStrategy::EVENT_ENTITY_DELETION:
return sprintf(
"Presentation Media Upload '%s' (%d) of type %s for presentation '%s' was deleted by user %s",
$title,
$id,
$class_name,
$presentation_title,
$this->getUserInfo()
);
}
} catch (\Exception $ex) {
Log::warning("PresentationMediaUploadAuditLogFormatter error: " . $ex->getMessage());
}

return null;
}
}
Loading