2018-11-02 11:54:46 +01:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-05-11 05:32:07 +02:00
|
|
|
*/
|
2018-11-02 11:54:46 +01:00
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2020-03-01 11:18:13 +01:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2023-04-26 15:03:32 +02:00
|
|
|
use Illuminate\Database\Eloquent\Relations\Pivot;
|
2023-08-11 10:04:41 +02:00
|
|
|
use Awobaz\Compoships\Exceptions\InvalidUsageException;
|
|
|
|
use Awobaz\Compoships\Database\Eloquent\Relations\HasMany;
|
2019-01-19 11:35:21 +01:00
|
|
|
|
2023-03-08 08:33:42 +01:00
|
|
|
/**
|
|
|
|
* App\Models\CompanyUser
|
|
|
|
*
|
|
|
|
* @property int $id
|
|
|
|
* @property int $company_id
|
|
|
|
* @property int $account_id
|
|
|
|
* @property int $user_id
|
|
|
|
* @property string|null $permissions
|
|
|
|
* @property object|null $notifications
|
|
|
|
* @property object|null $settings
|
|
|
|
* @property string $slack_webhook_url
|
2023-04-26 15:03:32 +02:00
|
|
|
* @property bool $is_owner
|
|
|
|
* @property bool $is_admin
|
|
|
|
* @property bool $is_locked
|
2023-03-08 08:33:42 +01:00
|
|
|
* @property int|null $deleted_at
|
|
|
|
* @property int|null $created_at
|
|
|
|
* @property int|null $updated_at
|
|
|
|
* @property int $permissions_updated_at
|
|
|
|
* @property string $ninja_portal_url
|
2023-06-07 05:53:38 +02:00
|
|
|
* @property object|null $react_settings
|
2023-03-08 08:33:42 +01:00
|
|
|
* @property-read \App\Models\Account $account
|
|
|
|
* @property-read \App\Models\Company $company
|
2023-04-26 15:03:32 +02:00
|
|
|
* @property-read \App\Models\CompanyUser $cu
|
2023-03-08 08:33:42 +01:00
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyToken> $token
|
|
|
|
* @property-read int|null $token_count
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyToken> $tokens
|
|
|
|
* @property-read int|null $tokens_count
|
|
|
|
* @property-read \App\Models\User $user
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\User> $users
|
|
|
|
* @property-read int|null $users_count
|
2023-08-11 10:04:41 +02:00
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser authCompany()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser newModelQuery()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser newQuery()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser onlyTrashed()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser query()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser whereAccountId($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser whereCompanyId($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser whereCreatedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser whereDeletedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser whereId($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser whereIsAdmin($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser whereIsLocked($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser whereIsOwner($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser whereNinjaPortalUrl($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser whereNotifications($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser wherePermissions($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser wherePermissionsUpdatedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser whereReactSettings($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser whereSettings($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser whereSlackWebhookUrl($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser whereUpdatedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser whereUserId($value)
|
2023-03-08 08:33:42 +01:00
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser withTrashed()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|CompanyUser withoutTrashed()
|
2023-03-16 05:20:38 +01:00
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyToken> $token
|
2023-03-29 04:13:50 +02:00
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyToken> $tokens
|
2023-04-26 00:43:54 +02:00
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\User> $users
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyToken> $token
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyToken> $tokens
|
2023-04-26 08:55:49 +02:00
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\User> $users
|
2023-04-26 15:03:32 +02:00
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyUser> $cu
|
2023-04-26 08:55:49 +02:00
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyToken> $token
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyToken> $tokens
|
2023-03-08 08:33:42 +01:00
|
|
|
* @mixin \Eloquent
|
|
|
|
*/
|
2019-01-19 11:35:21 +01:00
|
|
|
class CompanyUser extends Pivot
|
2018-11-02 11:54:46 +01:00
|
|
|
{
|
2020-03-01 11:18:13 +01:00
|
|
|
use SoftDeletes;
|
2022-03-15 13:28:16 +01:00
|
|
|
use \Awobaz\Compoships\Compoships;
|
2020-02-26 04:26:07 +01:00
|
|
|
|
2019-11-22 22:10:53 +01:00
|
|
|
protected $dateFormat = 'Y-m-d H:i:s.u';
|
|
|
|
|
2019-01-15 23:00:25 +01:00
|
|
|
/**
|
|
|
|
* The attributes that should be cast to native types.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
2021-01-29 13:29:42 +01:00
|
|
|
'permissions_updated_at' => 'timestamp',
|
2019-09-26 00:27:26 +02:00
|
|
|
'updated_at' => 'timestamp',
|
|
|
|
'created_at' => 'timestamp',
|
|
|
|
'deleted_at' => 'timestamp',
|
2019-11-29 12:15:50 +01:00
|
|
|
'settings' => 'object',
|
2020-03-08 10:06:21 +01:00
|
|
|
'notifications' => 'object',
|
2020-03-10 13:54:20 +01:00
|
|
|
'permissions' => 'string',
|
2023-06-05 11:38:38 +02:00
|
|
|
'react_settings' => 'object',
|
2019-01-15 23:00:25 +01:00
|
|
|
];
|
|
|
|
|
2019-11-21 09:38:57 +01:00
|
|
|
protected $fillable = [
|
|
|
|
'account_id',
|
|
|
|
'permissions',
|
2020-03-01 11:18:13 +01:00
|
|
|
'notifications',
|
2019-11-21 09:38:57 +01:00
|
|
|
'settings',
|
2023-02-14 11:04:07 +01:00
|
|
|
'react_settings',
|
2019-11-21 09:38:57 +01:00
|
|
|
'is_admin',
|
|
|
|
'is_owner',
|
2020-03-09 10:38:15 +01:00
|
|
|
'is_locked',
|
|
|
|
'slack_webhook_url',
|
2020-09-06 11:38:10 +02:00
|
|
|
'shop_restricted',
|
2019-11-21 09:38:57 +01:00
|
|
|
];
|
|
|
|
|
2021-03-03 08:22:14 +01:00
|
|
|
protected $touches = ['user'];
|
2020-07-16 13:01:39 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
protected $with = ['user', 'account'];
|
2022-04-11 09:45:37 +02:00
|
|
|
|
2020-05-06 13:49:42 +02:00
|
|
|
public function getEntityType()
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
return self::class;
|
2020-05-06 13:49:42 +02:00
|
|
|
}
|
|
|
|
|
2023-08-07 00:23:13 +02:00
|
|
|
public function account(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2018-11-02 11:54:46 +01:00
|
|
|
{
|
2019-09-11 02:37:53 +02:00
|
|
|
return $this->belongsTo(Account::class);
|
2018-11-02 11:54:46 +01:00
|
|
|
}
|
|
|
|
|
2023-08-07 00:23:13 +02:00
|
|
|
/**
|
2023-08-11 10:07:57 +02:00
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne<User>
|
2023-08-07 00:23:13 +02:00
|
|
|
*/
|
2023-08-11 10:04:41 +02:00
|
|
|
public function user_pivot()
|
2018-11-02 11:54:46 +01:00
|
|
|
{
|
2023-02-14 11:04:07 +01:00
|
|
|
return $this->hasOne(User::class)->withPivot('permissions', 'settings', 'react_settings', 'is_admin', 'is_owner', 'is_locked', 'slack_webhook_url', 'migrating');
|
2019-01-07 12:30:28 +01:00
|
|
|
}
|
2023-08-07 00:23:13 +02:00
|
|
|
|
|
|
|
/**
|
2023-08-11 10:07:57 +02:00
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne<Company>
|
2023-08-07 00:23:13 +02:00
|
|
|
*/
|
2023-08-11 10:04:41 +02:00
|
|
|
public function company_pivot()
|
2019-01-07 12:30:28 +01:00
|
|
|
{
|
2023-02-14 11:04:07 +01:00
|
|
|
return $this->hasOne(Company::class)->withPivot('permissions', 'settings', 'react_settings', 'is_admin', 'is_owner', 'is_locked', 'slack_webhook_url', 'migrating');
|
2018-11-02 11:54:46 +01:00
|
|
|
}
|
2019-06-25 05:55:02 +02:00
|
|
|
|
2023-08-11 10:04:41 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
|
|
|
public function user()
|
2019-06-25 05:55:02 +02:00
|
|
|
{
|
2021-09-08 01:29:20 +02:00
|
|
|
return $this->belongsTo(User::class)->withTrashed();
|
2019-06-25 05:55:02 +02:00
|
|
|
}
|
|
|
|
|
2023-08-11 10:04:41 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
|
|
|
public function company()
|
2019-06-25 05:55:02 +02:00
|
|
|
{
|
2019-11-24 09:19:53 +01:00
|
|
|
return $this->belongsTo(Company::class);
|
2019-06-25 05:55:02 +02:00
|
|
|
}
|
|
|
|
|
2023-08-11 09:58:43 +02:00
|
|
|
/**
|
2023-08-11 10:04:41 +02:00
|
|
|
* @return HasMany
|
2023-08-11 09:58:43 +02:00
|
|
|
*/
|
2023-08-11 10:04:41 +02:00
|
|
|
public function users()
|
2019-10-30 08:48:44 +01:00
|
|
|
{
|
2021-11-07 12:18:15 +01:00
|
|
|
return $this->hasMany(User::class)->withTrashed();
|
2019-10-30 08:48:44 +01:00
|
|
|
}
|
|
|
|
|
2023-08-11 10:04:41 +02:00
|
|
|
/**
|
|
|
|
* @return HasMany
|
|
|
|
*/
|
2019-06-25 05:55:02 +02:00
|
|
|
public function token()
|
|
|
|
{
|
2020-02-26 04:26:07 +01:00
|
|
|
return $this->hasMany(CompanyToken::class, 'user_id', 'user_id');
|
2019-06-25 05:55:02 +02:00
|
|
|
}
|
2020-02-26 04:26:07 +01:00
|
|
|
|
2023-08-11 10:04:41 +02:00
|
|
|
/**
|
|
|
|
* @return HasMany
|
|
|
|
*/
|
|
|
|
public function tokens()
|
2020-02-26 04:26:07 +01:00
|
|
|
{
|
|
|
|
return $this->hasMany(CompanyToken::class, 'user_id', 'user_id');
|
|
|
|
}
|
|
|
|
|
2023-08-11 10:04:41 +02:00
|
|
|
public function scopeAuthCompany($query): \Illuminate\Database\Eloquent\Builder
|
2020-03-11 12:05:05 +01:00
|
|
|
{
|
2023-06-07 06:29:06 +02:00
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
|
|
|
|
|
|
|
$query->where('company_id', $user->companyId());
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-03-11 12:05:05 +01:00
|
|
|
return $query;
|
|
|
|
}
|
2023-06-07 06:29:06 +02:00
|
|
|
|
|
|
|
/**
|
2023-06-07 07:45:44 +02:00
|
|
|
* Determines if the notifications should be React or Flutter links
|
2023-06-07 06:29:06 +02:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2023-08-11 10:04:41 +02:00
|
|
|
public function portalType(): bool
|
2023-06-07 06:29:06 +02:00
|
|
|
{
|
|
|
|
return isset($this->react_settings->react_notification_link) && $this->react_settings->react_notification_link;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|