]> BookStack Code Mirror - bookstack/blobdiff - app/Auth/Permissions/SimpleEntityData.php
Covered app icon setting with testing
[bookstack] / app / Auth / Permissions / SimpleEntityData.php
index 0d1c94b0dd2f6df1b499a964491f55bbe7a0302a..2128451fe0d34294bde87034a174aa8dd2b8d07d 100644 (file)
@@ -2,12 +2,27 @@
 
 namespace BookStack\Auth\Permissions;
 
+use BookStack\Entities\Models\Entity;
+
 class SimpleEntityData
 {
     public int $id;
     public string $type;
-    public bool $restricted;
     public int $owned_by;
     public ?int $book_id;
     public ?int $chapter_id;
-}
\ No newline at end of file
+
+    public static function fromEntity(Entity $entity): self
+    {
+        $attrs = $entity->getAttributes();
+        $simple = new self();
+
+        $simple->id = $attrs['id'];
+        $simple->type = $entity->getMorphClass();
+        $simple->owned_by = $attrs['owned_by'] ?? 0;
+        $simple->book_id = $attrs['book_id'] ?? null;
+        $simple->chapter_id = $attrs['chapter_id'] ?? null;
+
+        return $simple;
+    }
+}