| 1: | <?php |
| 2: | /** |
| 3: | * This code is licensed under AGPLv3 license or Afterlogic Software License |
| 4: | * if commercial version of the product was purchased. |
| 5: | * For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files. |
| 6: | */ |
| 7: | |
| 8: | namespace Aurora\Modules\Core\Models; |
| 9: | |
| 10: | use Aurora\System\Classes\Model; |
| 11: | use Aurora\Modules\Core\Models\Tenant; |
| 12: | |
| 13: | /** |
| 14: | * The Core User class. |
| 15: | * |
| 16: | * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0 |
| 17: | * @license https://afterlogic.com/products/common-licensing Afterlogic Software License |
| 18: | * @copyright Copyright (c) 2023, Afterlogic Corp. |
| 19: | * |
| 20: | * @property int $Id Object primary key |
| 21: | * @property string $UUID Unique identifier of the object |
| 22: | * @property string $Name User name |
| 23: | * @property string $PublicId User public ID, usually equals user's email address |
| 24: | * @property int $IdTenant ID of the tetant a user relates to |
| 25: | * @property bool $IsDisabled Reserved for future use |
| 26: | * @property int $IdSubscription @Deprecated since 9.7.0 |
| 27: | * @property int $Role User role from \Aurora\System\Enums\UserRole |
| 28: | * @property \DateTime $LastLogin Date at time of last login |
| 29: | * @property string $LastLoginNow @Deprecated since 9.7.0 |
| 30: | * @property int $LoginsCount Stores the number of times user has logged in |
| 31: | * @property string $Language Interface language set for this user |
| 32: | * @property int $TimeFormat Time format set for this user |
| 33: | * @property string $DateFormat Date format set for this user |
| 34: | * @property string $Question1 @Deprecated since 9.7.0 |
| 35: | * @property string $Question2 @Deprecated since 9.7.0 |
| 36: | * @property string $Answer1 @Deprecated since 9.7.0 |
| 37: | * @property string $Answer2 @Deprecated since 9.7.0 |
| 38: | * @property bool $SipEnable @Deprecated since 9.7.0 |
| 39: | * @property string $SipImpi @Deprecated since 9.7.0 |
| 40: | * @property string $SipPassword @Deprecated since 9.7.0 |
| 41: | * @property bool $DesktopNotifications @Deprecated since 9.7.0 |
| 42: | * @property string $Capa @Deprecated since 9.7.0 |
| 43: | * @property string $CustomFields @Deprecated since 9.7.0 |
| 44: | * @property bool $FilesEnable @Deprecated since 9.7.0 |
| 45: | * @property string $EmailNotification @Deprecated since 9.7.0 |
| 46: | * @property string $PasswordResetHash @Deprecated since 9.7.0 |
| 47: | * @property bool $WriteSeparateLog If set to true, a separate log file is recorded for the user |
| 48: | * @property string $DefaultTimeZone Default time zone set for this user |
| 49: | * @property int $TokensValidFromTimestamp Timestamp the token is valid since |
| 50: | * @property array $Properties Custom properties for use by other modules |
| 51: | */ |
| 52: | class User extends Model |
| 53: | { |
| 54: | protected $table = 'core_users'; |
| 55: | |
| 56: | protected $moduleName = 'Core'; |
| 57: | |
| 58: | protected $parentType = Tenant::class; |
| 59: | |
| 60: | protected $parentKey = 'IdTenant'; |
| 61: | |
| 62: | protected $parentInheritedAttributes = [ |
| 63: | ]; |
| 64: | |
| 65: | protected $foreignModel = Tenant::class; |
| 66: | protected $foreignModelIdColumn = 'IdTenant'; // Column that refers to an external table |
| 67: | |
| 68: | /** |
| 69: | * The attributes that are mass assignable. |
| 70: | * |
| 71: | * @var array |
| 72: | */ |
| 73: | protected $fillable = [ |
| 74: | 'Id', |
| 75: | 'UUID', |
| 76: | 'Name', |
| 77: | 'PublicId', |
| 78: | 'IdTenant', |
| 79: | 'IsDisabled', |
| 80: | 'IdSubscription', |
| 81: | 'Role', |
| 82: | 'LastLogin', |
| 83: | 'LastLoginNow', |
| 84: | 'LoginsCount', |
| 85: | 'Language', |
| 86: | 'TimeFormat', |
| 87: | 'DateFormat', |
| 88: | 'Question1', |
| 89: | 'Question2', |
| 90: | 'Answer1', |
| 91: | 'Answer2', |
| 92: | 'SipEnable', |
| 93: | 'SipImpi', |
| 94: | 'SipPassword', |
| 95: | 'DesktopNotifications', |
| 96: | 'Capa', |
| 97: | 'CustomFields', |
| 98: | 'FilesEnable', |
| 99: | 'EmailNotification', |
| 100: | 'PasswordResetHash', |
| 101: | 'WriteSeparateLog', |
| 102: | 'DefaultTimeZone', |
| 103: | 'TokensValidFromTimestamp', |
| 104: | 'Properties' |
| 105: | ]; |
| 106: | |
| 107: | protected $validationRules = [ |
| 108: | 'TimeFormat' => 'in:0,1', |
| 109: | ]; |
| 110: | |
| 111: | /** |
| 112: | * The attributes that should be hidden for arrays. |
| 113: | * |
| 114: | * @var array |
| 115: | */ |
| 116: | protected $hidden = [ |
| 117: | ]; |
| 118: | |
| 119: | protected $casts = [ |
| 120: | 'Properties' => 'array', |
| 121: | 'IsDisabled' => 'boolean', |
| 122: | 'SipEnable' => 'boolean', |
| 123: | 'DesktopNotifications' => 'boolean', |
| 124: | 'FilesEnable' => 'boolean', |
| 125: | 'WriteSeparateLog' => 'boolean' |
| 126: | ]; |
| 127: | |
| 128: | protected $attributes = [ |
| 129: | ]; |
| 130: | |
| 131: | /** |
| 132: | * Checks if a user is a superadmin. |
| 133: | * |
| 134: | * return bool |
| 135: | */ |
| 136: | public function isAdmin() |
| 137: | { |
| 138: | return $this->Id === -1; |
| 139: | } |
| 140: | |
| 141: | /** |
| 142: | * Checks if a user can act as a regular user. |
| 143: | * |
| 144: | * return bool |
| 145: | */ |
| 146: | public function isNormalOrTenant() |
| 147: | { |
| 148: | return $this->Role === \Aurora\System\Enums\UserRole::NormalUser || $this->Role === \Aurora\System\Enums\UserRole::TenantAdmin; |
| 149: | } |
| 150: | |
| 151: | /** |
| 152: | * Returns array of groups the user is related to. |
| 153: | * |
| 154: | * return array |
| 155: | */ |
| 156: | public function Groups() |
| 157: | { |
| 158: | return $this->belongsToMany(Group::class, 'core_group_user', 'UserId', 'GroupId'); |
| 159: | } |
| 160: | } |
| 161: |