Skip to content

Commit

Permalink
fix policy for org
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Oct 20, 2023
1 parent a2427e2 commit cc7e129
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/Filament/Resources/VolunteerResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private static function getProjectLink(VolunteerRequest $record): HtmlString
{
if ($record->model_type === 'App\Models\Project') {
$url = route('filament.resources.projects.view', $record->model_id);
$name = Str::words($record->model?->name, 3, '...');
$name = Str::words($record->model->name, 3, '...');

return new HtmlString(sprintf('<a href="%s">%s</a>', $url, $name));
}
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/OrganizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public function index(Request $request)

public function show(Organization $organization)
{
$this->authorize('view', $organization);

return Inertia::render('Public/Organizations/Show', [
'organization' => new ShowOrganizationResource(
$organization->loadMissing([
Expand Down
7 changes: 6 additions & 1 deletion app/Policies/OrganizationPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Policies;

use App\Enums\OrganizationStatus;
use App\Models\Organization;
use App\Models\User;

Expand All @@ -24,7 +25,11 @@ public function viewAny(User $user): bool
public function view(User $user, Organization $organization): bool
{
/* Anyone can see the details of an organization. */
return true;
if ($organization->isActive())
{
return true;
}
return $user->isSuperUser() || $user->isOrganizationAdmin($organization);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion config/filament.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
'footer' => [
'should_show_logo' => false,
],
'max_content_width' => null,
'max_content_width' => 'full',
'notifications' => [
'vertical_alignment' => 'top',
'alignment' => 'right',
Expand Down
8 changes: 4 additions & 4 deletions database/factories/OrganizationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ public function configure(): static
->count(2)
->hasAttached(
Volunteer::factory()
->count(17),
->count(1),
fn () => [
'status' => fake()->randomElement(VolunteerStatus::cases()),
]
)
->hasAttached(
Volunteer::factory()
->withUser()
->count(3),
->count(2),
fn () => [
'status' => fake()->randomElement(VolunteerStatus::cases()),
]
Expand All @@ -143,14 +143,14 @@ public function configure(): static

$organization->volunteers()->attach(
Volunteer::factory()
->count(10)
->count(1)
->create(),
['status' => VolunteerStatus::PENDING]
);

$organization->volunteers()->attach(
Volunteer::factory()
->count(10)
->count(1)
->withUser()
->create(),
['status' => VolunteerStatus::PENDING]
Expand Down
6 changes: 3 additions & 3 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function run(): void
->create();

User::factory()
->count(50)
->count(5)
->donor()
->create();

Expand All @@ -65,12 +65,12 @@ public function run(): void
->create();

Organization::factory()
->count(5)
->count(1)
->rejected()
->create();

Organization::factory()
->count(5)
->count(1)
->pending()
->create();

Expand Down
4 changes: 2 additions & 2 deletions resources/js/Pages/Public/Organizations/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@
<div>
<h3 class="text-base font-semibold text-gray-600">{{ $t('ong_address') }}</h3>
<p class="mt-2 text-base font-normal text-gray-500">
{{ organization.street_address }}, <br />
{{ organization.county_name }}, {{ organization.city_name }}
{{ organization.street_address }}<br/> {{ organization.location }} <br />

</p>
</div>
</div>
Expand Down

0 comments on commit cc7e129

Please sign in to comment.