]> BookStack Code Mirror - bookstack/blobdiff - app/Users/Models/User.php
Extracted icon helper, aligned container resolution
[bookstack] / app / Users / Models / User.php
index cbfdbef2dd6c43e326e27228bb1fe5b4ca308425..232ea88326aa96f2bdc1b646590dd975440e29c5 100644 (file)
@@ -88,36 +88,29 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
      */
     protected string $avatarUrl = '';
 
-    /**
-     * This holds the default user when loaded.
-     */
-    protected static ?User $defaultUser = null;
-
     /**
      * Returns the default public user.
+     * Fetches from the container as a singleton to effectively cache at an app level.
      */
-    public static function getDefault(): self
+    public static function getGuest(): self
     {
-        if (!is_null(static::$defaultUser)) {
-            return static::$defaultUser;
-        }
-
-        static::$defaultUser = static::query()->where('system_name', '=', 'public')->first();
-
-        return static::$defaultUser;
+        return app()->make('users.default');
     }
 
-    public static function clearDefault(): void
+    /**
+     * Check if the user is the default public user.
+     */
+    public function isGuest(): bool
     {
-        static::$defaultUser = null;
+        return $this->system_name === 'public';
     }
 
     /**
-     * Check if the user is the default public user.
+     * Check if the user has general access to the application.
      */
-    public function isDefault(): bool
+    public function hasAppAccess(): bool
     {
-        return $this->system_name === 'public';
+        return !$this->isGuest() || setting('app-public');
     }
 
     /**
@@ -345,7 +338,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
             return $splitName[0];
         }
 
-        return mb_substr($this->name, 0, $chars) . '..';
+        return mb_substr($this->name, 0, max($chars - 2, 0)) . '…';
     }
 
     /**
@@ -381,7 +374,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
      */
     public function refreshSlug(): string
     {
-        $this->slug = app(SlugGenerator::class)->generate($this);
+        $this->slug = app()->make(SlugGenerator::class)->generate($this);
 
         return $this->slug;
     }