Skip to content

Commit

Permalink
Merge pull request #483 from canyongbs/bugfix/ADVAPP-253-failing-test
Browse files Browse the repository at this point in the history
[ADVAPP-253]: EditInteractionTest.php fails when a ServiceRequest is used
  • Loading branch information
Orrison authored Jan 31, 2024
2 parents 01dc739 + 6862626 commit 8066dd8
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use AdvisingApp\Interaction\Models\InteractionOutcome;
use AdvisingApp\Interaction\Models\InteractionCampaign;
use AdvisingApp\Interaction\Models\InteractionRelation;
use AdvisingApp\ServiceManagement\Models\ServiceRequest;

/**
* @extends Factory<Interaction>
Expand All @@ -57,17 +58,14 @@ class InteractionFactory extends Factory
public function definition(): array
{
$interactable = fake()->randomElement([
Student::class,
Prospect::class,
// Disabled until ADVAPP-253
//ServiceRequest::class,
Student::inRandomOrder()->first() ?? Student::factory()->create(),
Prospect::factory()->create(),
ServiceRequest::factory()->create(),
]);

$interactable = $interactable::factory()->create();

return [
'user_id' => User::factory(),
'interactable_id' => $interactable->identifier(),
'interactable_id' => $interactable->getKey(),
'interactable_type' => $interactable->getMorphClass(),
'interaction_type_id' => InteractionType::factory(),
'interaction_relation_id' => InteractionRelation::factory(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@

namespace AdvisingApp\Interaction\Filament\Resources\InteractionResource\Pages;

use Filament\Actions;
use Filament\Forms\Form;
use Filament\Actions\DeleteAction;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Fieldset;
use Filament\Forms\Components\Textarea;
Expand Down Expand Up @@ -145,7 +145,7 @@ public function form(Form $form): Form
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
DeleteAction::make(),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ public function table(Table $table): Table
->actions([
ViewAction::make(),
EditAction::make(),
])
->bulkActions([
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public function interactions(): MorphMany
return $this->morphMany(
related: Interaction::class,
name: 'interactable',
type: 'interactable_type',
id: 'interactable_id'
);
}
}
12 changes: 5 additions & 7 deletions app-modules/interaction/src/Models/Interaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,11 @@ protected static function booted(): void
static::addGlobalScope('licensed', function (Builder $builder) {
$builder
->tap(new LicensedToEducatable('interactable'))
->where(fn (Builder $builder) => $builder
->where('interactable_type', '!=', app(ServiceRequest::class)->getMorphClass())
->orWhereDoesntHaveMorph(
'interactable',
ServiceRequest::class,
fn (Builder $builder) => $builder->tap(new LicensedToEducatable('respondent')),
));
->orWhereHasMorph(
'interactable',
ServiceRequest::class,
fn (Builder $builder) => $builder->tap(new LicensedToEducatable('respondent')),
);
});
}
}
13 changes: 8 additions & 5 deletions app-modules/interaction/src/Policies/InteractionPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@

use App\Models\Authenticatable;
use Illuminate\Auth\Access\Response;
use AdvisingApp\Prospect\Models\Prospect;
use App\Concerns\PerformsLicenseChecks;
use AdvisingApp\Interaction\Models\Interaction;
use AdvisingApp\StudentDataModel\Models\Student;
use AdvisingApp\Authorization\Enums\LicenseType;
use App\Policies\Contracts\PerformsChecksBeforeAuthorization;

class InteractionPolicy
class InteractionPolicy implements PerformsChecksBeforeAuthorization
{
use PerformsLicenseChecks;

public function before(Authenticatable $authenticatable): ?Response
{
if (! $authenticatable->hasAnyLicense([Student::getLicenseType(), Prospect::getLicenseType()])) {
return Response::deny('You are not licensed for the Retention or Recruitment CRM.');
if (! is_null($response = $this->hasAnyLicense($authenticatable, [LicenseType::RetentionCrm, LicenseType::RecruitmentCrm]))) {
return $response;
}

return null;
Expand Down
2 changes: 0 additions & 2 deletions app-modules/service-management/src/Models/ServiceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
use AdvisingApp\Campaign\Models\CampaignAction;
use AdvisingApp\StudentDataModel\Models\Student;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
Expand Down Expand Up @@ -84,7 +83,6 @@ class ServiceRequest extends BaseModel implements Auditable, CanTriggerAutoSubsc
use SoftDeletes;
use PowerJoins;
use AuditableTrait;
use HasUuids;
use HasManyMorphedInteractions;
use HasRelationships;

Expand Down

0 comments on commit 8066dd8

Please sign in to comment.