Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Custom Auth Guard For The Export And The Import Classes. #15404

Closed
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
2 changes: 1 addition & 1 deletion packages/actions/src/Concerns/CanExportRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected function setUp(): void
return;
}

$user = auth()->user();
$user = auth(Export::getAuthGuard())->user();

if ($action->hasColumnMapping()) {
$columnMap = collect($data['columnMap'])
Expand Down
16 changes: 8 additions & 8 deletions packages/actions/src/Concerns/CanImportRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ protected function setUp(): void

$set('columnMap', array_reduce($action->getImporter()::getColumns(), function (array $carry, ImportColumn $column) use ($lowercaseCsvColumnKeys, $lowercaseCsvColumnValues) {
$carry[$column->getName()] = $lowercaseCsvColumnKeys[
Arr::first(
array_intersect(
$lowercaseCsvColumnValues,
$column->getGuesses(),
),
)
Arr::first(
array_intersect(
$lowercaseCsvColumnValues,
$column->getGuesses(),
),
)
] ?? null;

return $carry;
Expand Down Expand Up @@ -212,7 +212,7 @@ protected function setUp(): void
return;
}

$user = auth()->user();
$user = auth(Import::getAuthGuard())->user();

$import = app(Import::class);
$import->user()->associate($user);
Expand Down Expand Up @@ -309,7 +309,7 @@ protected function setUp(): void
)
->when(
($jobConnection === 'sync') ||
(blank($jobConnection) && (config('queue.default') === 'sync')),
(blank($jobConnection) && (config('queue.default') === 'sync')),
fn (Notification $notification) => $notification
->persistent()
->send(),
Expand Down
12 changes: 12 additions & 0 deletions packages/actions/src/Exports/Models/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Export extends Model

protected static bool $hasPolymorphicUserRelationship = false;

protected static ?string $authGuard = null;

public function user(): BelongsTo
{
if (static::hasPolymorphicUserRelationship()) {
Expand Down Expand Up @@ -89,6 +91,16 @@ public static function hasPolymorphicUserRelationship(): bool
return static::$hasPolymorphicUserRelationship;
}

public static function useAuthGuard(?string $authGuard = null): void
{
static::$authGuard = $authGuard;
}

public static function getAuthGuard(): ?string
{
return static::$authGuard;
}

public function getFileDisk(): Filesystem
{
return Storage::disk($this->file_disk);
Expand Down
12 changes: 12 additions & 0 deletions packages/actions/src/Imports/Models/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class Import extends Model

protected static bool $hasPolymorphicUserRelationship = false;

protected static ?string $authGuard = null;

public function failedRows(): HasMany
{
return $this->hasMany(app(FailedImportRow::class)::class);
Expand Down Expand Up @@ -94,4 +96,14 @@ public static function hasPolymorphicUserRelationship(): bool
{
return static::$hasPolymorphicUserRelationship;
}

public static function useAuthGuard(?string $authGuard = null): void
{
static::$authGuard = $authGuard;
}

public static function getAuthGuard(): ?string
{
return static::$authGuard;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export default (Alpine) => {
// Calling `el.getBoundingClientRect()` from outside `requestAnimationFrame()` can
// occasionally cause the page to scroll to the top.
requestAnimationFrame(() => {
const getTop = () => this.$el.getBoundingClientRect().top
const getTop = () =>
this.$el.getBoundingClientRect().top
const oldTop = getTop()

respond(() => {
Expand All @@ -105,7 +106,7 @@ export default (Alpine) => {
oldTop - getTop()
}px)`,
},
{transform: 'translateY(0px)'},
{ transform: 'translateY(0px)' },
],
{
duration: this.transitionDuration,
Expand Down