3131use OCP \Collaboration \Resources \IResource ;
3232use OCP \Collaboration \Resources \ResourceException ;
3333use OCP \IRequest ;
34+ use OCP \IUserSession ;
3435
3536class CollaborationResourcesController extends OCSController {
37+
3638 /** @var IManager */
3739 private $ manager ;
3840
41+ /** @var IUserSession */
42+ private $ userSession ;
43+
3944 public function __construct (
40- $ appName ,
45+ string $ appName ,
4146 IRequest $ request ,
42- IManager $ manager
47+ IManager $ manager ,
48+ IUserSession $ userSession
4349 ) {
4450 parent ::__construct ($ appName , $ request );
4551
4652 $ this ->manager = $ manager ;
53+ $ this ->userSession = $ userSession ;
4754 }
4855
4956 /**
@@ -54,7 +61,7 @@ public function __construct(
5461 protected function getCollection (int $ collectionId ): ICollection {
5562 $ collection = $ this ->manager ->getCollection ($ collectionId );
5663
57- if (false ) { // TODO auth checking
64+ if (! $ collection -> canAccess ( $ this -> userSession -> getUser ())) {
5865 throw new CollectionException ('Not found ' );
5966 }
6067
@@ -141,12 +148,15 @@ public function removeResource(int $collectionId, string $resourceType, string $
141148 */
142149 public function getCollectionsByResource (string $ resourceType , string $ resourceId ): DataResponse {
143150 try {
144- // TODO auth checking
145151 $ resource = $ this ->manager ->getResource ($ resourceType , $ resourceId );
146152 } catch (CollectionException $ e ) {
147153 return new DataResponse ([], Http::STATUS_NOT_FOUND );
148154 }
149155
156+ if (!$ resource ->canAccess ($ this ->userSession ->getUser ())) {
157+ return new DataResponse ([], Http::STATUS_NOT_FOUND );
158+ }
159+
150160 return new DataResponse (array_map ([$ this , 'prepareCollection ' ], $ resource ->getCollections ()));
151161 }
152162
@@ -157,7 +167,8 @@ protected function prepareCollection(ICollection $collection): array {
157167 protected function prepareResources (IResource $ resource ): array {
158168 return [
159169 'type ' => $ resource ->getType (),
160- 'id ' => $ resource ->getId ()
170+ 'id ' => $ resource ->getId (),
171+ 'name ' => $ resource ->getName (),
161172 ];
162173 }
163174}
0 commit comments