summaryrefslogtreecommitdiff
path: root/src/application/mystic/forum/orm
diff options
context:
space:
mode:
authorJonas Kohl2024-09-12 19:49:17 +0200
committerJonas Kohl2024-09-12 19:49:17 +0200
commit086e2d2668784469ec114f6e6fd2b3dace3d7c3b (patch)
treeb9bacedb713501d88d24085940267a7c94e69b29 /src/application/mystic/forum/orm
parent34b1b391d4b03659a96f868857c230002b351514 (diff)
Way more progress on forum
Diffstat (limited to 'src/application/mystic/forum/orm')
-rw-r--r--src/application/mystic/forum/orm/Attachment.php18
-rw-r--r--src/application/mystic/forum/orm/Post.php6
-rw-r--r--src/application/mystic/forum/orm/Topic.php5
-rw-r--r--src/application/mystic/forum/orm/User.php16
-rw-r--r--src/application/mystic/forum/orm/UserPermissions.php59
5 files changed, 99 insertions, 5 deletions
diff --git a/src/application/mystic/forum/orm/Attachment.php b/src/application/mystic/forum/orm/Attachment.php
new file mode 100644
index 0000000..64e357c
--- /dev/null
+++ b/src/application/mystic/forum/orm/Attachment.php
@@ -0,0 +1,18 @@
+<?php
+declare(strict_types=1);
+
+namespace mystic\forum\orm;
+
+use mystic\forum\attributes\Column;
+use mystic\forum\attributes\PrimaryKey;
+use mystic\forum\attributes\References;
+use mystic\forum\attributes\Table;
+
+#[Table("public.attachments")]
+class Attachment extends Entity {
+ #[PrimaryKey] public string $id;
+ #[References("public.posts", onDelete: References::CASCADE)] public string $postId;
+ public string $name;
+ public string $mimeType;
+ #[Column(columnType: "bytea")] public string $contents;
+}
diff --git a/src/application/mystic/forum/orm/Post.php b/src/application/mystic/forum/orm/Post.php
index 2c9a38c..becbb9d 100644
--- a/src/application/mystic/forum/orm/Post.php
+++ b/src/application/mystic/forum/orm/Post.php
@@ -3,6 +3,7 @@ declare(strict_types=1);
namespace mystic\forum\orm;
+use mystic\forum\attributes\DefaultValue;
use mystic\forum\attributes\PrimaryKey;
use mystic\forum\attributes\References;
use mystic\forum\attributes\Table;
@@ -11,7 +12,8 @@ use mystic\forum\attributes\Table;
class Post extends Entity {
#[PrimaryKey] public string $id;
public string $content;
- #[References("public.users")] public string $authorId;
+ #[References("public.users", onDelete: References::SET_NULL)] public ?string $authorId;
public \DateTimeImmutable $postDate;
- #[References("public.topics", cascadeOnDelete: true)] public string $topicId;
+ #[References("public.topics", onDelete: References::CASCADE)] public string $topicId;
+ #[DefaultValue("false")] public bool $deleted;
}
diff --git a/src/application/mystic/forum/orm/Topic.php b/src/application/mystic/forum/orm/Topic.php
index 202fc50..421f5ec 100644
--- a/src/application/mystic/forum/orm/Topic.php
+++ b/src/application/mystic/forum/orm/Topic.php
@@ -4,12 +4,13 @@ declare(strict_types=1);
namespace mystic\forum\orm;
use mystic\forum\attributes\PrimaryKey;
+use mystic\forum\attributes\References;
use mystic\forum\attributes\Table;
#[Table("public.topics")]
class Topic extends Entity {
- #[PrimaryKey]
- public string $id;
+ #[PrimaryKey] public string $id;
public string $title;
public \DateTimeImmutable $creationDate;
+ #[References("public.users", onDelete: References::SET_NULL)] public ?string $createdBy;
}
diff --git a/src/application/mystic/forum/orm/User.php b/src/application/mystic/forum/orm/User.php
index 3b531b4..1db1d04 100644
--- a/src/application/mystic/forum/orm/User.php
+++ b/src/application/mystic/forum/orm/User.php
@@ -5,13 +5,27 @@ namespace mystic\forum\orm;
use mystic\forum\attributes\PrimaryKey;
use mystic\forum\attributes\Table;
+use mystic\forum\attributes\Unique;
#[Table("public.users")]
class User extends Entity {
+ public const SUPERUSER_ID = "SUPERUSER";
+
#[PrimaryKey]
public string $id;
- public string $name;
+ #[Unique] public string $name;
public string $displayName;
+ #[Unique] public string $email;
public \DateTimeImmutable $created;
public string $passwordHash;
+ public int $permissionMask;
+ public bool $passwordResetRequired;
+ public string $activationToken;
+ public bool $activated;
+
+ public function hasPermission(int $perm): bool {
+ if ($this->id === self::SUPERUSER_ID)
+ return true;
+ return ($this->permissionMask & $perm) === $perm;
+ }
}
diff --git a/src/application/mystic/forum/orm/UserPermissions.php b/src/application/mystic/forum/orm/UserPermissions.php
new file mode 100644
index 0000000..cd2fdf4
--- /dev/null
+++ b/src/application/mystic/forum/orm/UserPermissions.php
@@ -0,0 +1,59 @@
+<?php
+declare(strict_types=1);
+
+namespace mystic\forum\orm;
+
+use mystic\forum\utils\StaticClass;
+
+final class UserPermissions {
+ use StaticClass;
+
+ public const CREATE_OWN_POST = 0x01;
+ public const EDIT_OWN_POST = 0x02;
+ public const DELETE_OWN_POST = 0x04;
+
+ public const CREATE_OWN_TOPIC = 0x08;
+ public const EDIT_OWN_TOPIC = 0x10;
+ public const DELETE_OWN_TOPIC = 0x20;
+
+ public const CREATE_OWN_ATTACHMENT = 0x40;
+ public const EDIT_OWN_ATTACHMENT = 0x80;
+ public const DELETE_OWN_ATTACHMENT = 0x100;
+
+ // public const CREATE_OWN_USER = n/a;
+ public const EDIT_OWN_USER = 0x200;
+ public const DELETE_OWN_USER = 0x400;
+
+ // public const CREATE_OTHER_POST = n/a;
+ public const EDIT_OTHER_POST = 0x800;
+ public const DELETE_OTHER_POST = 0x1000;
+
+ public const CREATE_OTHER_USER = 0x2000;
+ public const EDIT_OTHER_USER = 0x4000;
+ public const DELETE_OTHER_USER = 0x8000;
+
+ public const DELETE_OTHER_TOPIC = 0x10000;
+
+ ////////
+
+ public const GROUP_USER = self::CREATE_OWN_POST
+ | self::EDIT_OWN_POST
+ | self::DELETE_OWN_POST
+ | self::CREATE_OWN_TOPIC
+ | self::DELETE_OWN_TOPIC
+ | self::CREATE_OWN_ATTACHMENT
+ | self::EDIT_OWN_ATTACHMENT
+ | self::DELETE_OWN_ATTACHMENT
+ | self::EDIT_OWN_USER
+ | self::DELETE_OWN_USER;
+
+ public const GROUP_MOD = self::GROUP_USER
+ | self::EDIT_OTHER_POST
+ | self::DELETE_OTHER_USER
+ | self::DELETE_OTHER_TOPIC;
+
+ public const GROUP_ADMIN = self::GROUP_MOD
+ | self::CREATE_OTHER_USER
+ | self::EDIT_OTHER_USER
+ | self::DELETE_OTHER_USER;
+}