Files
laraundfelix/app/Domain/Entitlement/Grant.php
T
Lars 4e0760db1e
Deploy Test / test (push) Successful in 1m38s
Deploy Test / deploy (push) Successful in 31s
Add feature tests for shop functionality and organization purchases
- Implement OfferOptionAdminTest to validate offer option management, including price display, activation, and cancellation.
- Create OrganizationPurchaseTest to ensure correct handling of organization purchases, including access control and order processing.
- Add ShopProductPageTest to verify shop product listings, search functionality, and product page details.
- Introduce BuildsShop trait for seeding test data related to shop functionality.
- Implement MoneyTest to validate money parsing and formatting, ensuring correct handling of euro amounts.
2026-11-21 12:06:24 +01:00

84 lines
2.7 KiB
PHP

<?php
namespace App\Domain\Entitlement;
use App\Domain\Catalog\ArticleRelease;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\RightsProfileVersion;
use App\Domain\Identity\Membership;
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Grant extends Model
{
protected $fillable = [
'acquisition_id',
'license_article_id',
'rights_profile_version_id',
'rights_snapshot',
'valid_from',
'valid_until',
'release_at_grant_id',
'status',
'status_reason',
];
protected function casts(): array
{
return [
'rights_snapshot' => 'array',
'valid_from' => 'datetime',
'valid_until' => 'datetime',
'status' => GrantStatus::class,
];
}
/**
* Berechtigungen, die ein Konto nutzen darf (zentrale Regel für Entscheidung, Bibliothek und Vorschaubilder):
* - persönliche Erwerbe: Inhaber ist die Person des Kontos;
* - Erwerbe einer Organisation: nur das auslösende Konto und nur, solange seine Mitgliedschaft mit
* Bestellberechtigung besteht (Etappe 1, Domänenmodell 04; Sitzpools folgen mit A4).
*
* @param Builder<Grant> $query
* @return Builder<Grant>
*/
public function scopeUsableBy(Builder $query, User $user): Builder
{
return $query->whereHas('acquisition', function (Builder $acquisition) use ($user): void {
$acquisition->where(function (Builder $either) use ($user): void {
$either->where('party_id', $user->party_id)
->orWhere(function (Builder $organisation) use ($user): void {
$organisation->where('acting_user_id', $user->id)
->whereIn('party_id', Membership::query()
->active()
->where('user_id', $user->id)
->where('may_order', true)
->select('party_id'));
});
});
});
}
public function acquisition(): BelongsTo
{
return $this->belongsTo(Acquisition::class);
}
public function article(): BelongsTo
{
return $this->belongsTo(LicenseArticle::class, 'license_article_id');
}
public function rights(): BelongsTo
{
return $this->belongsTo(RightsProfileVersion::class, 'rights_profile_version_id');
}
public function releaseAtGrant(): BelongsTo
{
return $this->belongsTo(ArticleRelease::class, 'release_at_grant_id');
}
}