Commit workspace changes
This commit is contained in:
@@ -11,6 +11,7 @@ use App\Models\CollectionMember;
|
||||
use App\Models\CollectionSave;
|
||||
use App\Models\CollectionSurfacePlacement;
|
||||
use App\Models\CollectionSubmission;
|
||||
use App\Models\Group;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -120,6 +121,7 @@ class Collection extends Model
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'group_id',
|
||||
'managed_by_user_id',
|
||||
'title',
|
||||
'slug',
|
||||
@@ -263,6 +265,11 @@ class Collection extends Model
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function group(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Group::class);
|
||||
}
|
||||
|
||||
public function managedBy(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'managed_by_user_id');
|
||||
@@ -448,7 +455,17 @@ class Collection extends Model
|
||||
{
|
||||
$userId = $user instanceof User ? $user->id : $user;
|
||||
|
||||
return $userId !== null && (int) $userId === (int) $this->user_id;
|
||||
if ($userId === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((int) ($this->group_id ?? 0) > 0) {
|
||||
$group = $this->relationLoaded('group') ? $this->group : $this->group()->with('members')->first();
|
||||
|
||||
return $group?->hasActiveMember((int) $userId) ?? false;
|
||||
}
|
||||
|
||||
return (int) $userId === (int) $this->user_id;
|
||||
}
|
||||
|
||||
public function isPubliclyAccessible(): bool
|
||||
@@ -488,6 +505,12 @@ class Collection extends Model
|
||||
|
||||
public function displayOwnerName(): string
|
||||
{
|
||||
if ((int) ($this->group_id ?? 0) > 0) {
|
||||
$group = $this->relationLoaded('group') ? $this->group : $this->group()->first();
|
||||
|
||||
return (string) ($group?->name ?: 'Skinbase Group');
|
||||
}
|
||||
|
||||
if ($this->type === self::TYPE_EDITORIAL && $this->editorial_owner_mode === self::EDITORIAL_OWNER_SYSTEM) {
|
||||
return (string) ($this->editorial_owner_label ?: config('collections.editorial.system_owner_label', 'Skinbase Editorial'));
|
||||
}
|
||||
@@ -499,6 +522,10 @@ class Collection extends Model
|
||||
|
||||
public function displayOwnerUsername(): ?string
|
||||
{
|
||||
if ((int) ($this->group_id ?? 0) > 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->type === self::TYPE_EDITORIAL && $this->editorial_owner_mode === self::EDITORIAL_OWNER_SYSTEM) {
|
||||
return null;
|
||||
}
|
||||
@@ -526,6 +553,12 @@ class Collection extends Model
|
||||
return null;
|
||||
}
|
||||
|
||||
if ((int) ($this->group_id ?? 0) > 0) {
|
||||
$group = $this->relationLoaded('group') ? $this->group : $this->group()->with('members')->first();
|
||||
|
||||
return $group?->activeRoleFor((int) $userId);
|
||||
}
|
||||
|
||||
if ($this->isOwnedBy($userId)) {
|
||||
return self::MEMBER_ROLE_OWNER;
|
||||
}
|
||||
@@ -546,10 +579,13 @@ class Collection extends Model
|
||||
|
||||
public function canBeManagedBy(User $user): bool
|
||||
{
|
||||
return in_array($this->activeMemberRoleFor($user), [
|
||||
self::MEMBER_ROLE_OWNER,
|
||||
self::MEMBER_ROLE_EDITOR,
|
||||
], true);
|
||||
if ((int) ($this->group_id ?? 0) > 0) {
|
||||
$group = $this->relationLoaded('group') ? $this->group : $this->group()->with('members')->first();
|
||||
|
||||
return $group?->canManageCollections($user) ?? false;
|
||||
}
|
||||
|
||||
return in_array($this->activeMemberRoleFor($user), [self::MEMBER_ROLE_OWNER, self::MEMBER_ROLE_EDITOR], true);
|
||||
}
|
||||
|
||||
public function canManageArtworks(User $user): bool
|
||||
@@ -559,6 +595,12 @@ class Collection extends Model
|
||||
|
||||
public function canManageMembers(User $user): bool
|
||||
{
|
||||
if ((int) ($this->group_id ?? 0) > 0) {
|
||||
$group = $this->relationLoaded('group') ? $this->group : $this->group()->with('members')->first();
|
||||
|
||||
return $group?->canManageMembers($user) ?? false;
|
||||
}
|
||||
|
||||
return $this->isCollaborative() && $this->canBeManagedBy($user);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user