Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Jan 29, 2025
2 parents d9fbb36 + 67006de commit 2474362
Show file tree
Hide file tree
Showing 34 changed files with 545 additions and 177 deletions.
1 change: 0 additions & 1 deletion app/Concerns/Enums/Comparable.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ trait Comparable
*/
public function is(mixed $enum): bool
{

if ($enum instanceof static) {
return $this->value === $enum->value;
}
Expand Down
48 changes: 48 additions & 0 deletions app/Console/Commands/EndProjectPeriod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Models\Project;
use App\Notifications\Ngo\ProjectEndingNotification;
use Illuminate\Console\Command;

class EndProjectPeriod extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:notification-end-project-period {--days=7}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Notify users that a project is ending in a number of days';

/**
* Execute the console command.
*/
public function handle(): void
{
$this->info('Ending project period...');
$daysBeforeEnding = (int) $this->option('days') ?? 7;
$this->info("Ending period {$daysBeforeEnding}...");
$projects = Project::withoutEagerLoads()->with(['organization'])
->whereIsApproved()
->whereDate('end', now()->addDays($daysBeforeEnding))
->get();
$projects->each(function (Project $project) use ($daysBeforeEnding) {

$users = $project->organization->load('users')->users->filter(function ($user) {
return $user->hasVerifiedEmail();
});
\Notification::send($users, new ProjectEndingNotification($project, $daysBeforeEnding));

});
}
}
10 changes: 10 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ protected function schedule(Schedule $schedule): void
->everyFourHours()
->onOneServer()
->sentryMonitor('process-authorized-transactions-job');

$schedule->command('app:notification-end-project-period', ['--days' => 10])
->dailyAt('09:00')
->onOneServer()
->sentryMonitor('notification-end-project-period');

$schedule->command('app:notification-end-project-period', ['--days' => 2])
->dailyAt('10:00')
->onOneServer()
->sentryMonitor('notification-end-project-period');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ protected function setUp(): void
if (! $media) {
return '-';
}

return new HtmlString(\sprintf(
'<a href="%s" target="_blank">%s</a>',
$media->getTemporaryUrl(now()->addMinutes(30)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Resources\ProjectResource\Widgets;

use App\Filament\Resources\ProjectResource;
use App\Filament\Resources\ProjectResource\Actions\Tables\Projects\RejectProjectAction;
use App\Models\Project;
use Filament\Tables\Actions\EditAction;
Expand Down Expand Up @@ -58,6 +59,7 @@ protected function getTableActions(): array
->iconButton()
->url($this->getTableRecordUrlUsing()),
EditAction::make()
->url(fn (Project $record) => ProjectResource::getUrl('edit', ['record' => $record]))
->iconButton(),
RejectProjectAction::make()
->iconButton(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ protected function getTableActions(): array
ViewAction::make()->label(__('project.actions.view'))
->iconButton()
->url($this->getTableRecordUrlUsing()),
EditAction::make()
EditAction::make('edit')
->url(fn (Project $record) => ProjectResource::getUrl('edit', ['record' => $record]))
->iconButton(),
ApproveProjectAction::make()
->iconButton(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Resources\ProjectResource\Widgets;

use App\Filament\Resources\ProjectResource;
use App\Filament\Resources\ProjectResource\Actions\Tables\Projects\ApproveProjectAction;
use App\Models\Project;
use Filament\Tables\Actions\EditAction;
Expand Down Expand Up @@ -55,6 +56,7 @@ protected function getTableActions(): array
->iconButton()
->url($this->getTableRecordUrlUsing()),
EditAction::make()
->url(fn (Project $record) => ProjectResource::getUrl('edit', ['record' => $record]))
->iconButton(),
ApproveProjectAction::make()
->iconButton(),
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Widgets/BaseDonationWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function getChartData(
)
->where('created_at', '>', $whereCreatedCondition)
// TODO: add CAPTURE after pr #348
->whereIn('status', [EuPlatescStatus::AUTHORIZED])
->whereIn('status', [EuPlatescStatus::AUTHORIZED->value, EuPlatescStatus::CHARGED->value])
->groupBy($chartInterval)
->orderBy($chartInterval)
->get();
Expand Down
12 changes: 6 additions & 6 deletions app/Http/Controllers/Auth/PasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public function update(Request $request): RedirectResponse
'password' => [
'required',
Password::min(8)
->mixedCase()
->letters()
->numbers()
->symbols()
->uncompromised(),
'confirmed'
->mixedCase()
->letters()
->numbers()
->symbols()
->uncompromised(),
'confirmed',
],
]);

Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Dashboard/VolunteerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Http\Controllers\Controller;
use App\Http\Resources\Collections\VolunteerCollection;
use App\Models\VolunteerRequest;
use App\Notifications\UserWasApprovedForVolunteering;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Spatie\QueryBuilder\QueryBuilder;
Expand Down Expand Up @@ -41,6 +42,7 @@ public function approve(Request $request, VolunteerRequest $volunteerRequest)
{
$this->authorize('update', $volunteerRequest);
$volunteerRequest->markAsApproved();
\Notification::send($volunteerRequest->volunteer->user, new UserWasApprovedForVolunteering());

return redirect()->back()
->with('success', __('volunteer.messages.approved'));
Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/Dashboard/WelcomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public function store(Request $request, User $user): RedirectResponse
$attributes = $request->validate([
'password' => ['required', 'confirmed',
Password::min(8)
->mixedCase()
->letters()
->numbers()
->symbols()
->uncompromised(),],
->mixedCase()
->letters()
->numbers()
->symbols()
->uncompromised(), ],
]);

$user->setPassword($attributes['password']);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/DonationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public function euPlatescCallback(EuPlatescRequest $request, Donation $donation)

(new EuPlatescService($donation->organization_id))->processIpn($donation, $validatedData);

echo "OK";//IMPORTANT to print OK
echo 'OK'; //IMPORTANT to print OK
}
}
1 change: 0 additions & 1 deletion app/Http/Controllers/NewsletterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class NewsletterController extends Controller
{

public function __invoke(Request $request)
{
$attributes = $request->validate([
Expand Down
12 changes: 3 additions & 9 deletions app/Http/Filters/DonationDatesFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@

namespace App\Http\Filters;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Spatie\QueryBuilder\Filters\Filter;

class DonationDatesFilter implements Filter
{
public function __invoke(Builder $query, $dates, string $property): void
{
if (! empty($dates[0])) {
$start = Carbon::createFromFormat('Y-m', $dates[0])->startOfDay();
$query->whereDate('created_at', '>=', $start);
}
if (! empty($dates[1])) {
$end = Carbon::createFromFormat('Y-m', $dates[1])->endOfDay();
$query->whereDate('created_at', '<=', $end);
}
[$start, $end] = $dates;
$query->whereDate('created_at', '>=', $start)
->whereDate('created_at', '<=', $end);
}
}
24 changes: 13 additions & 11 deletions app/Http/Requests/Donations/EuPlatescRequest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests\Donations;

use Illuminate\Foundation\Http\FormRequest;
Expand All @@ -23,17 +25,17 @@ public function authorize(): bool
public function rules(): array
{
return [
'amount' => ['required', 'decimal:2'],
'curr' => ['required', 'string'],
'amount' => ['required', 'decimal:2'],
'curr' => ['required', 'string'],
'invoice_id' => ['required', 'string'],
'ep_id' => ['required', 'string'],
'merch_id' => ['required', 'string'],
'action' => ['required', 'numeric', Rule::in(0, 1)],
'message' => ['required', 'string'],
'approval' => ['required', 'string'],
'timestamp' => ['required', 'date_format:YmdHis'],
'nonce' => ['required', 'string'],
'fp_hash' => ['required', 'string'],
'ep_id' => ['required', 'string'],
'merch_id' => ['required', 'string'],
'action' => ['required', 'numeric', Rule::in(0, 1)],
'message' => ['required', 'string'],
'approval' => ['required', 'string'],
'timestamp' => ['required', 'date_format:YmdHis'],
'nonce' => ['required', 'string'],
'fp_hash' => ['required', 'string'],
'sec_status' => ['nullable', 'numeric'],
'rrn' => ['nullable', 'numeric'],
'mcard' => ['nullable', 'numeric'],
Expand All @@ -45,7 +47,7 @@ public function rules(): array
'card_holder' => ['nullable', 'string'],
'email' => ['nullable', 'string'],
'rtype' => ['nullable', 'string'],
'cce' => ['nullable', 'string']
'cce' => ['nullable', 'string'],
];
}
}
41 changes: 35 additions & 6 deletions app/Http/Requests/Project/EditRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@
namespace App\Http\Requests\Project;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;

class EditRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
*/
protected function prepareForValidation(): void
{
if ($this->has('external_links')) {
$this->merge([
'external_links' => $this->appendHttpsToUrl($this->external_links),
]);
}

if ($this->has('videos')) {
$this->merge([
'videos' => $this->appendHttpsToUrl($this->videos),
]);
}
}

public function rules(): array
{
return [
Expand All @@ -37,7 +48,10 @@ public function rules(): array
'external_links.*.url' => ['required', 'url'],
'is_national' => ['boolean', 'nullable'],
'gallery' => ['array', 'nullable'],
'gallery.*.file' => ['nullable', 'image', 'max:5120'],
// TODO to check how we can validate this. Problema e ca validate nu stie sa ia mix intre File si array
// 'gallery.*.file' => ['nullable', 'image', 'max:5120'],
// 'gallery.*.id' => ['nullable', 'exists:media,id'],
// 'gallery.*.url' => ['nullable', 'string'],
'image' => ['nullable', 'image', 'max:5120'],
];
}
Expand All @@ -52,4 +66,19 @@ public function messages(): array
'gallery.*.file.max' => __('custom_validation.image.size'),
];
}

private function appendHttpsToUrl(array $data): array
{
return collect($data)->map(function ($item) {
if (! filled($item['url'])) {
return $item;
}
if (Str::isUrl($item['url'])) {
return $item;
}
$item['url'] = 'https://' . $item['url'];

return $item;
})->toArray();
}
}
1 change: 0 additions & 1 deletion app/Http/Resources/GalaProject/ShowResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,4 @@ public function toArray(Request $request): array

];
}

}
14 changes: 14 additions & 0 deletions app/Jobs/CaptureAuthorizedDonationJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use App\Enums\EuPlatescStatus;
use App\Models\Donation;
use App\Models\User;
use App\Notifications\Ngo\DonationReceived;
use App\Notifications\UserDonationReceived;
use App\Services\EuPlatescService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
Expand Down Expand Up @@ -53,6 +56,17 @@ public function handle(): void
'status' => EuPlatescStatus::CHARGED,
'status_updated_at' => now(),
]);
$userInstanceOfDonner = new User([
'email' => $this->donation->email,
'name' => $this->donation->first_name . ' ' . $this->donation->last_name,
]);
\Notification::send($userInstanceOfDonner, new UserDonationReceived($this->donation));
$organizationsUsers = $this->donation->load('organization')
->organization->load('users')->users->filter(function ($user) {
return $user->hasVerifiedEmail();
});

\Notification::send($organizationsUsers, new DonationReceived());
}
}
}
2 changes: 2 additions & 0 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ public function markAsApproved(): bool
$slug .= '-' . ($count + 1);
}

$this->activities->map(fn (Activity $activity) => $activity->approve());

return $this->update([
'status' => ProjectStatus::approved,
'status_updated_at' => $this->freshTimestamp(),
Expand Down
Loading

0 comments on commit 2474362

Please sign in to comment.