Skip to content

Commit

Permalink
fixes (#345)
Browse files Browse the repository at this point in the history
* refactor: project policy and form requests

* update to php 8.2

* add volunteer request policy

* formatting

* enable secure cookie flag

* style
  • Loading branch information
andreiio authored Feb 12, 2024
1 parent 0ebc2e6 commit d9dd32f
Show file tree
Hide file tree
Showing 62 changed files with 283 additions and 160 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
#SESSION_SECURE_COOKIE=true

REDIS_HOST=redis
REDIS_PASSWORD=
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.1-fpm-alpine AS vendor
FROM php:8.2-fpm-alpine AS vendor

ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /tmp
Expand Down
4 changes: 3 additions & 1 deletion app/Filament/Exports/ExcelExportWithNotificationInDB.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Filament\Exports;

use App\Notifications\Admin\ExportExcelNotification;
Expand All @@ -20,7 +22,7 @@ public function export()

$this->prepareQueuedExport();

$filename = Str::uuid().'-'.$this->getFilename();
$filename = Str::uuid() . '-' . $this->getFilename();
$authUser = auth()->user();

$this
Expand Down
2 changes: 2 additions & 0 deletions app/Filament/Filters/DateFilter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Filament\Filters;

use Carbon\Carbon;
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Resources/Articles/ArticleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static function table(Table $table): Table
->multiple()
->relationship('category', 'name')
->label(__('article.filter.category')),
DateFilter::make('created_at')
DateFilter::make('created_at'),
])
->actions([
Tables\Actions\EditAction::make()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ protected function getActions(): array

protected function getTableHeading(): string
{
return __('article.header.article', ['number' => Article::count()]) ;
return __('article.header.article', ['number' => Article::count()]);
}
}
2 changes: 1 addition & 1 deletion app/Filament/Resources/Articles/CategoryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static function table(Table $table): Table
->sortable(),
])
->filters([
DateFilter::make('updated_at')
DateFilter::make('updated_at'),
])
->actions([
Tables\Actions\EditAction::make()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ protected function getActions(): array

protected function getTableHeading(): string
{
return __('article.header.category', ['number' => ArticleCategory::count()]) ;
return __('article.header.category', ['number' => ArticleCategory::count()]);
}
}
2 changes: 1 addition & 1 deletion app/Filament/Resources/BCRProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static function table(Table $table): Table
return $table
->columns([
TextColumn::make('id')
->formatStateUsing(function (BcrProject $record) {
->formatStateUsing(function (BCRProject $record) {
return sprintf('#%d', $record->id);
})
->label(__('bcr-project.labels.id'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ protected function getActions(): array

protected function getTableHeading(): string
{
return __('bcr-project.header', ['number' => BCRProject::count()]) ;
return __('bcr-project.header', ['number' => BCRProject::count()]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ protected function getActions(): array

protected function getTableHeading(): string
{
return __('badge.header.category_badge', ['number' => BadgeCategory::count()]) ;
return __('badge.header.category_badge', ['number' => BadgeCategory::count()]);
}
}
2 changes: 1 addition & 1 deletion app/Filament/Resources/BadgeResource/Pages/ListBadges.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ protected function getTableQuery(): Builder

protected function getTableHeading(): string
{
return __('badge.header.badge', ['number' => Badge::count()]) ;
return __('badge.header.badge', ['number' => Badge::count()]);
}
}
2 changes: 1 addition & 1 deletion app/Filament/Resources/DonationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static function table(Table $table): Table
true: fn (Builder $query) => $query->whereHas('championshipStage'),
false: fn (Builder $query) => $query->whereDoesntHave('championshipStage'),
),
DateFilter::make('created_at')
DateFilter::make('created_at'),
])
->actions([
ViewAction::make()->iconButton(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ protected function getActions(): array

protected function getTableHeading(): string
{
return __('donation.header', ['number' => Donation::count()]) ;
return __('donation.header', ['number' => Donation::count()]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function getTableHeading(): string
protected function getTableQuery(): Builder
{
return parent::getTableQuery()
->isPendingChanges()
->isPendingChanges()
->withCount([
'activities' => fn (Builder $query) => $query->wherePending(),
])
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Resources/PageResource/Pages/ListPages.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ protected function getActions(): array

protected function getTableHeading(): string
{
return __('pages.header', ['number' => Page::count()]) ;
return __('pages.header', ['number' => Page::count()]);
}
}
22 changes: 9 additions & 13 deletions app/Filament/Resources/ProjectResource/Actions/ExportAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,18 @@ function (Builder $query) use ($name) {
),

Column::make('counties')
->heading(__('project.labels.counties'))
->heading(__('project.labels.counties'))
->formatStateUsing(
fn (Project $record) =>
$record->counties->map(fn (County $county) => $county->name)
->join(', ')
fn (Project $record) => $record->counties->map(fn (County $county) => $county->name)
->join(', ')
),

Column::make('category')
->heading(__('project.labels.category'))
->formatStateUsing(
fn (Project $record, $state) =>
$record->categories->map(fn (ProjectCategory $category) => $category->name)
->formatStateUsing(
fn (Project $record, $state) => $record->categories->map(fn (ProjectCategory $category) => $category->name)
->join(', ')
),
),

Column::make('description')
->heading(__('project.labels.description')),
Expand Down Expand Up @@ -139,20 +137,18 @@ function (Builder $query) use ($name) {
Column::make('donation_number')
->heading(__('donation.labels.count'))
->formatStateUsing(
fn (Project $record) =>
$record->donations->count()
fn (Project $record) => $record->donations->count()
),

Column::make('donation_amount')
->heading(__('donation.labels.amount'))
->formatStateUsing(
fn (Project $record) =>
$record->donations
fn (Project $record) => $record->donations
->map(fn (Donation $donation) => $donation->amount)
->sum()
),
])
->queue(),
->queue(),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected function paginateTableQuery(Builder $query): Paginator
protected function getTableHeaderActions(): array
{
return [
ProjectResource\Actions\ExportAction::make($this->getTableQueryStringIdentifier())
ProjectResource\Actions\ExportAction::make($this->getTableQueryStringIdentifier()),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ protected function getTableFilters(): array

protected function getTableHeading(): string
{
return __('ticket.header.close', ['number' => Ticket::query()->whereClosed()->count()]) ;
return __('ticket.header.close', ['number' => Ticket::query()->whereClosed()->count()]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ protected function getTableFilters(): array

protected function getTableHeading(): string
{
return __('ticket.header.open', ['number' => Ticket::query()->whereOpen()->count()]) ;
return __('ticket.header.open', ['number' => Ticket::query()->whereOpen()->count()]);
}
}
6 changes: 2 additions & 4 deletions app/Filament/Resources/UserResource/Actions/ExportAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ protected function setUp(): void
Column::make('newsletter_subscription')
->heading(__('user.labels.newsletter_subscription'))
->formatStateUsing(
fn (User $record) =>
$record->newsletter ?
fn (User $record) => $record->newsletter ?
$record->created_at->toFormattedDateTime() :
''
),
Expand All @@ -92,8 +91,7 @@ protected function setUp(): void
Column::make('last_donation_date')
->heading(__('user.labels.last_donation_date'))
->formatStateUsing(
fn (User $record) =>
$record->donations_count ?
fn (User $record) => $record->donations_count ?
$record->donations
->reject(fn ($item) => $item->status === EuPlatescStatus::CHARGED)
->last()?->created_at->toFormattedDateTime() : ''
Expand Down
16 changes: 9 additions & 7 deletions app/Filament/Resources/UserResource/Actions/ToggleUserAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,29 @@ protected function setUp(): void
{
parent::setUp();

$this->color(fn(User $record) => $record->email_verified_at ? 'danger' : 'success');
$this->color(fn (User $record) => $record->email_verified_at ? 'danger' : 'success');

$this->icon(fn(User $record) => $record->email_verified_at ? 'heroicon-s-x' : 'heroicon-s-check');
$this->icon(fn (User $record) => $record->email_verified_at ? 'heroicon-s-x' : 'heroicon-s-check');

$this->requiresConfirmation();

$this->modalHeading(function (User $record) {
return __('user.toggle_modal.heading', [
'name' => $record->name,
]);
});
return __('user.toggle_modal.heading', [
'name' => $record->name,
]);
});

$this->modalSubheading(function (User $record) {
$this->modalSubheading(function (User $record) {
$status = (bool) $this->record?->email_verified_at;
$key = sprintf('user.toggle_modal.subheading.%s', $status ? 'deactivate' : 'active');

return __($key, ['name' => $record->name]);
});

$this->modalButton(function (User $record) {
$status = (bool) $record->email_verified_at;
$key = sprintf('user.toggle_modal.actions.%s', $status ? 'deactivate' : 'active');

return __($key);
});

Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Resources/UserResource/Pages/ListUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ protected function getActions(): array

protected function getTableHeading(): string
{
return __('user.header', ['number' => User::count()]) ;
return __('user.header', ['number' => User::count()]);
}
}
2 changes: 1 addition & 1 deletion app/Filament/Resources/VolunteerResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static function table(Table $table): Table
fn (Builder $query) => $query->whereNull('user_id')
),
),
DateFilter::make('created_at')
DateFilter::make('created_at'),

])
->actions([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class ListVolunteers extends ListRecords

protected function getTableHeading(): string
{
return __('volunteer.header', ['number' => Volunteer::count()]) ;
return __('volunteer.header', ['number' => Volunteer::count()]);
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/NewPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function create(Request $request): Response
/**
* Handle an incoming new password request.
*
* @throws \Illuminate\Validation\ValidationException
* @throws ValidationException
*/
public function store(Request $request): RedirectResponse
{
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/PasswordResetLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function create(): Response
/**
* Handle an incoming password reset link request.
*
* @throws \Illuminate\Validation\ValidationException
* @throws ValidationException
*/
public function store(Request $request): RedirectResponse
{
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function store(RegistrationRequest $request): RedirectResponse
$user->save();
}

if ($subscribe && !blank(config('newsletter.driver_arguments.api_key'))) {
if ($subscribe && ! blank(config('newsletter.driver_arguments.api_key'))) {
NewsletterService::subscribe($user->email, $user->name);
}

Expand Down
19 changes: 15 additions & 4 deletions app/Http/Controllers/Dashboard/DonationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,26 @@ class DonationController extends Controller
{
public function index(Request $request): Response
{
$donations = auth()->user()->organization->donations()->with(['project:id,name,organization_id', 'organization:id,name'])->get();
$organizations = collect([]);
$projects = collect([]);
$donations = auth()->user()->organization
->donations()
->with([
'project:id,name,organization_id',
'organization:id,name',
])
->get();

$organizations = collect();
$projects = collect();

$donations->map(function ($donation) use (&$organizations, &$projects) {
$organizations->push($donation->project->organization);
$projects->push($donation->project);
});
$dates = $donations->pluck('created_at')->map(fn ($date) => $date->format('Y-m'))->unique();

$dates = $donations
->pluck('created_at')
->map(fn ($date) => $date->format('Y-m'))
->unique();

return Inertia::render('AdminOng/Donations/Index', [
'filter' => $request->query('filter'),
Expand Down
Loading

0 comments on commit d9dd32f

Please sign in to comment.