Skip to content
Draft
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
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;
}
}
11 changes: 10 additions & 1 deletion app/Audit/ConcreteFormatters/EntityCreationAuditLogFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
*/
class EntityCreationAuditLogFormatter extends AbstractAuditLogFormatter
{
public function __construct()
{
parent::__construct('entity_creation');
}

protected function getCreationIgnoredEntities(): array {
return [
'PresentationAction',
Expand All @@ -39,6 +44,10 @@ public function format($subject, $change_set): ?string {
$class_name = (new ReflectionClass($subject))->getShortName();
$ignored_entities = $this->getCreationIgnoredEntities();
if (in_array($class_name, $ignored_entities)) return null;
return "{$class_name} created";

$entity_id = method_exists($subject, 'getId') ? $subject->getId() : 'N/A';
$user_info = $this->getUserInfo();

return "{$class_name} (ID: {$entity_id}) created by {$user_info}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ class EntityDeletionAuditLogFormatter extends AbstractAuditLogFormatter
*/
private $child_entity_formatter;

public function __construct(?IChildEntityAuditLogFormatter $child_entity_formatter)
public function __construct(?IChildEntityAuditLogFormatter $child_entity_formatter = null)
{
parent::__construct('entity_deletion');
$this->child_entity_formatter = $child_entity_formatter;
}

Expand All @@ -56,6 +57,8 @@ public function format($subject, $change_set): ?string {
->format($subject, IChildEntityAuditLogFormatter::CHILD_ENTITY_DELETION);
}

return "{$class_name} deleted";
$entity_id = method_exists($subject, 'getId') ? $subject->getId() : 'unknown';
$user_info = $this->getUserInfo();
return "{$class_name} (ID: {$entity_id}) deleted by {$user_info}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ class EntityUpdateAuditLogFormatter extends AbstractAuditLogFormatter
*/
private $child_entity_formatter;

public function __construct(?IChildEntityAuditLogFormatter $child_entity_formatter)
public function __construct(?IChildEntityAuditLogFormatter $child_entity_formatter = null)
{
parent::__construct('entity_update');
$this->child_entity_formatter = $child_entity_formatter;
}

Expand Down Expand Up @@ -157,6 +158,10 @@ public function format($subject, $change_set): ?string

if (count($res) == 0) return null;

return join("|", $res);
$entity_id = method_exists($subject, 'getId') ? $subject->getId() : 'N/A';
$user_info = $this->getUserInfo();
$message = join("|", $res);

return "{$class_name} (ID: {$entity_id}) updated by {$user_info}: {$message}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?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\PresentationCategoryGroup;
use Illuminate\Support\Facades\Log;

class PresentationCategoryGroupAuditLogFormatter extends AbstractAuditLogFormatter
{
public function format($subject, array $change_set): ?string
{
if (!$subject instanceof PresentationCategoryGroup) {
return null;
}

try {
$name = $subject->getName() ?? 'Unknown Track Group';
$id = $subject->getId() ?? 'unknown';
$summit = $subject->getSummit();
$summit_name = $summit ? ($summit->getName() ?? 'Unknown Summit') : 'Unknown Summit';
$color = $subject->getColor() ?? 'N/A';

switch ($this->event_type) {
case IAuditStrategy::EVENT_ENTITY_CREATION:

return sprintf(
"Track Group (PresentationCategoryGroup) '%s' (%d) created for Summit '%s' with color '%s', max votes: %d by user %s",
$name,
$id,
$summit_name,
$color,
$subject->getMaxAttendeeVotes(),
$this->getUserInfo()
);

case IAuditStrategy::EVENT_ENTITY_UPDATE:
$change_details = $this->buildChangeDetails($change_set);
return sprintf(
"Track Group (PresentationCategoryGroup) '%s' (%d) for Summit '%s' updated: %s by user %s",
$name,
$id,
$summit_name,
$change_details,
$this->getUserInfo()
);

case IAuditStrategy::EVENT_ENTITY_DELETION:
return sprintf(
"Track Group (PresentationCategoryGroup) '%s' (%d) for Summit '%s' with color '%s' was deleted by user %s",
$name,
$id,
$summit_name,
$color,
$this->getUserInfo()
);
}
} catch (\Exception $ex) {
Log::warning("PresentationCategoryGroupAuditLogFormatter error: " . $ex->getMessage());
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public function format($subject, array $change_set): ?string

case IAuditStrategy::EVENT_ENTITY_UPDATE:
$extracted = $this->extractChangedFields($change_set);
$extracted['change_set'] = $change_set;
return $this->formatUpdate($data, $extracted);

case IAuditStrategy::EVENT_ENTITY_DELETION:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,12 @@ public function format($subject, array $change_set): ?string
);

case IAuditStrategy::EVENT_ENTITY_UPDATE:
$changed_fields = [];
if (isset($change_set['FirstName']) || isset($change_set['LastName'])) {
$changed_fields[] = "name";
}
if (isset($change_set['Email'])) {
$changed_fields[] = "email";
}
if (isset($change_set['Title'])) {
$changed_fields[] = "title";
}

if (isset($change_set['Country'])) {
$changed_fields[] = "country";
}
if (isset($change_set['AvailableForBureau'])) {
$changed_fields[] = "available_for_bureau";
}
if (isset($change_set['FundedTravel'])) {
$changed_fields[] = "funded_travel";
}
if (isset($change_set['WillingToTravel'])) {
$changed_fields[] = "willing_to_travel";
}
if (isset($change_set['WillingToPresentVideo'])) {
$changed_fields[] = "willing_to_present_video";
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,12 @@ protected function formatCreation(array $data): string

protected function formatUpdate(array $data, array $extracted): string
{
if ($extracted['old_status'] && $extracted['new_status']) {
return sprintf(
"Presentation '%s' (%s) status changed: %s → %s (%s changed) by user %s",
$data['title'],
$data['id'],
strtoupper($extracted['old_status']),
strtoupper($extracted['new_status']),
$extracted['fields'],
$this->getUserInfo()
);
}

$change_details = $this->buildChangeDetails($extracted['change_set']);
return sprintf(
"Presentation '%s' (%s) updated (%s changed) by user %s",
"Presentation '%s' (%s) updated: %s by user %s",
$data['title'],
$data['id'],
$extracted['fields'],
$change_details,
$this->getUserInfo()
);
}
Expand Down
85 changes: 85 additions & 0 deletions app/Audit/ConcreteFormatters/RSVPAuditLogFormatter.php
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 Illuminate\Support\Facades\Log;
use models\summit\RSVP;


class RSVPAuditLogFormatter extends AbstractAuditLogFormatter
{
/**
* {@inheritDoc}
*/
public function format($subject, array $change_set): ?string
{
// Validar que es una entidad RSVP
if (!$subject instanceof RSVP) {
return null;
}

try {
$eventTitle = $subject->getEvent()?->getTitle() ?? 'Unknown Event';
$ownerEmail = $subject->getOwner()?->getEmail() ?? 'Unknown Member';
$ownerId = $subject->getOwner()?->getId() ?? 'unknown';
$id = $subject->getId() ?? 'unknown';
$status = $subject->getStatus() ?? 'Unknown';
$seatType = $subject->getSeatType() ?? 'Unknown';

switch ($this->event_type) {
case IAuditStrategy::EVENT_ENTITY_CREATION:
return sprintf(
"RSVP created for event '%s' (ID: %s) by member %s (ID: %s) - Status: %s, Seat Type: %s, by user %s",
$eventTitle,
$subject->getEvent()?->getId() ?? 'unknown',
$ownerEmail,
$ownerId,
$status,
$seatType,
$this->getUserInfo()
);

case IAuditStrategy::EVENT_ENTITY_UPDATE:
$change_details = $this->buildChangeDetails($change_set);
return sprintf(
"RSVP (ID: %s) for event '%s' updated: %s by user %s",
$id,
$eventTitle,
$change_details,
$this->getUserInfo()
);

case IAuditStrategy::EVENT_ENTITY_DELETION:
return sprintf(
"RSVP (ID: %s) deleted for event '%s' by member %s (ID: %s) - Final Status: %s, Seat Type: %s by user %s",
$id,
$eventTitle,
$ownerEmail,
$ownerId,
$status,
$seatType,
$this->getUserInfo()
);
}
} catch (\Exception $ex) {
Log::warning("RSVPAuditLogFormatter error: " . $ex->getMessage());
}

return null;
}
}
Loading