diff --git a/lib/Alchemy/Phrasea/PhraseanetService/Controller/PSExposeController.php b/lib/Alchemy/Phrasea/PhraseanetService/Controller/PSExposeController.php index 6af7b9b0f3..25eadaa031 100644 --- a/lib/Alchemy/Phrasea/PhraseanetService/Controller/PSExposeController.php +++ b/lib/Alchemy/Phrasea/PhraseanetService/Controller/PSExposeController.php @@ -68,6 +68,87 @@ class PSExposeController extends Controller ]); } + /** + * Get list of user or group if param "groups" defined + * + * @param PhraseaApplication $app + * @param Request $request + * @return \Symfony\Component\HttpFoundation\JsonResponse + * + */ + public function listUsersAction(PhraseaApplication $app, Request $request) + { + $exposeConfiguration = $app['conf']->get(['phraseanet-service', 'expose-service', 'exposes'], []); + $exposeConfiguration = $exposeConfiguration[$request->get('exposeName')]; + + $userOrGroup = 'users'; + if ($request->get('groups')) { + $userOrGroup = 'groups'; + } + + $exposeClient = new Client(['base_uri' => $exposeConfiguration['expose_base_uri'], 'http_errors' => false]); + + $accessToken = $this->getAndSaveToken($exposeConfiguration); + + $response = $exposeClient->get('/permissions/' . $userOrGroup, [ + 'headers' => [ + 'Authorization' => 'Bearer '. $accessToken + ] + ]); + + $list = []; + if ($response->getStatusCode() == 200) { + $list = json_decode($response->getBody()->getContents(),true); + } + + return $app->json([ + 'list' => $list + ]); + } + + /** + * Add or update access control entry (ACE) for a publication + * + * @param PhraseaApplication $app + * @param Request $request + * @return \Symfony\Component\HttpFoundation\JsonResponse + */ + public function updatePublicationPermissionAction(PhraseaApplication $app, Request $request) + { + $exposeConfiguration = $app['conf']->get(['phraseanet-service', 'expose-service', 'exposes'], []); + $exposeConfiguration = $exposeConfiguration[$request->get('exposeName')]; + $exposeClient = new Client(['base_uri' => $exposeConfiguration['expose_base_uri'], 'http_errors' => false]); + + $accessToken = $this->getAndSaveToken($exposeConfiguration); + + try { + $response = $exposeClient->put('/permissions/ace', [ + 'headers' => [ + 'Authorization' => 'Bearer '. $accessToken, + 'Content-Type' => 'application/json' + ], + 'json' => $request->get('jsonData') + ]); + } catch(\Exception $e) { + return $this->app->json([ + 'success' => false, + 'message' => $e->getMessage() + ]); + } + + if ($response->getStatusCode() !== 200) { + return $this->app->json([ + 'success' => false, + 'message' => 'Status code: '. $response->getStatusCode() + ]); + } + + return $this->app->json([ + 'success' => true, + 'message' => 'Permission successfully updated!' + ]); + } + /** * Get list of publication * Use param "format=json" to retrieve a json diff --git a/lib/Alchemy/Phrasea/PhraseanetService/Provider/PSExposeServiceProvider.php b/lib/Alchemy/Phrasea/PhraseanetService/Provider/PSExposeServiceProvider.php index c377c2ad6d..dcfd9128b8 100644 --- a/lib/Alchemy/Phrasea/PhraseanetService/Provider/PSExposeServiceProvider.php +++ b/lib/Alchemy/Phrasea/PhraseanetService/Provider/PSExposeServiceProvider.php @@ -70,6 +70,14 @@ class PSExposeServiceProvider implements ControllerProviderInterface, ServicePro ->method('POST') ->bind('ps_expose_publication_add_assets'); + $controllers->match('/list/users', 'controller.ps.expose:listUsersAction') + ->method('GET') + ->bind('ps_expose_list_users'); + + $controllers->match('/publication/permission/update', 'controller.ps.expose:updatePublicationPermissionAction') + ->method('POST') + ->bind('ps_expose_publication_permission_update'); + return $controllers; } diff --git a/templates/web/prod/WorkZone/ExposeEdit.html.twig b/templates/web/prod/WorkZone/ExposeEdit.html.twig index a897781447..20dd855b16 100644 --- a/templates/web/prod/WorkZone/ExposeEdit.html.twig +++ b/templates/web/prod/WorkZone/ExposeEdit.html.twig @@ -113,6 +113,72 @@ +