Skip to content

Commit

Permalink
Associate activity with user by API key as fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
range-of-motion committed Dec 9, 2023
1 parent 96885de commit 4706ce7
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 2 deletions.
10 changes: 9 additions & 1 deletion app/Events/ImportCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@ class ImportCreated

public function __construct(Import $import)
{
$userId = null;

if (Auth::check()) {
$userId = Auth::user()->id;
} elseif (request()->get('apiKey')) {
$userId = request()->get('apiKey')->user_id;
}

Activity::create([
'space_id' => $import->space_id,
'user_id' => Auth::user()->id,
'user_id' => $userId,
'entity_id' => $import->id,
'entity_type' => 'import',
'action' => 'import.created'
Expand Down
10 changes: 9 additions & 1 deletion app/Events/ImportDeleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@ class ImportDeleted

public function __construct(Import $import)
{
$userId = null;

if (Auth::check()) {
$userId = Auth::user()->id;
} elseif (request()->get('apiKey')) {
$userId = request()->get('apiKey')->user_id;
}

Activity::create([
'space_id' => $import->space_id,
'user_id' => Auth::user()->id,
'user_id' => $userId,
'entity_id' => $import->id,
'entity_type' => 'import',
'action' => 'import.deleted'
Expand Down
2 changes: 2 additions & 0 deletions app/Events/RecurringCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public function __construct(Recurring $recurring)

if (Auth::check()) {
$userId = Auth::user()->id;
} elseif (request()->get('apiKey')) {
$userId = request()->get('apiKey')->user_id;
}

Activity::create([
Expand Down
2 changes: 2 additions & 0 deletions app/Events/RecurringDeleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public function __construct(Recurring $recurring)

if (Auth::check()) {
$userId = Auth::user()->id;
} elseif (request()->get('apiKey')) {
$userId = request()->get('apiKey')->user_id;
}

Activity::create([
Expand Down
2 changes: 2 additions & 0 deletions app/Events/TagCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public function __construct(Tag $tag)

if (Auth::check()) {
$userId = Auth::user()->id;
} elseif (request()->get('apiKey')) {
$userId = request()->get('apiKey')->user_id;
}

Activity::create([
Expand Down
2 changes: 2 additions & 0 deletions app/Events/TagDeleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public function __construct(Tag $tag)

if (Auth::check()) {
$userId = Auth::user()->id;
} elseif (request()->get('apiKey')) {
$userId = request()->get('apiKey')->user_id;
}

Activity::create([
Expand Down
2 changes: 2 additions & 0 deletions app/Events/TransactionCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public function __construct($transaction)

if (Auth::check()) {
$userId = Auth::user()->id;
} elseif (request()->get('apiKey')) {
$userId = request()->get('apiKey')->user_id;
}

if ($transaction instanceof Earning) {
Expand Down
2 changes: 2 additions & 0 deletions app/Events/TransactionDeleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public function __construct($transaction)

if (Auth::check()) {
$userId = Auth::user()->id;
} elseif (request()->get('apiKey')) {
$userId = request()->get('apiKey')->user_id;
}

if ($transaction instanceof Earning) {
Expand Down

0 comments on commit 4706ce7

Please sign in to comment.