Skip to content

Commit

Permalink
Remove unneccessary user id
Browse files Browse the repository at this point in the history
  • Loading branch information
hweihwang committed Apr 11, 2024
1 parent ae59bc2 commit 76e3395
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 57 deletions.
2 changes: 1 addition & 1 deletion lib/Db/LegacyRowMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private function resolveSearchValue(string $unresolvedSearchValue, string $userI
/**
* @param (int|string)[][] $sortArray
*
* @psalm-param list<array{columnId: int, mode: 'ASC'|'DESC'}> $sortArray
* @psalm-param list<array{columnId?: int, columnType?: string, mode?: 'ASC'|'DESC'}> $sortArray
*/
private function addOrderByRules(IQueryBuilder $qb, array $sortArray) {
foreach ($sortArray as $index => $sortRule) {
Expand Down
6 changes: 1 addition & 5 deletions lib/Event/RowDeletedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@
use OCP\EventDispatcher\Event;

final class RowDeletedEvent extends Event {
public function __construct(protected Row2 $row, protected string $userId) {
public function __construct(protected Row2 $row) {
parent::__construct();
}

public function getRow(): Row2 {
return $this->row;
}

public function getUserId(): string {
return $this->userId;
}
}
6 changes: 1 addition & 5 deletions lib/Event/TableDeletedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@
use OCP\EventDispatcher\Event;

final class TableDeletedEvent extends Event {
public function __construct(protected Table $table, protected string $userId) {
public function __construct(protected Table $table) {
parent::__construct();
}

public function getTable(): Table {
return $this->table;
}

public function getUserId(): string {
return $this->userId;
}
}
6 changes: 1 addition & 5 deletions lib/Event/ViewDeletedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@
use OCP\EventDispatcher\Event;

final class ViewDeletedEvent extends Event {
public function __construct(protected View $view, protected string $userId) {
public function __construct(protected View $view) {
parent::__construct();
}

public function getView(): View {
return $this->view;
}

public function getUserId(): string {
return $this->userId;
}
}
4 changes: 1 addition & 3 deletions lib/Listener/WhenRowDeletedAuditLogListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ public function handle(Event $event): void {
}

$row = $event->getRow();
$userId = $event->getUserId();
$rowId = $row->getId();

$this->auditLogService->log("Row with ID: $rowId was deleted by user with ID: $userId", [
$this->auditLogService->log("Row with ID: $rowId was deleted", [
'row' => $row->jsonSerialize(),
'userId' => $userId,
]);
}
}
4 changes: 1 addition & 3 deletions lib/Listener/WhenTableDeletedAuditLogListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ public function handle(Event $event): void {
}

$table = $event->getTable();
$userId = $event->getUserId();

$this->auditLogService->log("Table with ID: $table->id was deleted by user with ID: $userId", [
$this->auditLogService->log("Table with ID: $table->id was deleted", [
'table' => $table->jsonSerialize(),
'userId' => $userId,
]);
}
}
4 changes: 1 addition & 3 deletions lib/Listener/WhenViewDeletedAuditLogListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ public function handle(Event $event): void {
}

$view = $event->getView();
$userId = $event->getUserId();

$this->auditLogService->log("View with ID: $view->id was deleted by user with ID: $userId", [
$this->auditLogService->log("View with ID: $view->id was deleted", [
'view' => $view->jsonSerialize(),
'userId' => $userId,
]);
}
}
5 changes: 1 addition & 4 deletions lib/Service/RowService.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,7 @@ public function delete(int $id, ?int $viewId, string $userId): Row2 {
try {
$deletedRow = $this->row2Mapper->delete($item);

$event = new RowDeletedEvent(
row: $item,
userId: $userId
);
$event = new RowDeletedEvent(row: $item);

$this->eventDispatcher->dispatchTyped($event);

Expand Down
9 changes: 1 addition & 8 deletions lib/Service/TableService.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,7 @@ public function delete(int $id, ?string $userId = null): Table {
throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': '.$e->getMessage());
}

/*
* Decouple the side logic from the core business logic
* (logging, mail sending, etc.), called handling side effects and most of them can be done asynchronously via queue.
*/
$event = new TableDeletedEvent(
table: $item,
userId: $userId
);
$event = new TableDeletedEvent(table: $item);

$this->eventDispatcher->dispatchTyped($event);

Expand Down
10 changes: 2 additions & 8 deletions lib/Service/ViewService.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,7 @@ public function delete(int $id, ?string $userId = null): View {
try {
$deletedView = $this->mapper->delete($view);

$event = new ViewDeletedEvent(
view: $view,
userId: $userId
);
$event = new ViewDeletedEvent(view: $view);

$this->eventDispatcher->dispatchTyped($event);

Expand Down Expand Up @@ -317,10 +314,7 @@ public function deleteByObject(View $view, ?string $userId = null): View {

$this->mapper->delete($view);

$event = new ViewDeletedEvent(
view: $view,
userId: $userId
);
$event = new ViewDeletedEvent(view: $view);

$this->eventDispatcher->dispatchTyped($event);

Expand Down
6 changes: 2 additions & 4 deletions tests/unit/Listener/WhenRowDeletedAuditLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@ protected function setUp(): void {
public function testHandle(): void {
$row = new Row2();
$row->setId(1);
$userId = 'user1';

$event = new RowDeletedEvent($row, $userId);
$event = new RowDeletedEvent(row: $row);

$this->auditLogService
->expects($this->once())
->method('log')
->with(
$this->equalTo("Row with ID: {$row->getId()} was deleted by user with ID: $userId"),
$this->equalTo("Row with ID: {$row->getId()} was deleted"),
$this->equalTo([
'row' => $row->jsonSerialize(),
'userId' => $userId,
])
);

Expand Down
6 changes: 2 additions & 4 deletions tests/unit/Listener/WhenTableDeletedAuditLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@ protected function setUp(): void {
public function testHandle(): void {
$table = new Table();
$table->id = 1;
$userId = 'user1';

$event = new TableDeletedEvent($table, $userId);
$event = new TableDeletedEvent($table);

$this->auditLogService
->expects($this->once())
->method('log')
->with(
$this->equalTo("Table with ID: {$table->id} was deleted by user with ID: $userId"),
$this->equalTo("Table with ID: {$table->id} was deleted"),
$this->equalTo([
'table' => $table->jsonSerialize(),
'userId' => $userId,
])
);

Expand Down
6 changes: 2 additions & 4 deletions tests/unit/Listener/WhenViewDeletedAuditLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@ protected function setUp(): void {
public function testHandle(): void {
$view = new View();
$view->id = 1;
$userId = 'user1';

$event = new ViewDeletedEvent($view, $userId);
$event = new ViewDeletedEvent(view: $view);

$this->auditLogService
->expects($this->once())
->method('log')
->with(
$this->equalTo("View with ID: {$view->id} was deleted by user with ID: $userId"),
$this->equalTo("View with ID: {$view->id} was deleted"),
$this->equalTo([
'view' => $view->jsonSerialize(),
'userId' => $userId,
])
);

Expand Down

0 comments on commit 76e3395

Please sign in to comment.