feat: prepare private offers through existing opportunities
This commit is contained in:
@@ -30,6 +30,23 @@ class Opportunity extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
public function isPrivateOfferPreparation(): bool
|
||||
{
|
||||
return isset($this->workflow_context['private_offer_preparation']);
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saving(function (self $record) {
|
||||
$original = $record->getRawOriginal('workflow_context');
|
||||
$wasPrivate = is_string($original) && isset(json_decode($original, true)['private_offer_preparation']);
|
||||
abort_if($wasPrivate && ! $record->isPrivateOfferPreparation(), 403, 'A preparação privada não pode ser convertida neste percurso.');
|
||||
if ($record->isPrivateOfferPreparation()) {
|
||||
abort_unless($record->status === 'draft' && $record->published_at === null, 403, 'A publicação de Ofertas não está disponível nesta fase.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected $hidden = ['management_draft', 'management_creation_key', 'management_version', 'first_submitted_at', 'management_closed_once', 'owner_user_id', 'organization_id', 'workflow_context'];
|
||||
|
||||
protected $appends = ['maturity_catalogue_version'];
|
||||
@@ -115,6 +132,7 @@ class Opportunity extends Model
|
||||
public function scopePublished(Builder $query): Builder
|
||||
{
|
||||
if (Schema::hasColumn('opportunities', 'workflow_context')) {
|
||||
$query->whereNull('workflow_context->private_offer_preparation');
|
||||
$query->where(fn ($q) => $q->whereNull('owner_user_id')->orWhere('workflow_context->publication->visibility', 'public'));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user