|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace BookStack\Permissions; |
| 4 | + |
| 5 | +/** |
| 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. |
| 9 | + * |
| 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. |
| 13 | + */ |
| 14 | +enum Permission: string |
| 15 | +{ |
| 16 | + // Generic Actions |
| 17 | + // Used for more abstract entity permission checks |
| 18 | + case View = 'view'; |
| 19 | + case Create = 'create'; |
| 20 | + case Update = 'update'; |
| 21 | + case Delete = 'delete'; |
| 22 | + |
| 23 | + // System Permissions |
| 24 | + case AccessApi = 'access-api'; |
| 25 | + case ContentExport = 'content-export'; |
| 26 | + case ContentImport = 'content-import'; |
| 27 | + case EditorChange = 'editor-change'; |
| 28 | + case ReceiveNotifications = 'receive-notifications'; |
| 29 | + case RestrictionsManageAll = 'restrictions-manage-all'; |
| 30 | + case RestrictionsManageOwn = 'restrictions-manage-own'; |
| 31 | + case SettingsManage = 'settings-manage'; |
| 32 | + case TemplatesManage = 'templates-manage'; |
| 33 | + case UserRolesManage = 'user-roles-manage'; |
| 34 | + case UsersManage = 'users-manage'; |
| 35 | + |
| 36 | + // Entity permissions |
| 37 | + // Each has 'all' or 'own' in it's RolePermission, with the base non-suffix name being used |
| 38 | + // in actual checking logic, with the permission system handling the assessment of the underlying RolePermission. |
| 39 | + case AttachmentCreate = 'attachment-create'; |
| 40 | + case AttachmentCreateAll = 'attachment-create-all'; |
| 41 | + case AttachmentCreateOwn = 'attachment-create-own'; |
| 42 | + |
| 43 | + case AttachmentDelete = 'attachment-delete'; |
| 44 | + case AttachmentDeleteAll = 'attachment-delete-all'; |
| 45 | + case AttachmentDeleteOwn = 'attachment-delete-own'; |
| 46 | + |
| 47 | + case AttachmentUpdate = 'attachment-update'; |
| 48 | + case AttachmentUpdateAll = 'attachment-update-all'; |
| 49 | + case AttachmentUpdateOwn = 'attachment-update-own'; |
| 50 | + |
| 51 | + case BookCreate = 'book-create'; |
| 52 | + case BookCreateAll = 'book-create-all'; |
| 53 | + case BookCreateOwn = 'book-create-own'; |
| 54 | + |
| 55 | + case BookDelete = 'book-delete'; |
| 56 | + case BookDeleteAll = 'book-delete-all'; |
| 57 | + case BookDeleteOwn = 'book-delete-own'; |
| 58 | + |
| 59 | + case BookUpdate = 'book-update'; |
| 60 | + case BookUpdateAll = 'book-update-all'; |
| 61 | + case BookUpdateOwn = 'book-update-own'; |
| 62 | + |
| 63 | + case BookView = 'book-view'; |
| 64 | + case BookViewAll = 'book-view-all'; |
| 65 | + case BookViewOwn = 'book-view-own'; |
| 66 | + |
| 67 | + case BookshelfCreate = 'bookshelf-create'; |
| 68 | + case BookshelfCreateAll = 'bookshelf-create-all'; |
| 69 | + case BookshelfCreateOwn = 'bookshelf-create-own'; |
| 70 | + |
| 71 | + case BookshelfDelete = 'bookshelf-delete'; |
| 72 | + case BookshelfDeleteAll = 'bookshelf-delete-all'; |
| 73 | + case BookshelfDeleteOwn = 'bookshelf-delete-own'; |
| 74 | + |
| 75 | + case BookshelfUpdate = 'bookshelf-update'; |
| 76 | + case BookshelfUpdateAll = 'bookshelf-update-all'; |
| 77 | + case BookshelfUpdateOwn = 'bookshelf-update-own'; |
| 78 | + |
| 79 | + case BookshelfView = 'bookshelf-view'; |
| 80 | + case BookshelfViewAll = 'bookshelf-view-all'; |
| 81 | + case BookshelfViewOwn = 'bookshelf-view-own'; |
| 82 | + |
| 83 | + case ChapterCreate = 'chapter-create'; |
| 84 | + case ChapterCreateAll = 'chapter-create-all'; |
| 85 | + case ChapterCreateOwn = 'chapter-create-own'; |
| 86 | + |
| 87 | + case ChapterDelete = 'chapter-delete'; |
| 88 | + case ChapterDeleteAll = 'chapter-delete-all'; |
| 89 | + case ChapterDeleteOwn = 'chapter-delete-own'; |
| 90 | + |
| 91 | + case ChapterUpdate = 'chapter-update'; |
| 92 | + case ChapterUpdateAll = 'chapter-update-all'; |
| 93 | + case ChapterUpdateOwn = 'chapter-update-own'; |
| 94 | + |
| 95 | + case ChapterView = 'chapter-view'; |
| 96 | + case ChapterViewAll = 'chapter-view-all'; |
| 97 | + case ChapterViewOwn = 'chapter-view-own'; |
| 98 | + |
| 99 | + case CommentCreate = 'comment-create'; |
| 100 | + case CommentCreateAll = 'comment-create-all'; |
| 101 | + case CommentCreateOwn = 'comment-create-own'; |
| 102 | + |
| 103 | + case CommentDelete = 'comment-delete'; |
| 104 | + case CommentDeleteAll = 'comment-delete-all'; |
| 105 | + case CommentDeleteOwn = 'comment-delete-own'; |
| 106 | + |
| 107 | + case CommentUpdate = 'comment-update'; |
| 108 | + case CommentUpdateAll = 'comment-update-all'; |
| 109 | + case CommentUpdateOwn = 'comment-update-own'; |
| 110 | + |
| 111 | + case ImageCreate = 'image-create'; |
| 112 | + case ImageCreateAll = 'image-create-all'; |
| 113 | + case ImageCreateOwn = 'image-create-own'; |
| 114 | + |
| 115 | + case ImageDelete = 'image-delete'; |
| 116 | + case ImageDeleteAll = 'image-delete-all'; |
| 117 | + case ImageDeleteOwn = 'image-delete-own'; |
| 118 | + |
| 119 | + case ImageUpdate = 'image-update'; |
| 120 | + case ImageUpdateAll = 'image-update-all'; |
| 121 | + case ImageUpdateOwn = 'image-update-own'; |
| 122 | + |
| 123 | + case PageCreate = 'page-create'; |
| 124 | + case PageCreateAll = 'page-create-all'; |
| 125 | + case PageCreateOwn = 'page-create-own'; |
| 126 | + |
| 127 | + case PageDelete = 'page-delete'; |
| 128 | + case PageDeleteAll = 'page-delete-all'; |
| 129 | + case PageDeleteOwn = 'page-delete-own'; |
| 130 | + |
| 131 | + case PageUpdate = 'page-update'; |
| 132 | + case PageUpdateAll = 'page-update-all'; |
| 133 | + case PageUpdateOwn = 'page-update-own'; |
| 134 | + |
| 135 | + case PageView = 'page-view'; |
| 136 | + case PageViewAll = 'page-view-all'; |
| 137 | + case PageViewOwn = 'page-view-own'; |
| 138 | + |
| 139 | + /** |
| 140 | + * Get the generic permissions which may be queried for entities. |
| 141 | + */ |
| 142 | + public static function genericForEntity(): array |
| 143 | + { |
| 144 | + return [ |
| 145 | + self::View, |
| 146 | + self::Create, |
| 147 | + self::Update, |
| 148 | + self::Delete, |
| 149 | + ]; |
| 150 | + } |
| 151 | +} |
0 commit comments