66 */
77namespace OCA \Tables \Controller ;
88
9+ use OCA \Tables \AppInfo \Application ;
910use OCA \Tables \Dto \Column as ColumnDto ;
1011use OCA \Tables \Errors \InternalError ;
1112use OCA \Tables \Errors \NotFoundError ;
1213use OCA \Tables \Errors \PermissionError ;
14+ use OCA \Tables \Middleware \Attribute \RequirePermission ;
1315use OCA \Tables \ResponseDefinitions ;
1416use OCA \Tables \Service \ColumnService ;
1517use OCP \AppFramework \Http ;
18+ use OCP \AppFramework \Http \Attribute \NoAdminRequired ;
1619use OCP \AppFramework \Http \DataResponse ;
1720use OCP \IL10N ;
1821use OCP \IRequest ;
@@ -39,8 +42,6 @@ public function __construct(
3942 *
4043 * Return an empty array if no columns were found
4144 *
42- * @NoAdminRequired
43- *
4445 * @param int $nodeId Node ID
4546 * @param 'table'|'view' $nodeType Node type
4647 * @return DataResponse<Http::STATUS_OK, TablesColumn[], array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
@@ -49,6 +50,8 @@ public function __construct(
4950 * 403: No permissions
5051 * 404: Not found
5152 */
53+ #[NoAdminRequired]
54+ #[RequirePermission(permission: Application::PERMISSION_READ )]
5255 public function index (int $ nodeId , string $ nodeType ): DataResponse {
5356 try {
5457 if ($ nodeType === 'table ' ) {
@@ -71,15 +74,14 @@ public function index(int $nodeId, string $nodeType): DataResponse {
7174 /**
7275 * [api v2] Get a column object
7376 *
74- * @NoAdminRequired
75- *
7677 * @param int $id Column ID
7778 * @return DataResponse<Http::STATUS_OK, TablesColumn, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
7879 *
7980 * 200: Column returned
8081 * 403: No permissions
8182 * 404: Not found
8283 */
84+ #[NoAdminRequired]
8385 public function show (int $ id ): DataResponse {
8486 try {
8587 return new DataResponse ($ this ->service ->find ($ id )->jsonSerialize ());
@@ -97,8 +99,6 @@ public function show(int $id): DataResponse {
9799 *
98100 * Specify a subtype to use any special numbered column
99101 *
100- * @NoAdminRequired
101- *
102102 * @param int $baseNodeId Context of the column creation
103103 * @param string $title Title
104104 * @param boolean $mandatory Is mandatory
@@ -121,6 +121,8 @@ public function show(int $id): DataResponse {
121121 * @throws NotFoundError
122122 * @throws PermissionError
123123 */
124+ #[NoAdminRequired]
125+ #[RequirePermission(permission: Application::PERMISSION_MANAGE , typeParam: 'baseNodeType ' , idParam: 'baseNodeId ' )]
124126 public function createNumberColumn (int $ baseNodeId , string $ title , ?float $ numberDefault , ?int $ numberDecimals , ?string $ numberPrefix , ?string $ numberSuffix , ?float $ numberMin , ?float $ numberMax , ?string $ subtype = null , ?string $ description = null , ?array $ selectedViewIds = [], bool $ mandatory = false , string $ baseNodeType = 'table ' ): DataResponse {
125127 $ tableId = $ baseNodeType === 'table ' ? $ baseNodeId : null ;
126128 $ viewId = $ baseNodeType === 'view ' ? $ baseNodeId : null ;
@@ -151,8 +153,6 @@ public function createNumberColumn(int $baseNodeId, string $title, ?float $numbe
151153 *
152154 * Specify a subtype to use any special text column
153155 *
154- * @NoAdminRequired
155- *
156156 * @param int $baseNodeId Context of the column creation
157157 * @param string $title Title
158158 * @param string|null $textDefault Default
@@ -172,6 +172,8 @@ public function createNumberColumn(int $baseNodeId, string $title, ?float $numbe
172172 * @throws NotFoundError
173173 * @throws PermissionError
174174 */
175+ #[NoAdminRequired]
176+ #[RequirePermission(permission: Application::PERMISSION_MANAGE , typeParam: 'baseNodeType ' , idParam: 'baseNodeId ' )]
175177 public function createTextColumn (int $ baseNodeId , string $ title , ?string $ textDefault , ?string $ textAllowedPattern , ?int $ textMaxLength , ?string $ subtype = null , ?string $ description = null , ?array $ selectedViewIds = [], bool $ mandatory = false , string $ baseNodeType = 'table ' ): DataResponse {
176178 $ tableId = $ baseNodeType === 'table ' ? $ baseNodeId : null ;
177179 $ viewId = $ baseNodeType === 'view ' ? $ baseNodeId : null ;
@@ -199,8 +201,6 @@ public function createTextColumn(int $baseNodeId, string $title, ?string $textDe
199201 *
200202 * Specify a subtype to use any special selection column
201203 *
202- * @NoAdminRequired
203- *
204204 * @param int $baseNodeId Context of the column creation
205205 * @param string $title Title
206206 * @param string $selectionOptions Json array{id: int, label: string} with options that can be selected, eg [{"id": 1, "label": "first"},{"id": 2, "label": "second"}]
@@ -219,6 +219,8 @@ public function createTextColumn(int $baseNodeId, string $title, ?string $textDe
219219 * @throws NotFoundError
220220 * @throws PermissionError
221221 */
222+ #[NoAdminRequired]
223+ #[RequirePermission(permission: Application::PERMISSION_MANAGE , typeParam: 'baseNodeType ' , idParam: 'baseNodeId ' )]
222224 public function createSelectionColumn (int $ baseNodeId , string $ title , string $ selectionOptions , ?string $ selectionDefault , ?string $ subtype = null , ?string $ description = null , ?array $ selectedViewIds = [], bool $ mandatory = false , string $ baseNodeType = 'table ' ): DataResponse {
223225 $ tableId = $ baseNodeType === 'table ' ? $ baseNodeId : null ;
224226 $ viewId = $ baseNodeType === 'view ' ? $ baseNodeId : null ;
@@ -245,8 +247,6 @@ public function createSelectionColumn(int $baseNodeId, string $title, string $se
245247 *
246248 * Specify a subtype to use any special datetime column
247249 *
248- * @NoAdminRequired
249- *
250250 * @param int $baseNodeId Context of the column creation
251251 * @param string $title Title
252252 * @param 'today'|'now'|null $datetimeDefault For a subtype 'date' you can set 'today'. For a main type or subtype 'time' you can set to 'now'.
@@ -264,6 +264,8 @@ public function createSelectionColumn(int $baseNodeId, string $title, string $se
264264 * @throws NotFoundError
265265 * @throws PermissionError
266266 */
267+ #[NoAdminRequired]
268+ #[RequirePermission(permission: Application::PERMISSION_MANAGE , typeParam: 'baseNodeType ' , idParam: 'baseNodeId ' )]
267269 public function createDatetimeColumn (int $ baseNodeId , string $ title , ?string $ datetimeDefault , ?string $ subtype = null , ?string $ description = null , ?array $ selectedViewIds = [], bool $ mandatory = false , string $ baseNodeType = 'table ' ): DataResponse {
268270 $ tableId = $ baseNodeType === 'table ' ? $ baseNodeId : null ;
269271 $ viewId = $ baseNodeType === 'view ' ? $ baseNodeId : null ;
@@ -287,8 +289,6 @@ public function createDatetimeColumn(int $baseNodeId, string $title, ?string $da
287289 /**
288290 * [api v2] Create new usergroup column
289291 *
290- * @NoAdminRequired
291- *
292292 * @param int $baseNodeId Context of the column creation
293293 * @param string $title Title
294294 * @param string|null $usergroupDefault Json array{id: string, type: int}, eg [{"id": "admin", "type": 0}, {"id": "user1", "type": 0}]
@@ -309,6 +309,8 @@ public function createDatetimeColumn(int $baseNodeId, string $title, ?string $da
309309 * @throws NotFoundError
310310 * @throws PermissionError
311311 */
312+ #[NoAdminRequired]
313+ #[RequirePermission(permission: Application::PERMISSION_MANAGE , typeParam: 'baseNodeType ' , idParam: 'baseNodeId ' )]
312314 public function createUsergroupColumn (int $ baseNodeId , string $ title , ?string $ usergroupDefault , bool $ usergroupMultipleItems = null , bool $ usergroupSelectUsers = null , bool $ usergroupSelectGroups = null , bool $ showUserStatus = null , string $ description = null , ?array $ selectedViewIds = [], bool $ mandatory = false , string $ baseNodeType = 'table ' ): DataResponse {
313315 $ tableId = $ baseNodeType === 'table ' ? $ baseNodeId : null ;
314316 $ viewId = $ baseNodeType === 'view ' ? $ baseNodeId : null ;
0 commit comments