3 namespace BookStack\Permissions;
6 * Enum to represent the permissions which may be used in checks.
7 * These generally align with RolePermission names, although some are abstract or truncated as some checks
8 * are performed across a range of different items which may be subject to inheritance and other complications.
10 * We use and still allow the string values in usage to allow for compatibility with scenarios where
11 * users have customised their instance with additional permissions via the theme system.
12 * This enum primarily exists for alignment within the codebase.
14 * Permissions with all/own suffixes may also be represented as a higher-level alias without the own/all
15 * suffix, which are used and assessed in the permission system logic.
17 enum Permission: string
20 // Used for more abstract entity permission checks
22 case Create = 'create';
23 case Update = 'update';
24 case Delete = 'delete';
27 case AccessApi = 'access-api';
28 case ContentExport = 'content-export';
29 case ContentImport = 'content-import';
30 case EditorChange = 'editor-change';
31 case ReceiveNotifications = 'receive-notifications';
32 case RestrictionsManage = 'restrictions-manage';
33 case RestrictionsManageAll = 'restrictions-manage-all';
34 case RestrictionsManageOwn = 'restrictions-manage-own';
35 case SettingsManage = 'settings-manage';
36 case TemplatesManage = 'templates-manage';
37 case UserRolesManage = 'user-roles-manage';
38 case UsersManage = 'users-manage';
40 // Non-entity content permissions
41 case AttachmentCreate = 'attachment-create';
42 case AttachmentCreateAll = 'attachment-create-all';
43 case AttachmentCreateOwn = 'attachment-create-own';
44 case AttachmentDelete = 'attachment-delete';
45 case AttachmentDeleteAll = 'attachment-delete-all';
46 case AttachmentDeleteOwn = 'attachment-delete-own';
47 case AttachmentUpdate = 'attachment-update';
48 case AttachmentUpdateAll = 'attachment-update-all';
49 case AttachmentUpdateOwn = 'attachment-update-own';
51 case CommentCreateAll = 'comment-create-all';
52 case CommentDelete = 'comment-delete';
53 case CommentDeleteAll = 'comment-delete-all';
54 case CommentDeleteOwn = 'comment-delete-own';
55 case CommentUpdate = 'comment-update';
56 case CommentUpdateAll = 'comment-update-all';
57 case CommentUpdateOwn = 'comment-update-own';
59 case ImageCreateAll = 'image-create-all';
60 case ImageCreateOwn = 'image-create-own';
61 case ImageDelete = 'image-delete';
62 case ImageDeleteAll = 'image-delete-all';
63 case ImageDeleteOwn = 'image-delete-own';
64 case ImageUpdate = 'image-update';
65 case ImageUpdateAll = 'image-update-all';
66 case ImageUpdateOwn = 'image-update-own';
68 // Entity content permissions
69 case BookCreate = 'book-create';
70 case BookCreateAll = 'book-create-all';
71 case BookCreateOwn = 'book-create-own';
72 case BookDelete = 'book-delete';
73 case BookDeleteAll = 'book-delete-all';
74 case BookDeleteOwn = 'book-delete-own';
75 case BookUpdate = 'book-update';
76 case BookUpdateAll = 'book-update-all';
77 case BookUpdateOwn = 'book-update-own';
78 case BookView = 'book-view';
79 case BookViewAll = 'book-view-all';
80 case BookViewOwn = 'book-view-own';
82 case BookshelfCreate = 'bookshelf-create';
83 case BookshelfCreateAll = 'bookshelf-create-all';
84 case BookshelfCreateOwn = 'bookshelf-create-own';
85 case BookshelfDelete = 'bookshelf-delete';
86 case BookshelfDeleteAll = 'bookshelf-delete-all';
87 case BookshelfDeleteOwn = 'bookshelf-delete-own';
88 case BookshelfUpdate = 'bookshelf-update';
89 case BookshelfUpdateAll = 'bookshelf-update-all';
90 case BookshelfUpdateOwn = 'bookshelf-update-own';
91 case BookshelfView = 'bookshelf-view';
92 case BookshelfViewAll = 'bookshelf-view-all';
93 case BookshelfViewOwn = 'bookshelf-view-own';
95 case ChapterCreate = 'chapter-create';
96 case ChapterCreateAll = 'chapter-create-all';
97 case ChapterCreateOwn = 'chapter-create-own';
98 case ChapterDelete = 'chapter-delete';
99 case ChapterDeleteAll = 'chapter-delete-all';
100 case ChapterDeleteOwn = 'chapter-delete-own';
101 case ChapterUpdate = 'chapter-update';
102 case ChapterUpdateAll = 'chapter-update-all';
103 case ChapterUpdateOwn = 'chapter-update-own';
104 case ChapterView = 'chapter-view';
105 case ChapterViewAll = 'chapter-view-all';
106 case ChapterViewOwn = 'chapter-view-own';
108 case PageCreate = 'page-create';
109 case PageCreateAll = 'page-create-all';
110 case PageCreateOwn = 'page-create-own';
111 case PageDelete = 'page-delete';
112 case PageDeleteAll = 'page-delete-all';
113 case PageDeleteOwn = 'page-delete-own';
114 case PageUpdate = 'page-update';
115 case PageUpdateAll = 'page-update-all';
116 case PageUpdateOwn = 'page-update-own';
117 case PageView = 'page-view';
118 case PageViewAll = 'page-view-all';
119 case PageViewOwn = 'page-view-own';
122 * Get the generic permissions which may be queried for entities.
124 public static function genericForEntity(): array
135 * Return the application permission-check middleware-string for this permission.
136 * Uses registered CheckUserHasPermission middleware.
138 public function middleware(): string
140 return 'can:' . $this->value;