1616use OCA \Tables \Middleware \Attribute \RequirePermission ;
1717use OCA \Tables \Model \RowDataInput ;
1818use OCA \Tables \ResponseDefinitions ;
19+ use OCA \Tables \Service \ConfigService ;
1920use OCA \Tables \Service \FederationService ;
2021use OCA \Tables \Service \RowService ;
2122use OCA \Tables \Service \TableService ;
@@ -42,6 +43,7 @@ public function __construct(
4243 private TableService $ tableService ,
4344 private ViewService $ viewService ,
4445 private FederationService $ federationService ,
46+ private ConfigService $ configService ,
4547 ) {
4648 parent ::__construct ($ request , $ logger , $ n , $ userId );
4749 }
@@ -75,16 +77,8 @@ public function createRow(string $nodeCollection, int $nodeId, mixed $data): Dat
7577 $ tableId = $ viewId = null ;
7678 if ($ iNodeType === Application::NODE_TYPE_TABLE ) {
7779 $ tableId = $ nodeId ;
78- if ($ this ->federationService ->isNodeFederated ($ tableId , 'table ' )) {
79- $ table = $ this ->tableService ->find ($ nodeId , true );
80- return new DataResponse ($ this ->federationService ->createRow ($ table , $ data ));
81- }
8280 } elseif ($ iNodeType === Application::NODE_TYPE_VIEW ) {
8381 $ viewId = $ nodeId ;
84- if ($ this ->federationService ->isNodeFederated ($ viewId , 'view ' )) {
85- $ view = $ this ->viewService ->find ($ nodeId , false , $ this ->userId );
86- return new DataResponse ($ this ->federationService ->createRow ($ view , $ data ));
87- }
8882 }
8983
9084 $ newRowData = new RowDataInput ();
@@ -93,6 +87,16 @@ public function createRow(string $nodeCollection, int $nodeId, mixed $data): Dat
9387 }
9488
9589 try {
90+ if ($ this ->configService ->isFederationEnabled ()) {
91+ if ($ tableId !== null && $ this ->federationService ->isNodeFederated ($ tableId , 'table ' )) {
92+ $ table = $ this ->tableService ->find ($ nodeId , true );
93+ return new DataResponse ($ this ->federationService ->createRow ($ table , $ data ));
94+ }
95+ if ($ viewId !== null && $ this ->federationService ->isNodeFederated ($ viewId , 'view ' )) {
96+ $ view = $ this ->viewService ->find ($ nodeId , false , $ this ->userId );
97+ return new DataResponse ($ this ->federationService ->createRow ($ view , $ data ));
98+ }
99+ }
96100 return new DataResponse ($ this ->rowService ->create ($ tableId , $ viewId , $ newRowData )->jsonSerialize ());
97101 } catch (BadRequestError $ e ) {
98102 return $ this ->handleBadRequestError ($ e );
@@ -134,18 +138,20 @@ public function updateRow(string $nodeCollection, int $nodeId, int $rowId, mixed
134138 $ tableId = $ viewId = null ;
135139 if ($ iNodeType === Application::NODE_TYPE_TABLE ) {
136140 $ tableId = $ nodeId ;
137- if ($ this ->federationService ->isNodeFederated ($ tableId , 'table ' )) {
138- $ table = $ this ->tableService ->find ($ nodeId , true );
139- return new DataResponse ($ this ->federationService ->updateRow ($ table , $ rowId , $ data ));
140- }
141141 } elseif ($ iNodeType === Application::NODE_TYPE_VIEW ) {
142142 $ viewId = $ nodeId ;
143- if ($ this ->federationService ->isNodeFederated ($ viewId , 'view ' )) {
144- $ view = $ this ->viewService ->find ($ nodeId , false , $ this ->userId );
145- return new DataResponse ($ this ->federationService ->updateRow ($ view , $ rowId , $ data ));
146- }
147143 }
148144 try {
145+ if ($ this ->configService ->isFederationEnabled ()) {
146+ if ($ tableId !== null && $ this ->federationService ->isNodeFederated ($ tableId , 'table ' )) {
147+ $ table = $ this ->tableService ->find ($ nodeId , true );
148+ return new DataResponse ($ this ->federationService ->updateRow ($ table , $ rowId , $ data ));
149+ }
150+ if ($ viewId !== null && $ this ->federationService ->isNodeFederated ($ viewId , 'view ' )) {
151+ $ view = $ this ->viewService ->find ($ nodeId , false , $ this ->userId );
152+ return new DataResponse ($ this ->federationService ->updateRow ($ view , $ rowId , $ data ));
153+ }
154+ }
149155 return new DataResponse ($ this ->rowService ->updateSet ($ rowId , $ viewId , $ data , $ this ->userId , $ tableId )->jsonSerialize ());
150156 } catch (NotFoundError $ e ) {
151157 return $ this ->handleNotFoundError ($ e );
@@ -177,18 +183,20 @@ public function deleteRow(string $nodeCollection, int $nodeId, int $rowId): Data
177183 $ tableId = $ viewId = null ;
178184 if ($ iNodeType === Application::NODE_TYPE_TABLE ) {
179185 $ tableId = $ nodeId ;
180- if ($ this ->federationService ->isNodeFederated ($ tableId , 'table ' )) {
181- $ table = $ this ->tableService ->find ($ nodeId , true );
182- return new DataResponse ($ this ->federationService ->deleteRow ($ table , $ rowId ));
183- }
184186 } elseif ($ iNodeType === Application::NODE_TYPE_VIEW ) {
185187 $ viewId = $ nodeId ;
186- if ($ this ->federationService ->isNodeFederated ($ viewId , 'view ' )) {
187- $ view = $ this ->viewService ->find ($ nodeId , false , $ this ->userId );
188- return new DataResponse ($ this ->federationService ->deleteRow ($ view , $ rowId ));
189- }
190188 }
191189 try {
190+ if ($ this ->configService ->isFederationEnabled ()) {
191+ if ($ tableId !== null && $ this ->federationService ->isNodeFederated ($ tableId , 'table ' )) {
192+ $ table = $ this ->tableService ->find ($ nodeId , true );
193+ return new DataResponse ($ this ->federationService ->deleteRow ($ table , $ rowId ));
194+ }
195+ if ($ viewId !== null && $ this ->federationService ->isNodeFederated ($ viewId , 'view ' )) {
196+ $ view = $ this ->viewService ->find ($ nodeId , false , $ this ->userId );
197+ return new DataResponse ($ this ->federationService ->deleteRow ($ view , $ rowId ));
198+ }
199+ }
192200 return new DataResponse ($ this ->rowService ->delete ($ rowId , $ viewId , $ this ->userId , $ tableId )->jsonSerialize ());
193201 } catch (NotFoundError $ e ) {
194202 return $ this ->handleNotFoundError ($ e );
0 commit comments