Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117655746
D4085.1774870430.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
6 KB
Referenced Files
None
Subscribers
None
D4085.1774870430.diff
View Options
diff --git a/src/app/Domain.php b/src/app/Domain.php
--- a/src/app/Domain.php
+++ b/src/app/Domain.php
@@ -44,6 +44,15 @@
// domain has been created in LDAP
public const STATUS_LDAP_READY = 1 << 6;
+ /** @var int The allowed states for this object used in StatusPropertyTrait */
+ private int $allowed_states = self::STATUS_NEW |
+ self::STATUS_ACTIVE |
+ self::STATUS_SUSPENDED |
+ self::STATUS_DELETED |
+ self::STATUS_CONFIRMED |
+ self::STATUS_VERIFIED |
+ self::STATUS_LDAP_READY;
+
// open for public registration
public const TYPE_PUBLIC = 1 << 0;
// zone hosted with us
@@ -170,29 +179,13 @@
*/
public function setStatusAttribute($status)
{
- $new_status = 0;
-
- $allowed_values = [
- self::STATUS_NEW,
- self::STATUS_ACTIVE,
- self::STATUS_SUSPENDED,
- self::STATUS_DELETED,
- self::STATUS_CONFIRMED,
- self::STATUS_VERIFIED,
- self::STATUS_LDAP_READY,
- ];
-
- foreach ($allowed_values as $value) {
- if ($status & $value) {
- $new_status |= $value;
- $status ^= $value;
- }
- }
-
- if ($status > 0) {
+ // Detect invalid flags
+ if ($status & ~$this->allowed_states) {
throw new \Exception("Invalid domain status: {$status}");
}
+ $new_status = $status;
+
if ($this->isPublic()) {
$this->attributes['status'] = $new_status;
return;
diff --git a/src/app/Group.php b/src/app/Group.php
--- a/src/app/Group.php
+++ b/src/app/Group.php
@@ -44,6 +44,13 @@
// group has been created in LDAP
public const STATUS_LDAP_READY = 1 << 4;
+ /** @var int The allowed states for this object used in StatusPropertyTrait */
+ private int $allowed_states = self::STATUS_NEW |
+ self::STATUS_ACTIVE |
+ self::STATUS_SUSPENDED |
+ self::STATUS_DELETED |
+ self::STATUS_LDAP_READY;
+
/** @var array<string, string> The attributes that should be cast */
protected $casts = [
'created_at' => 'datetime:Y-m-d H:i:s',
diff --git a/src/app/Resource.php b/src/app/Resource.php
--- a/src/app/Resource.php
+++ b/src/app/Resource.php
@@ -45,6 +45,13 @@
// resource has been created in IMAP
public const STATUS_IMAP_READY = 1 << 8;
+ /** @var int The allowed states for this object used in StatusPropertyTrait */
+ private int $allowed_states = self::STATUS_NEW |
+ self::STATUS_ACTIVE |
+ self::STATUS_DELETED |
+ self::STATUS_LDAP_READY |
+ self::STATUS_IMAP_READY;
+
// A template for the email attribute on a resource creation
public const EMAIL_TEMPLATE = 'resource-{id}@{domainName}';
diff --git a/src/app/SharedFolder.php b/src/app/SharedFolder.php
--- a/src/app/SharedFolder.php
+++ b/src/app/SharedFolder.php
@@ -48,6 +48,13 @@
// folder has been created in IMAP
public const STATUS_IMAP_READY = 1 << 8;
+ /** @var int The allowed states for this object used in StatusPropertyTrait */
+ private int $allowed_states = self::STATUS_NEW |
+ self::STATUS_ACTIVE |
+ self::STATUS_DELETED |
+ self::STATUS_LDAP_READY |
+ self::STATUS_IMAP_READY;
+
/** @const array Supported folder type labels */
public const SUPPORTED_TYPES = ['mail', 'event', 'contact', 'task', 'note', 'file'];
diff --git a/src/app/Traits/StatusPropertyTrait.php b/src/app/Traits/StatusPropertyTrait.php
--- a/src/app/Traits/StatusPropertyTrait.php
+++ b/src/app/Traits/StatusPropertyTrait.php
@@ -101,34 +101,10 @@
*/
public function setStatusAttribute($status)
{
- $new_status = 0;
-
- $allowed_states = [
- 'STATUS_NEW',
- 'STATUS_ACTIVE',
- 'STATUS_SUSPENDED',
- 'STATUS_DELETED',
- 'STATUS_LDAP_READY',
- 'STATUS_IMAP_READY',
- ];
-
- foreach ($allowed_states as $const) {
- if (!defined("static::$const")) {
- continue;
- }
-
- $value = constant("static::$const");
-
- if ($status & $value) {
- $new_status |= $value;
- $status ^= $value;
- }
- }
-
- if ($status > 0) {
+ if ($status & ~$this->allowed_states) {
throw new \Exception("Invalid status: {$status}");
}
- $this->attributes['status'] = $new_status;
+ $this->attributes['status'] = $status;
}
}
diff --git a/src/app/User.php b/src/app/User.php
--- a/src/app/User.php
+++ b/src/app/User.php
@@ -61,6 +61,16 @@
// a restricted user
public const STATUS_RESTRICTED = 1 << 7;
+ /** @var int The allowed states for this object used in StatusPropertyTrait */
+ private int $allowed_states = self::STATUS_NEW |
+ self::STATUS_ACTIVE |
+ self::STATUS_SUSPENDED |
+ self::STATUS_DELETED |
+ self::STATUS_LDAP_READY |
+ self::STATUS_IMAP_READY |
+ self::STATUS_DEGRADED |
+ self::STATUS_RESTRICTED;
+
/** @var array<int, string> The attributes that are mass assignable */
protected $fillable = [
'id',
@@ -621,40 +631,6 @@
$this->setPasswordAttribute($password);
}
- /**
- * User status mutator
- *
- * @throws \Exception
- */
- public function setStatusAttribute($status)
- {
- $new_status = 0;
-
- $allowed_values = [
- self::STATUS_NEW,
- self::STATUS_ACTIVE,
- self::STATUS_SUSPENDED,
- self::STATUS_DELETED,
- self::STATUS_LDAP_READY,
- self::STATUS_IMAP_READY,
- self::STATUS_DEGRADED,
- self::STATUS_RESTRICTED,
- ];
-
- foreach ($allowed_values as $value) {
- if ($status & $value) {
- $new_status |= $value;
- $status ^= $value;
- }
- }
-
- if ($status > 0) {
- throw new \Exception("Invalid user status: {$status}");
- }
-
- $this->attributes['status'] = $new_status;
- }
-
/**
* Validate the user credentials
*
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Mar 30, 11:33 AM (4 d, 3 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18806379
Default Alt Text
D4085.1774870430.diff (6 KB)
Attached To
Mode
D4085: Simplify setStatusAttribute
Attached
Detach File
Event Timeline