From 69ccdefb51d4b766d3c1541f07cc8f4cedc2018b Mon Sep 17 00:00:00 2001 From: Aina Sitraka <35221835+aynsix@users.noreply.github.com> Date: Wed, 26 Oct 2022 00:21:25 +0300 Subject: [PATCH] PHRAS-3754 admin - user detail - Record ACL tab (#4148) * record acl tab in admin * fix email locked, limit record right to 200 * fix * add filter * update * feed element, basket element * feed list * feed entries * when not expand * some improvement --- .../Controller/Admin/UserController.php | 87 ++- .../ControllerProvider/Admin/Users.php | 4 + lib/Alchemy/Phrasea/Helper/User/Edit.php | 131 +++++ .../Repositories/BasketElementRepository.php | 46 ++ .../Repositories/FeedEntryRepository.php | 21 + .../Model/Repositories/FeedItemRepository.php | 49 ++ .../Model/Repositories/FeedRepository.php | 11 + .../WorkerRunningJobRepository.php | 1 - templates/web/admin/editusers.html.twig | 499 +++++++++++++----- .../web/admin/user/records_list.html.twig | 34 ++ 10 files changed, 742 insertions(+), 141 deletions(-) create mode 100644 templates/web/admin/user/records_list.html.twig diff --git a/lib/Alchemy/Phrasea/Controller/Admin/UserController.php b/lib/Alchemy/Phrasea/Controller/Admin/UserController.php index de776bfeaf..0d4d171d91 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/UserController.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/UserController.php @@ -16,16 +16,20 @@ use Alchemy\Phrasea\Controller\Controller; use Alchemy\Phrasea\Core\Response\CSVFileResponse; use Alchemy\Phrasea\Helper\User as UserHelper; use Alchemy\Phrasea\Model\Entities\AuthFailure; +use Alchemy\Phrasea\Model\Entities\Feed; use Alchemy\Phrasea\Model\Entities\FtpCredential; use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\Entities\WebhookEvent; use Alchemy\Phrasea\Model\Manipulator\RegistrationManipulator; use Alchemy\Phrasea\Model\Manipulator\UserManipulator; use Alchemy\Phrasea\Model\NativeQueryProvider; +use Alchemy\Phrasea\Model\Repositories\FeedEntryRepository; +use Alchemy\Phrasea\Model\Repositories\FeedRepository; use Alchemy\Phrasea\Model\Repositories\RegistrationRepository; use Alchemy\Phrasea\Model\Repositories\UserRepository; use Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate; use Alchemy\Phrasea\Notification\Receiver; +use Doctrine\ORM\EntityManager; use Goodby\CSV\Export\Protocol\ExporterInterface; use Goodby\CSV\Import\Standard\Interpreter; use Symfony\Component\HttpFoundation\Request; @@ -39,7 +43,88 @@ class UserController extends Controller public function editRightsAction(Request $request) { $rights = $this->getUserEditHelper($request); - return $this->render('admin/editusers.html.twig', $rights->get_users_rights()); + + return $this->render('admin/editusers.html.twig', + array_merge($rights->get_user_records_rights(), + $rights->getFeeds(), + $rights->getBasketElements(), + $rights->get_users_rights()) + ); + } + + public function listRecordAcl(Request $request) + { + $rights = $this->getUserEditHelper($request); + $results = $rights->get_user_records_rights($request->query->get('userId'), $request->query->get('databoxId'), $request->query->get('recordId')); + + return $this->app->json([ + 'content' => $this->render('admin/user/records_list.html.twig', ['records_acl' => $results['records_acl']]), + 'total_count' => $results['total_count'], + 'total_result' => count($results['records_acl']) + ]); + } + + public function deleteFeedEntry(Request $request) + { + /** @var EntityManager $manager */ + $manager = $this->app['orm.em']; + /** @var FeedEntryRepository $feedEntryRepo */ + $feedEntryRepo = $this->app['repo.feed-entries']; + + /** @var Feed|null $feed */ + $feedEntry = $feedEntryRepo->find($request->request->get('feedEntryId')); + + if ($feedEntry == null) { + return $this->app->json(['success' => false, 'message' => 'publication not found']); + } + + $manager->remove($feedEntry); + $manager->flush(); + + return $this->app->json(['success' => true]); + } + + public function listFeedEntry(Request $request) + { + /** @var UserRepository $userRepo */ + $userRepo = $this->app['repo.users']; + $user = $userRepo->find($request->query->get('userId')); + + // when not expand + if ($request->query->get('feedId') == null) { + return $this->app->json(['content' => '']); + } + + /** @var FeedRepository $feedsRepository */ + $feedsRepository = $this->app['repo.feeds']; + /** @var Feed|null $feed */ + $feed = $feedsRepository->find($request->query->get('feedId')); + + if ($feed == null || $user == null) { + return $this->app->json(['content' => 'Give feed_id or user_id']); + } else { + /** @var FeedEntryRepository $feedEntryRepo */ + $feedEntryRepo = $this->app['repo.feed-entries']; + $feedEntryRepo->getByUserAndFeed($user, $feed); + + return $this->app->json(['content' => $this->render('admin/user/records_list.html.twig', [ + 'feed_entries' => $feedEntryRepo->getByUserAndFeed($user, $feed) + ]), + 'feed_entries_count' => $feedEntryRepo->getByUserAndFeed($user, $feed, true) + ]); + } + } + + public function listRecordBasket(Request $request) + { + $rights = $this->getUserEditHelper($request); + $results = $rights->getBasketElements($request->query->get('userId'), $request->query->get('databoxId'), $request->query->get('recordId')); + + return $this->app->json([ + 'content' => $this->render('admin/user/records_list.html.twig', ['basket_elements' => $results['basket_elements']]), + 'total_count' => $results['basket_elements_count'], + 'total_result' => count($results['basket_elements']) + ]); } public function resetRightsAction(Request $request) diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Users.php b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Users.php index eb0a893a39..136724400f 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Admin/Users.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Admin/Users.php @@ -86,6 +86,10 @@ class Users implements ControllerProviderInterface, ServiceProviderInterface ->bind('users_import_csv'); $controllers->get('/import/example/rtf/', 'controller.admin.users:importRtfExampleAction') ->bind('users_import_rtf'); + $controllers->get('/records-acl/', 'controller.admin.users:listRecordAcl'); + $controllers->get('/feed-entry/', 'controller.admin.users:listFeedEntry'); + $controllers->post('/feed-entry/delete/', 'controller.admin.users:deleteFeedEntry'); + $controllers->get('/records-basket/', 'controller.admin.users:listRecordBasket'); return $controllers; } diff --git a/lib/Alchemy/Phrasea/Helper/User/Edit.php b/lib/Alchemy/Phrasea/Helper/User/Edit.php index 357324c647..3457c2a1bc 100644 --- a/lib/Alchemy/Phrasea/Helper/User/Edit.php +++ b/lib/Alchemy/Phrasea/Helper/User/Edit.php @@ -15,8 +15,12 @@ use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application\Helper\NotifierAware; use Alchemy\Phrasea\Core\LazyLocator; use Alchemy\Phrasea\Exception\InvalidArgumentException; +use Alchemy\Phrasea\Model\Entities\Feed; use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\Manipulator\UserManipulator; +use Alchemy\Phrasea\Model\Repositories\BasketElementRepository; +use Alchemy\Phrasea\Model\Repositories\FeedEntryRepository; +use Alchemy\Phrasea\Model\Repositories\FeedRepository; use Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate; use Alchemy\Phrasea\Notification\Receiver; use Doctrine\DBAL\Connection; @@ -205,6 +209,133 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper return $out; } + public function getFeeds($userId = null) + { + if (empty($userId)) { + if (count($this->users) == 1) { + $userId = current($this->users); + } else { + return [ + 'feeds' => [], + ]; + } + } + + $user = $this->app['repo.users']->find($userId); + + /** @var FeedRepository $feedsRepository */ + $feedsRepository = $this->app['repo.feeds']; + $feeds = $feedsRepository->getUserFeed($user); + + /** @var FeedEntryRepository $feedEntryRepo */ + $feedEntryRepo = $this->app['repo.feed-entries']; + + $feedCount = []; + /** @var Feed $feed */ + foreach ($feeds as $feed) { + $feedCount[$feed->getId()] = $feedEntryRepo->getByUserAndFeed($user, $feed, true); + } + + return [ + 'feeds' => $feedsRepository->getUserFeed($user), + 'feeds_count' => $feedCount + ]; + } + + public function getBasketElements($userId = null, $databoxId = null, $recordId = null) + { + if (empty($userId)) { + if (count($this->users) == 1) { + $userId = current($this->users); + } else { + return [ + 'basket_elements' => [], + ]; + } + } + + $user = $this->app['repo.users']->find($userId); + + /** @var BasketElementRepository $basketElementRepository */ + $basketElementRepository = $this->app['repo.basket-elements']; + + return [ + 'basket_elements' => $basketElementRepository->getElements($user, $databoxId, $recordId), + 'basket_elements_count' => $basketElementRepository->getElementsCount($user, $databoxId, $recordId) + ]; + } + + public function get_user_records_rights($userId = null, $databoxId = null, $recordId = null) + { + $rows = []; + $totalCount = 0; + + $databoxIds = array_map(function (\databox $databox) { + return $databox->get_sbas_id(); + }, + $this->app->getApplicationBox()->get_databoxes() + ); + + if (empty($userId)) { + if (count($this->users) == 1) { + $userId = current($this->users); + } else { + return [ + 'records_acl' => $rows, + 'total_count' => $totalCount, + 'databoxIds' => $databoxIds + ]; + } + } + + $whereClause = "WHERE rr.usr_id = :usr_id"; + $params[':usr_id'] = $userId; + + if (!empty($databoxId)) { + $whereClause .= " AND rr.sbas_id= :databox_id"; + $params[':databox_id'] = $databoxId; + } + + if (!empty($recordId)) { + $whereClause .= " AND rr.record_id= :record_id"; + $params[':record_id'] = $recordId; + } + + $sql = "SELECT rr.sbas_id, rr.record_id, rr.preview, rr.document, rr.`case` as type, \n" + . "IF(TRIM(p.last_name)!='' OR TRIM(p.first_name)!='', \n" + . " CONCAT_WS(' ', p.last_name, p.first_name),\n" + . " IF(TRIM(p.email)!='', p.email, p.login)\n" + . ") as pusher_name\n" + . " FROM records_rights rr \n" + . " INNER JOIN sbas ON sbas.sbas_id = rr.sbas_id\n" + . " JOIN Users as p ON p.id = rr.pusher_usr_id\n" + . $whereClause + . " ORDER BY rr.id DESC limit 200 \n" + ; + + $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); + $stmt->execute($params); + $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC); + $stmt->closeCursor(); + + $sql = "SELECT count(*) as nb \n" + . " FROM records_rights rr \n" + . " INNER JOIN sbas ON sbas.sbas_id = rr.sbas_id\n" + . $whereClause + ; + + $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); + $stmt->execute($params); + $totalCount = $stmt->fetchColumn(); + $stmt->closeCursor(); + + return [ + 'records_acl' => $rows, + 'total_count' => $totalCount, + 'databoxIds' => $databoxIds + ]; + } + public function get_quotas() { $this->base_id = (int) $this->request->get('base_id'); diff --git a/lib/Alchemy/Phrasea/Model/Repositories/BasketElementRepository.php b/lib/Alchemy/Phrasea/Model/Repositories/BasketElementRepository.php index 59834b6054..53fdf6d7e0 100644 --- a/lib/Alchemy/Phrasea/Model/Repositories/BasketElementRepository.php +++ b/lib/Alchemy/Phrasea/Model/Repositories/BasketElementRepository.php @@ -233,4 +233,50 @@ DQL; return $builder->getQuery()->getResult(); } + + public function getElements(User $user, $databoxId = null, $recordId = null, $nbElement = 200) + { + $qb = $this->createQueryBuilder('be'); + $qb->innerJoin('be.basket', 'b'); + + $qb->where($qb->expr()->eq('b.user', ':user')); + $qb->setParameter(':user', $user); + + if ($databoxId != null) { + $qb->andWhere('be.sbas_id = :databoxId'); + $qb->setParameter(':databoxId', $databoxId); + } + + if ($recordId != null) { + $qb->andWhere('be.record_id = :recordId'); + $qb->setParameter(':recordId', $recordId); + } + + $qb->orderBy('be.id', 'DESC'); + $qb->setMaxResults($nbElement); + + return $qb->getQuery()->getResult(); + } + + public function getElementsCount(User $user, $databoxId = null, $recordId = null) + { + $qb = $this->createQueryBuilder('be'); + $qb->select('count(be)'); + $qb->innerJoin('be.basket', 'b'); + + $qb->where($qb->expr()->eq('b.user', ':user')); + $qb->setParameter(':user', $user); + + if ($databoxId != null) { + $qb->andWhere('be.sbas_id = :databoxId'); + $qb->setParameter(':databoxId', $databoxId); + } + + if ($recordId != null) { + $qb->andWhere('be.record_id = :recordId'); + $qb->setParameter(':recordId', $recordId); + } + + return $qb->getQuery()->getSingleScalarResult(); + } } diff --git a/lib/Alchemy/Phrasea/Model/Repositories/FeedEntryRepository.php b/lib/Alchemy/Phrasea/Model/Repositories/FeedEntryRepository.php index cff09597ad..20b5837c2a 100644 --- a/lib/Alchemy/Phrasea/Model/Repositories/FeedEntryRepository.php +++ b/lib/Alchemy/Phrasea/Model/Repositories/FeedEntryRepository.php @@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Model\Repositories; use Alchemy\Phrasea\Model\Entities\Feed; use Alchemy\Phrasea\Model\Entities\FeedEntry; +use Alchemy\Phrasea\Model\Entities\User; use Doctrine\ORM\EntityRepository; /** @@ -64,4 +65,24 @@ class FeedEntryRepository extends EntityRepository return $builder->getQuery()->getSingleScalarResult(); } + + public function getByUserAndFeed(User $user, Feed $feed, $isCount = false) + { + $qb = $this->createQueryBuilder('fe'); + + $qb->innerJoin('fe.publisher', 'fp'); + $qb->where($qb->expr()->eq('fp.user', ':publisher')); + $qb->setParameter(':publisher', $user); + + $qb->andWhere($qb->expr()->eq('fe.feed', ':feed')); + $qb->setParameter(':feed', $feed); + + if ($isCount) { + $qb->select('count(fe)'); + return $qb->getQuery()->getSingleScalarResult(); + } else { + $qb->orderBy('fe.id', 'DESC'); + return $qb->getQuery()->getResult(); + } + } } diff --git a/lib/Alchemy/Phrasea/Model/Repositories/FeedItemRepository.php b/lib/Alchemy/Phrasea/Model/Repositories/FeedItemRepository.php index 59345d2a6d..2819267efd 100644 --- a/lib/Alchemy/Phrasea/Model/Repositories/FeedItemRepository.php +++ b/lib/Alchemy/Phrasea/Model/Repositories/FeedItemRepository.php @@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Model\Repositories; use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Model\Entities\FeedItem; +use Alchemy\Phrasea\Model\Entities\User; use Doctrine\ORM\EntityRepository; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -103,4 +104,52 @@ class FeedItemRepository extends EntityRepository return $items; } + + public function getItemsCount(User $user, $databoxId = null, $recordId = null) + { + $qb = $this->createQueryBuilder('fi'); + $qb->select('count(fi)'); + $qb->innerjoin('fi.entry', 'fe'); + $qb->innerjoin('fe.publisher', 'fp'); + + $qb->where($qb->expr()->eq('fp.user', ':publisher')); + $qb->setParameter(':publisher', $user); + + if ($databoxId != null) { + $qb->andWhere('fi.sbasId = :databoxId'); + $qb->setParameter(':databoxId', $databoxId); + } + + if ($recordId != null) { + $qb->andWhere('fi.recordId = :recordId'); + $qb->setParameter(':recordId', $recordId); + } + + return $qb->getQuery()->getSingleScalarResult(); + } + + public function getLastItems(User $user, $databoxId = null, $recordId = null, $nbItems = 200) + { + $qb = $this->createQueryBuilder('fi'); + $qb->innerjoin('fi.entry', 'fe'); + $qb->innerjoin('fe.publisher', 'fp'); + + $qb->where($qb->expr()->eq('fp.user', ':publisher')); + $qb->setParameter(':publisher', $user); + + if ($databoxId != null) { + $qb->andWhere('fi.sbasId = :databoxId'); + $qb->setParameter(':databoxId', $databoxId); + } + + if ($recordId != null) { + $qb->andWhere('fi.recordId = :recordId'); + $qb->setParameter(':recordId', $recordId); + } + + $qb->orderBy('fi.id', 'DESC'); + $qb->setMaxResults($nbItems); + + return $qb->getQuery()->getResult(); + } } diff --git a/lib/Alchemy/Phrasea/Model/Repositories/FeedRepository.php b/lib/Alchemy/Phrasea/Model/Repositories/FeedRepository.php index 87ebb1e104..2d16a30a80 100644 --- a/lib/Alchemy/Phrasea/Model/Repositories/FeedRepository.php +++ b/lib/Alchemy/Phrasea/Model/Repositories/FeedRepository.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\Model\Repositories; use Alchemy\Phrasea\Model\Entities\Feed; +use Alchemy\Phrasea\Model\Entities\User; use Doctrine\ORM\EntityRepository; /** @@ -108,4 +109,14 @@ class FeedRepository extends EntityRepository return $qb->getQuery()->getResult(); } + + public function getUserFeed(User $user) + { + $qb = $this->createQueryBuilder('f'); + $qb->innerJoin('f.publishers', 'fp'); + $qb->where($qb->expr()->eq('fp.user', ':publisher')); + $qb->setParameter(':publisher', $user); + + return $qb->getQuery()->getResult(); + } } diff --git a/lib/Alchemy/Phrasea/Model/Repositories/WorkerRunningJobRepository.php b/lib/Alchemy/Phrasea/Model/Repositories/WorkerRunningJobRepository.php index d6c61589f6..f1db1d1cb3 100644 --- a/lib/Alchemy/Phrasea/Model/Repositories/WorkerRunningJobRepository.php +++ b/lib/Alchemy/Phrasea/Model/Repositories/WorkerRunningJobRepository.php @@ -472,7 +472,6 @@ class WorkerRunningJobRepository extends EntityRepository } return $qb->getQuery()->getSingleScalarResult(); - } public function updateStatusRunningToCanceledSinceCreated($hour = 0) diff --git a/templates/web/admin/editusers.html.twig b/templates/web/admin/editusers.html.twig index 4cc94fbab2..794079e1ab 100644 --- a/templates/web/admin/editusers.html.twig +++ b/templates/web/admin/editusers.html.twig @@ -80,6 +80,24 @@ width: 70%; } + #basket_tab table, #basket_tab th, + #feed_tab table, #feed_tab th, + #record_acl_tab table, + #record_acl_tab th { + border: 1px solid #a5a0a0; + border-collapse: collapse; + text-align: center; + padding:0px 10px; + } + + #basket_tab td, + #feed_tab td, + #record_acl_tab td{ + border-right: 1px solid #a5a0a0; + border-left: 1px solid #a5a0a0; + padding:0px 10px; + } + #api_tab th, #api_tab td, #auth_failure_tab th, @@ -92,6 +110,10 @@
+ {% if main_user is not empty %} +

{{ main_user.getDisplayName() ~ ' ( ' ~ main_user.getId() ~' )'}}

+ {% endif %} +
@@ -434,126 +465,129 @@ {% if main_user is not empty and main_user.isTemplate is empty and main_user.isSpecial is empty %}
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +
- {{ 'admin::compte-utilisateur identifiant' | trans }} - - -
- {{ 'admin::compte-utilisateur sexe' | trans }} - - -
- {{ 'admin::compte-utilisateur prenom' | trans }} - - -
- {{ 'admin::compte-utilisateur nom' | trans }} - - -
- {{ 'admin::compte-utilisateur email' | trans }} - - -
- {{ 'admin::compte-utilisateur adresse' | trans }} - - -
- {{ 'admin::compte-utilisateur code postal' | trans }} - - -
- {{ 'admin::compte-utilisateur ville' | trans }} - - -
- {{ 'admin::compte-utilisateur poste' | trans }} - - -
- {{ 'admin::compte-utilisateur societe' | trans }} - - -
- {{ 'admin::compte-utilisateur activite' | trans }} - - -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - -
+ {{ 'admin::compte-utilisateur identifiant' | trans }} + + +
+ {{ 'admin::compte-utilisateur sexe' | trans }} + + +
+ {{ 'admin::compte-utilisateur prenom' | trans }} + + +
+ {{ 'admin::compte-utilisateur nom' | trans }} + + +
+ {{ 'admin::compte-utilisateur email' | trans }} + + +
+ {{ 'admin::compte-utilisateur adresse' | trans }} + + +
+ {{ 'admin::compte-utilisateur code postal' | trans }} + + +
+ {{ 'admin::compte-utilisateur ville' | trans }} + + +
+ {{ 'admin::compte-utilisateur poste' | trans }} + + +
+ {{ 'admin::compte-utilisateur societe' | trans }} + + +
+ {{ 'admin::compte-utilisateur activite' | trans }} + + +
- {{ 'admin::compte-utilisateur telephone' | trans }} - - -
- {{ 'admin::compte-utilisateur fax' | trans }} - - -
-
+ + + {{ 'admin::compte-utilisateur telephone' | trans }} + + + + + + + + {{ 'admin::compte-utilisateur fax' | trans }} + + + + + + + - +
+ + + + +
{% set usrProviders = app['repo.usr-auth-providers'].findByUser(main_user) %} @@ -701,6 +735,98 @@ {% endif %}
+ +
+

User record acl

+
+ + + +
+ +

{{ records_acl|length }} / {{ total_count }} (last 200 rights displayed)

+ + + + + + + + + + + + + {% for r_a in records_acl %} + + + + + + + + + {% endfor %} + +
databox namerecord_idright on documentright on subdeftypepusher name
{{ r_a.sbas_id | sbas_labels(app) }}{{ r_a.record_id }}{{ r_a.document }}{{ r_a.preview }}{{ r_a.type }}{{ r_a.pusher_name }}
+
+ +
+

{{ "User's publications in feeds" | trans}}

+
+ {% for f in feeds %} +
+ {{ f.title }} + {% if f.public %}public{% endif %} + + {{ feeds_count[f.getId()] }} publication(s) + +
+
+ {% endfor %} +
+
+ +
+

User basket

+ +
+ + + +
+ +

{{ basket_elements|length }} / {{ basket_elements_count }} (last 200 basket records displayed)

+ + + + + + + + + + {% for b_e in basket_elements %} + + + + + + {% endfor %} + +
databox namerecord_idBasket name
{{ b_e.getSbasId() | sbas_labels(app) }}{{ b_e.getRecordId() }}{{ b_e.basket.name }}
+
+ {% endif %}
@@ -1209,7 +1335,15 @@ ini_edit_usrs(); - $('div.tabs').tabs(); + $('div.tabs').tabs({ + activate:function( event, ui ) { + if (ui.newPanel.selector === '#rights_tab' || ui.newPanel.selector === '#user_infos_tab') { + $("#right-ajax .form-actions").removeClass('hidden'); + } else { + $("#right-ajax .form-actions").addClass('hidden'); + } + } + }); $('#users_rights_form button#reset_rights').bind('click', function () { if (confirm("{{ 'Are you sure you want to reset rights?' | trans }}")) { @@ -1316,29 +1450,116 @@ }); }); - $('#mail_locked_activation').on('click', function() { - let $this = $(this); - $.ajax({ - type: 'POST', - url: '/admin/users/mail-locked/change/', - dataType: 'json', - data: { - user_id: {{ main_user.getId() }}, - action: $this.is(':checked') ? 'locked' : 'unlocked' - }, - success: function (data) { - if (data.success == true) { - if ($this.is(':checked')) { - $('.mail-locked-label').removeClass('hidden'); - $('.mail-unlocked-label').addClass('hidden'); - } else { - $('.mail-locked-label').addClass('hidden'); - $('.mail-unlocked-label').removeClass('hidden'); - } + $('input[type=radio][name="email-locked"]').change( function() { + let $this = $(this); + $.ajax({ + type: 'POST', + url: '/admin/users/mail-locked/change/', + dataType: 'json', + data: { + user_id: {{ main_user.getId() }}, + action: $this.val() + }, + success: function (data) { } + }); + }); + + function listRecordAcl() { + $.ajax({ + type: "GET", + url: "/admin/users/records-acl/", + data: { + databoxId : $("#acl-databox-filter").val(), + recordId : $("#acl-record-filter").val(), + userId: {{ main_user.getId() }} + }, + success: function (data) { + $("#record_acl_list").empty().html(data.content); + $(".acl-result-count").empty().text(data.total_result + ' / ' + data.total_count); + } + }); + } + + function listRecordBasket() { + $.ajax({ + type: "GET", + url: "/admin/users/records-basket/", + data: { + databoxId : $("#basket-databox-filter").val(), + recordId : $("#basket-record-filter").val(), + userId: {{ main_user.getId() }} + }, + success: function (data) { + $("#record_basket_list").empty().html(data.content); + $(".basket-result-count").empty().text(data.total_result + ' / ' + data.total_count); + } + }); + } + + function listFeedEntry(userId, feedId, dest) { + $.ajax({ + type: 'GET', + url: '/admin/users/feed-entry/', + dataType: 'json', + data: { + userId: userId, + feedId: feedId + }, + success: function (data) { + dest.empty().html(data.content); + dest.siblings('.ui-state-active').find(".publication-count").text(data.feed_entries_count); + } + }); + } + + $("#acl-databox-filter").on('change', function() { + listRecordAcl(); + }); + + $("#acl-record-filter").on('input', function() { + listRecordAcl(); + }); + + $("#basket-databox-filter").on('change', function() { + listRecordBasket(); + }); + + $("#basket-record-filter").on('input', function() { + listRecordBasket(); + }); + + $("#feeds-list").accordion({ + active: false, + heightStyle: 'content', + collapsible: true, + autoHeight: true, + fillSpace: true, + activate: function(){ + let dest = $(this).find('.ui-state-active').next('.feed-content'); + let feedId = $(this).find('.ui-state-active').attr('data-feed'); + + listFeedEntry({{ main_user.getId() }}, feedId, dest) } }); - }); + + $("#feed_tab").on('click', '.delete-publication', function() { + let feedId = $(this).closest('.feed-content').attr('data-feed'); + let dest = $(this).closest('.feed-content'); + if(confirm('This delete the publication "' + $(this).siblings('.publication-name').text() + '"')) { + $.ajax({ + type: "POST", + url: "/admin/users/feed-entry/delete/", + data: { + feedEntryId : $(this).attr('data-feed-entry'), + }, + success: function (data) { + listFeedEntry({{ main_user.getId() }}, feedId, dest) + } + }); + } + }); + {% endif %} }); diff --git a/templates/web/admin/user/records_list.html.twig b/templates/web/admin/user/records_list.html.twig new file mode 100644 index 0000000000..3e4ce00bd7 --- /dev/null +++ b/templates/web/admin/user/records_list.html.twig @@ -0,0 +1,34 @@ +{% for r_a in records_acl %} + + {{ r_a.sbas_id | sbas_labels(app) }} + {{ r_a.record_id }} + {{ r_a.document }} + {{ r_a.preview }} + {{ r_a.type }} + {{ r_a.pusher_name }} + +{% endfor %} + +{% if feed_entries is defined %} + {% if feed_entries | length > 0 %} +
    + {% for f_e in feed_entries %} +
  • + {{ f_e.title }} + ({{ f_e.getItems() | length }} records) + +
  • + {% endfor %} +
+ {% else %} +

No publication

+ {% endif %} +{% endif %} + +{% for b_e in basket_elements %} + + {{ b_e.getSbasId() | sbas_labels(app) }} + {{ b_e.getRecordId() }} + {{ b_e.basket.name }} + +{% endfor %}