src/Controller/ApiWebhookController.php line 655

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Model\OrganizationModel;
  4. use App\Model\PackageModel;
  5. use App\Service\RedisCache;
  6. use App\Service\EmailService;
  7. use Pimcore\Log\ApplicationLogger;
  8. use Pimcore\Controller\FrontendController;
  9. use Knp\Component\Pager\PaginatorInterface;
  10. use App\Service\PublicUserPermissionService;
  11. use Pimcore\Model\DataObject\Organization;
  12. use Pimcore\Model\DataObject\Package;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Symfony\Component\HttpFoundation\JsonResponse;
  17. use Symfony\Contracts\Translation\TranslatorInterface;
  18. use Symfony\Component\Security\Core\User\UserInterface;
  19. use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
  20. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  21. use Symfony\Component\Templating\EngineInterface;
  22. use Pimcore\Model\DataObject\Customer;
  23. use Pimcore\Model\DataObject;
  24. use App\Model\UserModel;
  25. use App\Model\ReportLogModel;
  26. use App\Model\PermissionUserGroupModel;
  27. class ApiWebhookController extends FrontendController
  28. {
  29.     private $organizationModel;
  30.     private $userModel;
  31.     private $reportModel;
  32.     private $packageModel;
  33.     private $permissionUserGroupModel;
  34.     public function __construct(
  35.         private TokenStorageInterface $tokenStorageInterface,
  36.         private JWTTokenManagerInterface $jwtManager,
  37.         private PublicUserPermissionService $publicUserPermissionService,
  38.         protected TranslatorInterface $translator,
  39.         private ApplicationLogger $logger,
  40.         private EmailService $emailService,
  41.         private EngineInterface $templating,
  42.     ) {
  43.         // header('Content-Type: application/json; charset=UTF-8');
  44.         // header("Access-Control-Allow-Origin: *");
  45.         $this->publicUserPermissionService $publicUserPermissionService;
  46.         $this->organizationModel = new OrganizationModel();
  47.         $this->userModel = new UserModel();
  48.         $this->packageModel = new PackageModel($templating);
  49.         $this->permissionUserGroupModel = new PermissionUserGroupModel();
  50.         $this->reportModel = new ReportLogModel();
  51.     }
  52.     /**
  53.      * @Route("api/webhook/add-ncm-user", methods={"POST"})
  54.      */
  55.     public function addNCMUser(Request $requestEngineInterface $templating): JsonResponse
  56.     {
  57.         try {
  58.             $response $this->publicUserPermissionService->isAuthorized($request$this->translator);
  59.             if ($response['success'] !== true) {
  60.                 return $this->json($response);
  61.             }
  62.             $user $response['user'];
  63.             $params json_decode($request->getContent(), true);
  64.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  65.             $requiredParameters = [
  66.                 'name',
  67.                 'email',
  68.                 'role',
  69.                 'allowedApiGrpups'
  70.             ];
  71.             // if (isset($params['role']) && ($params['role'] == USER_ROLES['NCM_OPERATOR'])) {
  72.             //     array_push($requiredParameters, "disallowedApiGroups");
  73.             // }
  74.             foreach ($requiredParameters as $param) {
  75.                 if (!isset($params[$param])) {
  76.                     $missingParams[] = $param;
  77.                 }
  78.             }
  79.             if (!empty($missingParams)) {
  80.                 // Throw an exception with a message that includes the missing parameters
  81.                 $parameterList implode(", "$missingParams);
  82.                 return $this->json(['success' => false'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
  83.             }
  84.             $name $params['name'];
  85.             $email $params['email'];
  86.             $role = isset($params['role']) ? $params['role'] : USER_ROLES['NCM_OPERATOR'];
  87.             $userTagId = isset($params['tagId']) ? $params['tagId'] : null;
  88.             $isNoExpiry = (isset($params['isNoExpiry']) ? $params['isNoExpiry'] : false);
  89.             $password $params['password'];
  90.             $hostName NCM_ADMIN_HOST_NAME;
  91.             $phone = isset($params['phone']) ? $params['phone'] : null;
  92.             // $disallowedApiGroupsArray = isset($params['disallowedApiGroups']) ? $params['disallowedApiGroups'] : [];
  93.             $allowedApiGrpups $params['allowedApiGrpups'];
  94.             $result $this->organizationModel->adminAddInviteNCMUser(
  95.                 $request,
  96.                 $this->translator,
  97.                 $email,
  98.                 $name,
  99.                 $role,
  100.                 $userTagId,
  101.                 $hostName,
  102.                 $user,
  103.                 $allowedApiGrpups,
  104.                 $templating,
  105.                 $isNoExpiry,
  106.                 $phone,
  107.                 $password
  108.             );
  109.             return $this->json($result);
  110.         } catch (\Exception $ex) {
  111.             $this->logger->error($ex->getMessage());
  112.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  113.         }
  114.     }
  115.     /**
  116.      * @Route("api/webhook/edit-ncm-user" , methods={"POST"})
  117.      */
  118.     public function editNCMUser(Request $request,): JsonResponse
  119.     {
  120.         try {
  121.             $response $this->publicUserPermissionService->isAuthorized($request$this->translator);
  122.             if ($response['success'] !== true) {
  123.                 return $this->json($response);
  124.             }
  125.             $user $response['user'];
  126.             $params  json_decode($request->getContent(), true);
  127.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  128.             $requiredParameters = [
  129.                 'id',
  130.                 'role'
  131.             ];
  132.             foreach ($requiredParameters as $param) {
  133.                 if (!isset($params[$param]) || empty($params[$param])) {
  134.                     $missingParams[] = $param;
  135.                 }
  136.             }
  137.             if (!empty($missingParams)) {
  138.                 // Throw an exception with a message that includes the missing parameters
  139.                 $parameterList implode(", "$missingParams);
  140.                 return $this->json(['success' => false'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
  141.             }
  142.             $customer Customer::getByEmail($params['email'], true);
  143.             if (!$customer instanceof \Pimcore\Model\DataObject\Customer) {
  144.                 throw new \Exception("User not found");
  145.             }
  146.             $params['id'] = $customer->getId();
  147.             $loggedInUser Customer::getByEmail($params['loggedInUserEmail'], true);
  148.             if (!$loggedInUser instanceof \Pimcore\Model\DataObject\Customer) {
  149.                 throw new \Exception("User not found");
  150.             }
  151.             //validate Role first
  152.             if (isset($params['role'])) {
  153.                 $loggedInUserRole $loggedInUser->getRole()->getName();
  154.                 if (!array_key_exists($params['role'], USER_ROLES)) {
  155.                     return $this->json(["success" => false"message" => $this->translator->trans($params['role'] . "_is_not_available_in_role_list .")]);
  156.                 } elseif ($loggedInUserRole == USER_ROLES['CLIENT_USER'] && ($params['role'] == USER_ROLES['NCM_OPERATOR'] || $params['role'] == USER_ROLES['NCM_IT'] || $params['role'] == USER_ROLES['CLIENT_ADMIN'])) {
  157.                     return $this->json(["success" => false"message" => $this->translator->trans(USER_ROLES[$loggedInUserRole] . "_can_not_add_" USER_ROLES[$params['role']] . "_role.")]);
  158.                 } elseif ($loggedInUserRole == USER_ROLES['CLIENT_ADMIN'] && ($params['role'] == USER_ROLES['NCM_IT'] || $params['role'] == USER_ROLES['NCM_OPERATOR'])) {
  159.                     return $this->json(["success" => false"message" => $this->translator->trans(USER_ROLES[$loggedInUserRole] . "_can_not_add_" USER_ROLES[$params['role']] . "._role")]);
  160.                 } elseif ($loggedInUserRole == USER_ROLES['NCM_OPERATOR'] && ($params['role'] == USER_ROLES['NCM_IT'])) {
  161.                     return $this->json(["success" => false"message" => $this->translator->trans(USER_ROLES[$loggedInUserRole] . "_can_not_add_" USER_ROLES[$params['role']] . "._role")]);
  162.                 } elseif ($params['role'] == USER_ROLES['CLIENT_ADMIN'] || $params['role'] == USER_ROLES['CLIENT_USER']) {
  163.                     return $this->json(["success" => false"message" => $this->translator->trans(USER_ROLES[$params['role']] . "_is_not_available_in_NCM_ROLES")]);
  164.                 }
  165.             }
  166.             // Perform parameter validation here
  167.             if (!isset($params['id'])) {
  168.                 return $this->json(['success' => false'message' =>  $this->translator->trans('missing_required_parameters')]);
  169.             }
  170.             // Perform parameter validation here
  171.             if (isset($params['password']) && $loggedInUserRole != USER_ROLES['NCM_IT']) {
  172.                 return $this->json(['success' => false'message' =>  $this->translator->trans('only_' USER_ROLES['NCM_IT'] . '_can_change_password')]);
  173.             }
  174.             $params['loggedInUser'] = $loggedInUser;
  175.             // Call the editUser method and get the result
  176.             $result $this->userModel->editNCMUser($params$this->translator);
  177.             return $this->json($result);
  178.         } catch (\Exception $ex) {
  179.             $this->logger->error($ex->getMessage());
  180.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  181.         }
  182.     }
  183.     /**
  184.      * @Route("api/webhook/update-profile", methods={"POST"})
  185.      */
  186.     public function updateProfile(Request $request): JsonResponse
  187.     {
  188.         try {
  189.             $response $this->publicUserPermissionService->isAuthorized($request$this->translator);
  190.             if ($response['success'] !== true) {
  191.                 return $this->json($response);
  192.             }
  193.             $user $response['user'];
  194.             $params  json_decode($request->getContent(), true);
  195.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  196.             // Perform parameter validation here
  197.             if (!isset($params['id']) || !isset($params['name']) || !isset($params['department']) || !isset($params['title'])) {
  198.                 return $this->json(['success' => false'message' => $this->translator->trans('missing_required_parameters')]);
  199.             }
  200.             $userByEmail Customer::getByEmail($params['userEmail'], true);
  201.             if (!$userByEmail instanceof \Pimcore\Model\DataObject\Customer) {
  202.                 throw new \Exception("User not found");
  203.             }
  204.             $params["id"] = $userByEmail->getId();
  205.             // Call the updateProfile method and get the result
  206.             $result $this->userModel->updateProfile($params$this->translator);
  207.             return $this->json($result);
  208.         } catch (\Exception $ex) {
  209.             $this->logger->error($ex->getMessage());
  210.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  211.         }
  212.     }
  213.     /**
  214.      * @Route("api/webhook/change-password", methods={"POST"})
  215.      */
  216.     public function changePassword(Request $request): JsonResponse
  217.     {
  218.         try {
  219.             $response $this->publicUserPermissionService->isAuthorized($request$this->translator);
  220.             if ($response['success'] !== true) {
  221.                 return $this->json($response);
  222.             }
  223.             $user $response['user'];
  224.             $params  json_decode($request->getContent(), true);
  225.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  226.             $userByEmail Customer::getByEmail($params['userEmail'], true);
  227.             if (!$userByEmail instanceof \Pimcore\Model\DataObject\Customer) {
  228.                 throw new \Exception("User not found");
  229.             }
  230.             // Perform parameter validation here
  231.             if (!isset($params['oldPassword']) || !isset($params['newPassword']) || !isset($params['confirmNewPassword'])) {
  232.                 return $this->json(['success' => false'message' => $this->translator->trans('missing_required_parameters')]);
  233.             }
  234.             // Call the changePassword method and get the result
  235.             $result $this->userModel->changePassword($userByEmail$params$this->translator);
  236.             return $this->json($result);
  237.         } catch (\Exception $ex) {
  238.             $this->logger->error($ex->getMessage());
  239.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  240.         }
  241.     }
  242.     /**
  243.      * @Route("api/webhook/create-organization", methods={"POST"})
  244.      */
  245.     public function createOrganization(Request $request)
  246.     {
  247.         try {
  248.             $response $this->publicUserPermissionService->isAuthorized($request$this->translator);
  249.             if ($response['success'] !== true) {
  250.                 return $this->json($response);
  251.             }
  252.             $user $response['user'];
  253.             $params json_decode($request->getContent(), true);
  254.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  255.             $id $params['id'] ?? 0000;
  256.             $entExist Organization::getById($idtrue);
  257.             if ($entExist instanceof Organization) {
  258.                 $createNameEn trim(strip_tags($params['name']));
  259.                 $entExist->setUniqueId($params['uniqueId']);
  260.                 $entExist->setName($createNameEn'en');
  261.                 $entExist->setName(isset($params['nameAr']) ? trim(strip_tags($params['nameAr'])) : $createNameEn'ar');
  262.                 $entExist->save();
  263.                 return $this->json(['success' => false'message' => $this->translator->trans("organization_already_exists")]);
  264.             }
  265.             // Perform parameter validation here
  266.             $requiredParameters = [
  267.                 'clientType',
  268.                 'name'
  269.             ];
  270.             foreach ($requiredParameters as $param) {
  271.                 if (!isset($params[$param]) || empty($params[$param])) {
  272.                     $missingParams[] = $param;
  273.                 }
  274.             }
  275.             if (!empty($missingParams)) {
  276.                 // Throw an exception with a message that includes the missing parameters
  277.                 $parameterList implode(", "$missingParams);
  278.                 return $this->json(['success' => false'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
  279.             }
  280.             $userByEmail Customer::getByEmail($params['userEmail'], true);
  281.             if (!$userByEmail instanceof \Pimcore\Model\DataObject\Customer) {
  282.                 throw new \Exception("User not found");
  283.             }
  284.             $packageObj = new Package\Listing();
  285.             $packageObj->setLocale('en');
  286.             $packageObj->setCondition("packageName = ?"$params['packageName']);
  287.             $packageObj->setLimit(1);
  288.             $pObj $packageObj->current();
  289.             $params['packageId'] = $pObj $pObj->getId() : 16145;
  290.             // Call the createOrganization method and get the result
  291.             $result $this->organizationModel->createEntity($request$params$userByEmail$this->translator);
  292.             return $this->json($result);
  293.         } catch (\Exception $ex) {
  294.             $this->logger->error($ex->getMessage());
  295.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  296.         }
  297.     }
  298.     /**
  299.      * @Route("api/webhook/edit-organization", methods={"POST"})
  300.      */
  301.     public function updateOrganization(Request $request)
  302.     {
  303.         try {
  304.             $params  json_decode($request->getContent(), true);
  305.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  306.             if (empty($params["uniqueId"])) {
  307.                 return $this->json(['success' => false'message' => $this->translator->trans("Unique ID is required")]);
  308.             }
  309.             $result $this->organizationModel->editOrganization($request$params$this->packageModel$this->translator);
  310.             return $this->json($result);
  311.         } catch (\Exception $ex) {
  312.             $this->logger->error($ex->getMessage());
  313.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  314.         }
  315.     }
  316.     /**
  317.      * @Route("api/webhook/delete-organization", methods={"POST"})
  318.      */
  319.     public function deleteOrganization(Request $request)
  320.     {
  321.         try {
  322.             $params  json_decode($request->getContent(), true);
  323.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  324.             if (empty($params["uniqueId"])) {
  325.                 return $this->json(['success' => false'message' => $this->translator->trans("Unique ID is required")]);
  326.             }
  327.             $userByEmail Customer::getByEmail($params['userEmail'], true);
  328.             if (!$userByEmail instanceof \Pimcore\Model\DataObject\Customer) {
  329.                 throw new \Exception("User not found");
  330.             }
  331.             $result $this->organizationModel->deleteOrganization($userByEmail$params$this->translator);
  332.             return $this->json($result);
  333.         } catch (\Exception $ex) {
  334.             $this->logger->error($ex->getMessage());
  335.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  336.         }
  337.     }
  338.     /**
  339.      * @Route("api/webhook/get-api-groups", methods={"POST"})
  340.      */
  341.     public function getApiGroups(Request $request)
  342.     {
  343.         try {
  344.             $params  json_decode($request->getContent(), true);
  345.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  346.             $result $this->packageModel->listReportingApiGroups($params$this->translator);
  347.             return $this->json($result);
  348.         } catch (\Exception $ex) {
  349.             $this->logger->error($ex->getMessage());
  350.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  351.         }
  352.     }
  353.     /**
  354.      * @Route("api/webhook/create-permission-user-group", methods={"POST"})
  355.      */
  356.     public function createPermissionUserGroup(Request $request)
  357.     {
  358.         try {
  359.             $params  json_decode($request->getContent(), true);
  360.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  361.             $user $this->getUser();
  362.             $result $this->permissionUserGroupModel->createPermissionUserGroup(
  363.                 $params["name"],
  364.                 $params["description"] ?? '',
  365.                 $params["apiGroupIds"],
  366.                 $user,
  367.                 $this->translator
  368.             );
  369.             return $this->json($result);
  370.         } catch (\Exception $ex) {
  371.             $this->logger->error($ex->getMessage());
  372.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  373.         }
  374.     }
  375.     /**
  376.      * @Route("api/webhook/edit-permission-user-group", methods={"POST"})
  377.      */
  378.     public function editPermissionUserGroup(Request $request)
  379.     {
  380.         try {
  381.             $params  json_decode($request->getContent(), true);
  382.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  383.             $user $this->getUser();
  384.             $result $this->permissionUserGroupModel->editPermissionUserGroup(
  385.                 $params,
  386.                 $this->translator
  387.             );
  388.             return $this->json($result);
  389.         } catch (\Exception $ex) {
  390.             $this->logger->error($ex->getMessage());
  391.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  392.         }
  393.     }
  394.     /**
  395.      * @Route("api/webhook/delete-permission-user-group", methods={"POST"})
  396.      */
  397.     public function deletePermissionUserGroup(Request $request)
  398.     {
  399.         try {
  400.             $params  json_decode($request->getContent(), true);
  401.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  402.             $user $this->getUser();
  403.             $result $this->permissionUserGroupModel->deletePermissionUserGroup(
  404.                 $params,
  405.                 $this->translator
  406.             );
  407.             return $this->json($result);
  408.         } catch (\Exception $ex) {
  409.             $this->logger->error($ex->getMessage());
  410.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  411.         }
  412.     }
  413.     /**
  414.      * @Route("api/webhook/list-permission-user-groups", methods={"POST"})
  415.      */
  416.     public function listPermissionUserGroups(Request $requestPaginatorInterface $paginator)
  417.     {
  418.         try {
  419.             $params  json_decode($request->getContent(), true);
  420.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  421.             $result $this->permissionUserGroupModel->listPermissionUserGroups($params$paginator);
  422.             return $this->json($result);
  423.         } catch (\Exception $ex) {
  424.             $this->logger->error($ex->getMessage());
  425.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  426.         }
  427.     }
  428.     /**
  429.      * @Route("api/webhook/add-reporting-user", methods={"POST"})
  430.      */
  431.     public function addReportingUser(Request $request)
  432.     {
  433.         try {
  434.             $params  json_decode($request->getContent(), true);
  435.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  436.             $result $this->userModel->addReportingUser($params$this->translator);
  437.             if ($result['success'] == true) {
  438.                 return $this->json(['success' => true'message' => $this->translator->trans("user_created_successfully")]);
  439.             }
  440.             return $this->json(['success' => false'message' => $result['message']]);
  441.         } catch (\Exception $ex) {
  442.             $this->logger->error($ex->getMessage());
  443.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  444.         }
  445.     }
  446.     /**
  447.      * @Route("api/webhook/invite-reporting-user", methods={"POST"})
  448.      */
  449.     public function inviteReportingUser(Request $requestEngineInterface $templating)
  450.     {
  451.         try {
  452.             $params  json_decode($request->getContent(), true);
  453.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  454.             $result $this->userModel->inviteReportingUser($params$templating$this->translator);
  455.             if ($result['success'] == true) {
  456.                 return $this->json(['success' => true'message' => $this->translator->trans("user_invited_successfully")]);
  457.             }
  458.             return $this->json(['success' => false'message' => $result['message']]);
  459.         } catch (\Exception $ex) {
  460.             $this->logger->error($ex->getMessage());
  461.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  462.         }
  463.     }
  464.     /**
  465.      * @Route("api/webhook/resend-reporting-user-invite" , methods={"POST"})
  466.      */
  467.     public function resendReportingUserInvite(Request $requestEngineInterface $templating): JsonResponse
  468.     {
  469.         try {
  470.             $params json_decode($request->getContent(), true);
  471.             // $response = $this->publicUserPermissionService->isAuthorized($request, $this->translator);
  472.             // if ($response['success'] !== true) {
  473.             //     return $this->json($response);
  474.             // }
  475.             // Perform parameter validation here
  476.             if (!isset($params['id'])) {
  477.                 return $this->json(['success' => false'message' =>  $this->translator->trans('missing_required_parameter_id')]);
  478.             }
  479.             // Call the resendEwsUserInvite method and get the result
  480.             $result $this->userModel->resendReportingUserInvite($params$templating$this->translator);
  481.             return $this->json($result);
  482.         } catch (\Exception $ex) {
  483.             $this->logger->error($ex->getMessage());
  484.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  485.         }
  486.     }
  487.     /**
  488.      * @Route("api/webhook/list-reporting-users", methods={"POST"})
  489.      */
  490.     public function listReportingUsers(Request $requestPaginatorInterface $paginator)
  491.     {
  492.         try {
  493.             $params  json_decode($request->getContent(), true);
  494.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  495.             $result $this->userModel->listReportingUsers($params$paginator$this->translator);
  496.             return $this->json($result);
  497.         } catch (\Exception $ex) {
  498.             $this->logger->error($ex->getMessage());
  499.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  500.         }
  501.     }
  502.     /**
  503.      * @Route("api/webhook/edit-reporting-user" , methods={"POST"})
  504.      */
  505.     public function editReportingUser(Request $request,): JsonResponse
  506.     {
  507.         try {
  508.             $params json_decode($request->getContent(), true);
  509.             $response $this->publicUserPermissionService->isAuthorized($request$this->translator);
  510.             if ($response['success'] !== true) {
  511.                 return $this->json($response);
  512.             }
  513.             // Perform parameter validation here
  514.             if (!isset($params['id'])) {
  515.                 return $this->json(['success' => false'message' =>  $this->translator->trans('missing_required_parameter_id')]);
  516.             }
  517.             // Call the editUser method and get the result
  518.             $result $this->userModel->editReportingUser($params$this->translator);
  519.             return $this->json($result);
  520.         } catch (\Exception $ex) {
  521.             $this->logger->error($ex->getMessage());
  522.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  523.         }
  524.     }
  525.     /**
  526.      * @Route("api/webhook/delete-reporting-user", methods={"POST"})
  527.      */
  528.     public function deleteUserReportingUser(Request $request): JsonResponse
  529.     {
  530.         try {
  531.             $response $this->publicUserPermissionService->isAuthorized($request$this->translator);
  532.             if ($response['success'] !== true) {
  533.                 return $this->json($response);
  534.             }
  535.             $params  json_decode($request->getContent(), true);
  536.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  537.             if (!isset($params['id']) || empty($params['id'])) {
  538.                 return $this->json(['success' => false'message' => $this->translator->trans("missing_required_parameter_user_id")]);
  539.             }
  540.             // Normalize id to array for single or multiple user delete
  541.             $params['id'] = is_array($params['id']) ? array_values(array_filter($params['id'])) : [$params['id']];
  542.             $result $this->userModel->deleteUserReportingUser($params$this->translator);
  543.             return $this->json($result);
  544.         } catch (\Exception $ex) {
  545.             return $this->json(['success' => false'message' =>  $ex->getMessage()]);
  546.         }
  547.     }
  548.     /**
  549.      * @Route("api/webhook/get-latest-report", methods={"POST"})
  550.      */
  551.     public function getLatestReport(Request $request): JsonResponse
  552.     {
  553.         try {
  554.             // $response = $this->publicUserPermissionService->isAuthorized($request, $this->translator);
  555.             // if ($response['success'] !== true) {
  556.             //     return $this->json($response);
  557.             // }
  558.             $params  json_decode($request->getContent(), true);
  559.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  560.            
  561.             // Call the editUser method and get the result
  562.             $result $this->reportModel->getLatestReport($params['reportType'], $this->translator,false);
  563.             return $this->json($result);
  564.         } catch (\Exception $ex) {
  565.             return $this->json(['success' => false'message' =>  $ex->getMessage()]);
  566.         }
  567.     }
  568.     /**
  569.      * @Route("api/webhook/assign-bulk-reporting-user-permission-group", name="assign_bulk_reporting_user_permission_group", methods={"POST"})
  570.      */    
  571.     public function assignBulkReportingUserPermissionGroup(Request $request): JsonResponse
  572.     {
  573.         try {
  574.             $params json_decode($request->getContent(), true);
  575.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  576.             $response $this->publicUserPermissionService->isAuthorized($request$this->translator);
  577.             if ($response['success'] !== true) {
  578.                 return $this->json($response);
  579.             }
  580.             // Perform parameter validation here
  581.             if (!isset($params["userIds"]) || empty($params["userIds"]) || !is_array($params["userIds"])) {
  582.                 return $this->json(['success' => false'message' => $this->translator->trans("User_ids_are_required")]);
  583.             }
  584.             if (!isset($params["tagId"])) {
  585.                 return $this->json(['success' => false'message' => $this->translator->trans("tag_id_is_required")]);
  586.             }
  587.             // Call the editUser method and get the result
  588.             $result $this->userModel->assignBulkReportingUserPermissionGroup($params$this->translator);
  589.             return $this->json($result);
  590.         } catch (\Exception $ex) {
  591.             $this->logger->error($ex->getMessage());
  592.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  593.         }
  594.     }
  595.     /**
  596.      * @Route("api/webhook/assign-bulk-reporting-user-tag", name="assign_bulk_reporting_user_tag", methods={"POST"})
  597.      */
  598.     public function assignBulkReportingUserTag(Request $request): JsonResponse
  599.     {
  600.         try {
  601.             $params json_decode($request->getContent(), true);
  602.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  603.             $response $this->publicUserPermissionService->isAuthorized($request$this->translator);
  604.             if ($response['success'] !== true) {
  605.                 return $this->json($response);
  606.             }
  607.             // Perform parameter validation here
  608.             if (!isset($params["userIds"]) || empty($params["userIds"]) || !is_array($params["userIds"])) {
  609.                 return $this->json(['success' => false'message' => $this->translator->trans("User_ids_are_required")]);
  610.             }
  611.             if (!isset($params["tagIds"]) || empty($params["tagIds"]) || !is_array($params["tagIds"])) {
  612.                 return $this->json(['success' => false'message' => $this->translator->trans("Tag_ids_are_required")]);
  613.             }
  614.             // Call the assignBulkReportingUserTag method and get the result
  615.             $result $this->userModel->assignBulkReportingUserTag($params$this->translator);
  616.             return $this->json($result);
  617.         } catch (\Exception $ex) {
  618.             $this->logger->error($ex->getMessage());
  619.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  620.         }
  621.     }
  622.     /**
  623.      * @Route("api/webhook/create-reporting-tag", name="create_reporting_tag", methods={"POST"})
  624.      */
  625.     public function createReportingTag(Request $request): JsonResponse
  626.     {
  627.         try {
  628.             $params json_decode($request->getContent(), true);
  629.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  630.             $response $this->publicUserPermissionService->isAuthorized($request$this->translator);
  631.             if ($response['success'] !== true) {
  632.                 return $this->json($response);
  633.             }
  634.             // Perform parameter validation here
  635.             if (!isset($params["name"]) || empty($params["name"])) {
  636.                 return $this->json(['success' => false'message' => $this->translator->trans("Name_is_required")]);
  637.             }
  638.             // Call the createReportingTag method and get the result
  639.             $result $this->userModel->createReportingTag($params$this->translator);
  640.             return $this->json($result);
  641.         } catch (\Exception $ex) {
  642.             $this->logger->error($ex->getMessage());
  643.             return $this->json(['success' => false'message' => $ex->getMessage()]);
  644.         }
  645.     }
  646.     /**
  647.      * @Route("api/webhook/list-reporting-tags", name="list_reporting_tags", methods={"POST"})
  648.      */
  649.     public function listReportingTags(Request $requestPaginatorInterface $paginator): JsonResponse
  650.     {
  651.         try {
  652.             $params json_decode($request->getContent(), true);
  653.             $this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
  654.             $response $this->publicUserPermissionService->isAuthorized($request$this->translator);
  655.             if ($response['success'] !== true) {
  656.                 return $this->json($response);
  657.             }
  658.             
  659.             // Call the listReportingTags method and get the result
  660.             $result $this->userModel->listReportingTags($params$this->translator$paginator);
  661.             if ($result['success'] == true) {
  662.                 return $this->json(['success' => true'data' => $result['data'], 'paginationVariables' => $result['paginationVariables']]);
  663.             }
  664.             return $this->json(['success' => false'message' => $result['message'] ?? $this->translator->trans(USER_ERROR_MESSAGE)]);
  665.         } catch (\Exception $ex) {
  666.             $this->logger->error($ex->getMessage());
  667.             return $this->json(['success' => false'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
  668.         }
  669.     }   
  670. }