Skip to content

Commit

Permalink
fix: unpublishing a users public page may return a 404 error (resolves
Browse files Browse the repository at this point in the history
  • Loading branch information
jobara authored Nov 19, 2024
1 parent 1007fd7 commit 979d750
Show file tree
Hide file tree
Showing 13 changed files with 386 additions and 206 deletions.
6 changes: 5 additions & 1 deletion app/Http/Controllers/IndividualController.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,11 @@ public function updatePublicationStatus(Request $request, Individual $individual
$individual->publish();
}

return redirect(localized_route('individuals.show', $individual));
if ($individual->isPreviewable()) {
return redirect(localized_route('individuals.show', $individual));
} else {
return redirect(localized_route('dashboard'));
}
}

public function destroy(DestroyIndividualRequest $request, Individual $individual): RedirectResponse
Expand Down
6 changes: 5 additions & 1 deletion app/Http/Controllers/OrganizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,11 @@ public function updatePublicationStatus(Request $request, Organization $organiza
$organization->publish();
}

return redirect(localized_route('organizations.show', $organization));
if ($organization->isPreviewable()) {
return redirect(localized_route('organizations.show', $organization));
} else {
return redirect(localized_route('dashboard'));
}
}

public function destroy(DestroyOrganizationRequest $request, Organization $organization): RedirectResponse
Expand Down
2 changes: 1 addition & 1 deletion resources/views/organizations/partials/about.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
@endforeach
</ul>

@if ($organization->isConsultant())
@if ($organization->isConsultant() && $organization->consulting_services)
<h3>{{ __('Consulting services') }}</h3>
<x-interpretation name="{{ __('Consulting services', [], 'en') }}" />
<p>{{ __('As an Accessibility Consultant, we can help with:') }}</p>
Expand Down
3 changes: 2 additions & 1 deletion tests/Datasets/AddOrganizationValidationErrors.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Enums\OrganizationRole;
use App\Models\Organization;

dataset('addOrganizationValidationErrors', function () {
Expand All @@ -15,7 +16,7 @@
'Organization is not a participant' => [
'state' => fn () => ['organization_id' => Organization::factory()->create([
'name' => 'not a participant org',
'roles' => ['connector'],
'roles' => [OrganizationRole::CommunityConnector->value],
])->id],
'errors' => fn () => ['organization_id' => __('The organization you have added does not participate in engagements.')],
],
Expand Down
34 changes: 24 additions & 10 deletions tests/Datasets/EngagementIsPublishable.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<?php

use App\Enums\AcceptedFormat;
use App\Enums\EngagementFormat;
use App\Enums\EngagementRecruitment;
use App\Enums\MeetingType;
use App\Enums\ProvinceOrTerritory;

dataset('engagementIsPublishable', function () {
$baseModel = [
'name' => ['en' => 'Workshop'],
'languages' => ['en', 'fr', 'asl', 'sql'],
'who' => 'individuals',
'format' => 'workshop',
'recruitment' => 'open-call',
'format' => EngagementFormat::Workshop->value,
'recruitment' => EngagementRecruitment::OpenCall->value,
'ideal_participants' => 25,
'minimum_participants' => 15,
'paid' => true,
Expand All @@ -15,7 +21,7 @@
];

$interviewModel = array_merge($baseModel, [
'format' => 'interviews',
'format' => EngagementFormat::Interviews->value,
'window_start_date' => '2022-11-01',
'window_end_date' => '2022-11-15',
'window_start_time' => '09:00',
Expand All @@ -30,28 +36,36 @@
'saturday' => 'no',
'sunday' => 'no',
],
'meeting_types' => ['in_person', 'web_conference', 'phone'],
'meeting_types' => [
MeetingType::InPerson->value,
MeetingType::WebConference->value,
MeetingType::Phone->value,
],
'street_address' => '1223 Main Street',
'locality' => 'Anytown',
'region' => 'ON',
'region' => ProvinceOrTerritory::Ontario->value,
'postal_code' => 'M46 17B',
'meeting_software' => 'WebMeetingApp',
'meeting_url' => 'https://example.com/meet',
'meeting_phone' => '6476231847',
'materials_by_date' => '2022-11-01',
'complete_by_date' => '2022-11-15',
'accepted_formats' => ['writing', 'audio', 'video'],
'accepted_formats' => [
AcceptedFormat::Writing->value,
AcceptedFormat::Audio->value,
AcceptedFormat::Video->value,
],
]);

$surveyModel = array_merge($baseModel, [
'format' => 'survey',
'format' => EngagementFormat::Survey->value,
'materials_by_date' => '2022-11-01',
'complete_by_date' => '2022-11-15',
'document_languages' => ['en', 'fr'],
]);

$otherAsyncModel = array_merge($baseModel, [
'format' => 'other-async',
'format' => EngagementFormat::OtherAsync->value,
'materials_by_date' => '2022-11-01',
'complete_by_date' => '2022-11-15',
'document_languages' => ['en', 'fr'],
Expand Down Expand Up @@ -100,13 +114,13 @@
],
'not publishable when focus group and missing meeting' => [
false,
array_replace_recursive($baseModel, ['format' => 'focus-group']),
array_replace_recursive($baseModel, ['format' => EngagementFormat::FocusGroup->value]),
false,
true,
],
'not publishable when other synchronous and missing meeting' => [
false,
array_replace_recursive($baseModel, ['format' => 'other-sync']),
array_replace_recursive($baseModel, ['format' => EngagementFormat::OtherSync->value]),
false,
true,
],
Expand Down
14 changes: 10 additions & 4 deletions tests/Datasets/IndividualIsInProgress.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

use App\Enums\CommunityConnectorHasLivedExperience;
use App\Enums\ConsultingService;
use App\Enums\MeetingType;
use App\Enums\ProvinceOrTerritory;
use Illuminate\Support\Arr;

dataset('individualIsInProgress', function () {
Expand Down Expand Up @@ -31,12 +34,12 @@
$filledData = [
'pronouns' => ['she', 'her'],
'bio' => 'This is my bio',
'region' => 'NS',
'region' => ProvinceOrTerritory::NovaScotia->value,
'locality' => 'Halifax',
'working_languages' => ['en'],
'consulting_services' => [
'designing-consultation',
'running-consultation',
ConsultingService::DesigningConsultation->value,
ConsultingService::RunningConsultation->value,
],
'social_links' => [
'linked_in' => 'https://linkedin.com/in/someone',
Expand All @@ -56,7 +59,10 @@
'current' => 1,
],
],
'meeting_types' => ['in_person', 'web_conference'],
'meeting_types' => [
MeetingType::InPerson->value,
MeetingType::WebConference->value,
],
'extra_attributes' => ['cross_disability_and_deaf_connections' => 1],
];

Expand Down
13 changes: 8 additions & 5 deletions tests/Datasets/OrganizationIsInProgress.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

use App\Enums\ConsultingService;
use App\Enums\ProvinceOrTerritory;
use App\Enums\StaffHaveLivedExperience;
use Illuminate\Support\Arr;

dataset('organizationIsInProgress', function () {
Expand All @@ -23,21 +26,21 @@
];

$filledData = [
'region' => 'NS',
'region' => ProvinceOrTerritory::NovaScotia->value,
'locality' => 'Halifax',
'about' => 'About this org',
'service_areas' => ['NS'],
'service_areas' => [ProvinceOrTerritory::NovaScotia->value],
'consulting_services' => [
'designing-consultation',
'running-consultation',
ConsultingService::DesigningConsultation->value,
ConsultingService::RunningConsultation->value,
],
'social_links' => [
'linked_in' => 'https://linkedin.com/in/someone',
],
'website_link' => 'https://example.com',
'other_disability_constituency' => 'Something not listed',
'other_ethnoracial_identity_constituency' => 'Something else',
'staff_lived_experience' => 'prefer-not-to-answer',
'staff_lived_experience' => StaffHaveLivedExperience::PreferNotToAnswer->value,
'extra_attributes' => ['disability_and_deaf_constituencies' => 1],
];

Expand Down
5 changes: 3 additions & 2 deletions tests/Datasets/OrganizationIsPublishable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use App\Enums\ConsultingService;
use App\Enums\OrganizationRole;
use App\Enums\ProvinceOrTerritory;
use App\Enums\StaffHaveLivedExperience;

dataset('organizationIsPublishable', function () {
$baseModel = [
Expand All @@ -12,10 +13,10 @@
'contact_person_phone' => '4165555555',
'locality' => 'Toronto',
'preferred_contact_method' => 'email',
'region' => 'ON',
'region' => ProvinceOrTerritory::Ontario->value,
'roles' => [OrganizationRole::AccessibilityConsultant],
'service_areas' => [ProvinceOrTerritory::Ontario->value],
'staff_lived_experience' => 'yes',
'staff_lived_experience' => StaffHaveLivedExperience::Yes->value,
];

return [
Expand Down
4 changes: 3 additions & 1 deletion tests/Datasets/UpdateIndividualRequestValidationErrors.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use App\Enums\ConsultingService;

dataset('updateIndividualRequestValidationErrors', function () {
return array_map('array_values', [
'Missing name' => [
Expand Down Expand Up @@ -63,7 +65,7 @@
fn () => ['working_languages' => __('validation.array', ['attribute' => __('Working languages')])],
],
'Consulting services not an array' => [
['consulting_services' => 'analysis'],
['consulting_services' => ConsultingService::Analysis->value],
fn () => ['consulting_services' => __('validation.array', ['attribute' => __('Consulting services')])],
],
'Consulting service invalid' => [
Expand Down
Loading

0 comments on commit 979d750

Please sign in to comment.