From 4a13c3e6155c9537c6f8a46ece48bef63322197a Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 23 Jul 2019 03:39:53 +0000 Subject: [PATCH 1/5] Create PrivacyPolicy entity. Add links from Customer to PrivacyPolicy. #233 --- src/Entity/Customer.php | 56 +++++++++++++++++ src/Entity/PrivacyPolicy.php | 116 +++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 src/Entity/PrivacyPolicy.php diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index 08c39293..d1576621 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -147,6 +147,27 @@ class Customer */ protected $priv_promo; + /** + * @ORM\ManyToOne(targetEntity="PrivacyPolicy", inversedBy="cust_mobile_app") + * @ORM\JoinColumn(name="mobile_policy_id", referencedColumnName="id") + * @Assert\NotBlank() + */ + protected $privpol_mobile_app; + + /** + * @ORM\ManyToOne(targetEntity="PrivacyPolicy", inversedBy="cust_third_party") + * @ORM\JoinColumn(name="third_party_policy_id", referencedColumnName="id") + * @Assert\NotBlank() + */ + protected $privpol_third_party; + + /** + * @ORM\ManyToOne(targetEntity="PrivacyPolicy", inversedBy="cust_promo") + * @ORM\JoinColumn(name="promo_policy_id", referencedColumnName="id") + * @Assert\NotBlank() + */ + protected $privpol_promo; + public function __construct() { $this->numbers = new ArrayCollection(); @@ -433,4 +454,39 @@ class Customer { return $this->priv_promo; } + + public function setPrivacyPolicyMobile($privpol_mobile_app) + { + $this->privpol_mobile_app = $privpol_mobile_app; + return $this; + } + + public function getPrivacyPolicyMobile() + { + return $this->privpol_mobile_app; + } + + public function setPrivacyPolicyThirdParty($privpol_third_party) + { + $this->privpol_third_party = $privpol_third_party; + return $this; + } + + public function getPrivacyPolicyThirdParty() + { + return $this->privpol_third_party; + } + + public function setPrivacyPolicyPromo($privpol_promo) + { + $this->privpol_promo = $privpol_promo; + return $this; + } + + public function getPrivacyPolicyPromo() + { + return $this->privpol_promo; + } + + } diff --git a/src/Entity/PrivacyPolicy.php b/src/Entity/PrivacyPolicy.php new file mode 100644 index 00000000..b59ee551 --- /dev/null +++ b/src/Entity/PrivacyPolicy.php @@ -0,0 +1,116 @@ +id; + } + + public function setName($name) + { + $this->name = $name; + return $this; + } + + public function getName() + { + return $this->name; + } + + public function setContent($content) + { + $this->content = $content; + return $this; + } + + public function getContent() + { + return $this->content; + } + + public function setCustMobileApp($cust_mobile_app) + { + $this->cust_mobile_app = $cust_mobile_app; + return $this; + } + + public function getCustMobileApp() + { + return $this->cust_mobile_app; + } + + public function setCustThirdParty($cust_third_party) + { + $this->cust_third_party = $cust_third_party; + return $this; + } + + public function getCustThirdParty() + { + return $this->cust_third_party; + } + + public function setCustPromo($cust_promo) + { + $this->cust_promo = $cust_promo; + return $this; + } + + public function getCustPromo() + { + return $this->cust_promo; + } + + + + + +} + From 1535fd9cd96d877a4b8bdb770e9ec4bab6edf4c7 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 23 Jul 2019 04:02:04 +0000 Subject: [PATCH 2/5] Rename the columns linking customer and privacy policy. #233 --- src/Entity/Customer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index d1576621..10ba5cd7 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -149,21 +149,21 @@ class Customer /** * @ORM\ManyToOne(targetEntity="PrivacyPolicy", inversedBy="cust_mobile_app") - * @ORM\JoinColumn(name="mobile_policy_id", referencedColumnName="id") + * @ORM\JoinColumn(name="policy_mobile_app_id", referencedColumnName="id") * @Assert\NotBlank() */ protected $privpol_mobile_app; /** * @ORM\ManyToOne(targetEntity="PrivacyPolicy", inversedBy="cust_third_party") - * @ORM\JoinColumn(name="third_party_policy_id", referencedColumnName="id") + * @ORM\JoinColumn(name="policy_third_party_id", referencedColumnName="id") * @Assert\NotBlank() */ protected $privpol_third_party; /** * @ORM\ManyToOne(targetEntity="PrivacyPolicy", inversedBy="cust_promo") - * @ORM\JoinColumn(name="promo_policy_id", referencedColumnName="id") + * @ORM\JoinColumn(name="policy_promo_id", referencedColumnName="id") * @Assert\NotBlank() */ protected $privpol_promo; From 50a3afb21326034b32fec58d88a159b9bcf3e0ee Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 23 Jul 2019 09:57:14 +0000 Subject: [PATCH 3/5] Add privacy policy in menu and acl yaml files. Add routes for private policy functions. Add PrivatePolicyController. Add twig files for private policy. #233 --- config/acl.yaml | 15 ++ config/menu.yaml | 4 + config/routes/privacy_policy.yaml | 33 +++ src/Controller/PrivacyPolicyController.php | 272 +++++++++++++++++++++ templates/privacy-policy/form.html.twig | 142 +++++++++++ templates/privacy-policy/list.html.twig | 142 +++++++++++ 6 files changed, 608 insertions(+) create mode 100644 config/routes/privacy_policy.yaml create mode 100644 src/Controller/PrivacyPolicyController.php create mode 100644 templates/privacy-policy/form.html.twig create mode 100644 templates/privacy-policy/list.html.twig diff --git a/config/acl.yaml b/config/acl.yaml index 5695e217..e868c7ec 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -252,6 +252,7 @@ access_keys: label: Search - id: warranty.search label: Customer Battery Search + - id: ticket label: Ticket Access acls: @@ -329,3 +330,17 @@ access_keys: label: View - id: review.delete label: Delete + + - id: privacypolicy + label: Privacy Policy + acls: + - id: privacy_policy.menu + label: Menu + - id: privacy_policy.list + label: List + - id: privacy_policy.add + label: Add + - id: privacy_policy.update + label: Update + - id: privacy_policy.delete + label: Delete diff --git a/config/menu.yaml b/config/menu.yaml index d470f680..b0a00d92 100644 --- a/config/menu.yaml +++ b/config/menu.yaml @@ -143,6 +143,10 @@ main_menu: acl: warranty.search label: Customer Battery Search parent: support + - id: privacy_policy_list + acl: privacy_policy.list + label: Privacy Policy + parent: support - id: service acl: service.menu diff --git a/config/routes/privacy_policy.yaml b/config/routes/privacy_policy.yaml new file mode 100644 index 00000000..6a5708b2 --- /dev/null +++ b/config/routes/privacy_policy.yaml @@ -0,0 +1,33 @@ +privacy_policy_list: + path: /privacy_policies + controller: App\Controller\PrivacyPolicyController::index + +privacy_policy_rows: + path: /privacy_policies/rows + controller: App\Controller\PrivacyPolicyController::rows + methods: [POST] + +privacy_policy_create: + path: /privacy_policies/create + controller: App\Controller\PrivacyPolicyController::addForm + methods: [GET] + +privacy_policy_create_submit: + path: /privacy_policies/create + controller: App\Controller\PrivacyPolicyController:addSubmit + methods: [POST] + +privacy_policy_update: + path: /privacy_policies/{id} + controller: App\Controller\PrivacyPolicyController::updateForm + methods: [GET] + +privacy_policy_update_submit: + path : /privacy_policies/{id} + controller: App\Controller\PrivacyPolicyController:updateSubmit + methods: [POST] + +privacy_policy_delete: + path: /privacy_policies/{id} + controller: App\Controller\PrivacyPolicyController:destroy + methods: [DELETE] diff --git a/src/Controller/PrivacyPolicyController.php b/src/Controller/PrivacyPolicyController.php new file mode 100644 index 00000000..70b39278 --- /dev/null +++ b/src/Controller/PrivacyPolicyController.php @@ -0,0 +1,272 @@ +denyAccessUnlessGranted('privacy_policy.list', null, 'No access.'); + + return $this->render('privacy-policy/list.html.twig'); + } + + public function rows(Request $req) + { + $this->denyAccessUnlessGranted('privacy_policy.list', null, 'No access.'); + + // build query + $qb = $this->getDoctrine() + ->getRepository(PrivacyPolicy::class) + ->createQueryBuilder('q'); + + // get datatable params + $datatable = $req->request->get('datatable'); + + // count total records + $tquery = $qb->select('COUNT(q)'); + + // add fitlers to count query + $this->setQueryFilters($datatable, $tquery); + + $total = $tquery->getQuery() + ->getSingleScalarResult(); + + // get current page number + $page = $datatable['pagination']['page'] ?? 1; + + $perpage = $datatable['pagination']['perpage']; + $offset = ($page - 1) * $perpage; + + // add metadata + $meta = [ + 'page' => $page, + 'perpage' => $perpage, + 'pages' => ceil($total / $perpage), + 'total' => $total, + 'sort' => 'asc', + 'field' => 'id' + ]; + + // build query + $query = $qb->select('q'); + + // add filters to query + $this->setQueryFilters($datatable, $query); + + // check if sorting is present, otherwise use default + if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) { + $order = $datatable['sort']['sort'] ?? 'asc'; + $query->orderBy('q.' . $datatable['sort']['field'], $order); + } else { + $query->orderBy('q.id', 'asc'); + } + + // get rows for this page + $obj_rows = $query->setFirstResult($offset) + ->setMaxResults($perpage) + ->getQuery() + ->getResult(); + + // process rows + $rows = []; + foreach ($obj_rows as $orow) { + // add row data + $row['id'] = $orow->getID(); + $row['name'] = $orow->getName(); + + // add row metadata + $row['meta'] = [ + 'update_url' => '', + 'delete_url' => '' + ]; + + // add crud urls + if ($this->isGranted('privacy_policy.update')) + $row['meta']['update_url'] = $this->generateUrl('privacy_policy_update', ['id' => $row['id']]); + if ($this->isGranted('privacy_policy.delete')) + $row['meta']['delete_url'] = $this->generateUrl('privacy_policy_delete', ['id' => $row['id']]); + + $rows[] = $row; + } + + // response + return $this->json([ + 'meta' => $meta, + 'data' => $rows + ]); + } + + /** + * @Menu(selected="privacy_policy_list") + */ + public function addForm() + { + $this->denyAccessUnlessGranted('privacy_policy.add', null, 'No access.'); + + $params = []; + $params['obj'] = new PrivacyPolicy(); + $params['mode'] = 'create'; + + // response + return $this->render('privacy-policy/form.html.twig', $params); + } + + public function addSubmit(Request $req, ValidatorInterface $validator) + { + $this->denyAccessUnlessGranted('privacy_policy.add', null, 'No access.'); + + // create new object + $em = $this->getDoctrine()->getManager(); + $row = new PrivacyPolicy(); + + // set and save values + $row->setName($req->request->get('name')); + $row->setContent($req->request->get('content')); + + // validate + $errors = $validator->validate($row); + + // initialize error list + $error_array = []; + + // add errors to list + foreach ($errors as $error) { + $error_array[$error->getPropertyPath()] = $error->getMessage(); + } + + // check if any errors were found + if (!empty($error_array)) { + // return validation failure response + return $this->json([ + 'success' => false, + 'errors' => $error_array + ], 422); + } else { + // validated! save the entity + $em->persist($row); + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + } + + /** + * @Menu(selected="privacy_policy_list") + */ + public function updateForm($id) + { + $this->denyAccessUnlessGranted('privacy_policy.update', null, 'No access.'); + + $params = []; + $params['mode'] = 'update'; + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(PrivacyPolicy::class)->find($id); + + // make sure this row exists + if (empty($row)) + throw $this->createNotFoundException('The item does not exist'); + + $params['obj'] = $row; + + // response + return $this->render('privacy-policy/form.html.twig', $params); + } + + public function updateSubmit(Request $req, ValidatorInterface $validator, $id) + { + $this->denyAccessUnlessGranted('privacy_policy.update', null, 'No access.'); + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(PrivacyPolicy::class)->find($id); + + // make sure this row exists + if (empty($row)) + throw $this->createNotFoundException('The item does not exist'); + + // set and save values + $row->setName($req->request->get('name')); + + // validate + $errors = $validator->validate($row); + + // initialize error list + $error_array = []; + + // add errors to list + foreach ($errors as $error) { + $error_array[$error->getPropertyPath()] = $error->getMessage(); + } + + // check if any errors were found + if (!empty($error_array)) { + // return validation failure response + return $this->json([ + 'success' => false, + 'errors' => $error_array + ], 422); + } else { + // validated! save the entity + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + } + + /** + * @Menu(selected="privacy_policy_list") + */ + public function destroy($id) + { + $this->denyAccessUnlessGranted('privacy_policy.delete', null, 'No access.'); + + $params = []; + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(PrivacyPolicy::class)->find($id); + + if (empty($row)) + throw $this->createNotFoundException('The item does not exist'); + + // delete this row + $em->remove($row); + $em->flush(); + + // response + $response = new Response(); + $response->setStatusCode(Response::HTTP_OK); + $response->send(); + } + + protected function setQueryFilters($datatable, &$query) + { + if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) { + $query->where('q.name LIKE :filter') + ->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%'); + } + } +} diff --git a/templates/privacy-policy/form.html.twig b/templates/privacy-policy/form.html.twig new file mode 100644 index 00000000..efd2f3b3 --- /dev/null +++ b/templates/privacy-policy/form.html.twig @@ -0,0 +1,142 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

Privacy Policies

+
+
+
+ +
+ +
+
+
+
+
+
+ + + +

+ {% if mode == 'update' %} + Edit Policy + {{ obj.getID() }} + {% else %} + New Policy + {% endif %} +

+
+
+
+
+
+
+
+ + + +
+
+
+
+ + + +
+
+
+
+
+
+
+ + Back +
+
+
+
+
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/templates/privacy-policy/list.html.twig b/templates/privacy-policy/list.html.twig new file mode 100644 index 00000000..d0c40e11 --- /dev/null +++ b/templates/privacy-policy/list.html.twig @@ -0,0 +1,142 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ Privacy Policies +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} From b657ae95d511882d1b36fd9c6d37ea905a556992 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 24 Jul 2019 08:45:52 +0000 Subject: [PATCH 4/5] Add setting of privacy policy for customer when user updates info for mobile session and when user sends privacy settings for third party and promo. #233 --- src/Controller/APIController.php | 44 +++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 2a476dce..63691592 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -395,6 +395,17 @@ class APIController extends Controller // update mobile phone of customer $cust->setPhoneMobile(substr($this->session->getPhoneNumber(), 2)); + // get privacy policy for mobile + $policy = $em->createQuery('SELECT policy FROM App\Entity\PrivacyPolicy policy WHERE policy.name LIKE :policy_type') + ->setParameter('policy_type', "%" . "mobile" . "%") + ->getOneOrNullResult(); + + // set policy id + if ($policy != null) + { + $cust->setPrivacyPolicyMobile($policy); + } + $em->flush(); return $res->getReturnResponse(); @@ -1787,9 +1798,40 @@ class APIController extends Controller // set privacy settings $priv_promo = $req->request->get('priv_promo', false); - $cust->setPrivacyThirdParty($req->request->get('priv_third_party')) + $priv_third_party = $req->request->get('priv_third_party'); + $cust->setPrivacyThirdParty($priv_third_party) ->setPrivacyPromo($priv_promo); + // check if privacy settings are true + // if true, set the private policy for the customer + if ($priv_promo) + { + // find the promo policy + $policy = $em->createQuery('SELECT policy FROM App\Entity\PrivacyPolicy policy WHERE policy.name LIKE :policy_type') + ->setParameter('policy_type', "%" . "promo" . "%") + ->getOneOrNullResult(); + + // set policy id + if ($policy != null) + { + $cust->setPrivacyPolicyPromo($policy); + } + } + + if ($priv_third_party) + { + // find the third party policy + $policy = $em->createQuery('SELECT policy FROM App\Entity\PrivacyPolicy policy WHERE policy.name LIKE :policy_type') + ->setParameter('policy_type', "%" . "third party" . "%") + ->getOneOrNullResult(); + + // set policy id + if ($policy != null) + { + $cust->setPrivacyPolicyThirdParty($policy); + } + } + $em->flush(); return $res->getReturnResponse(); From 830803ac2d5794ef5f096d11b4585ded8cff8f32 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 24 Jul 2019 12:54:59 +0000 Subject: [PATCH 5/5] Create command to set the privacy policy for existing customers. #233 --- .../SetCustomerPrivacyPolicyCommand.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/Command/SetCustomerPrivacyPolicyCommand.php diff --git a/src/Command/SetCustomerPrivacyPolicyCommand.php b/src/Command/SetCustomerPrivacyPolicyCommand.php new file mode 100644 index 00000000..8e2f468f --- /dev/null +++ b/src/Command/SetCustomerPrivacyPolicyCommand.php @@ -0,0 +1,81 @@ +em = $om; + + parent::__construct(); + } + + protected function configure() + { + $this->setName('customer:setprivacypolicy') + ->setDescription('Set customer private policy.') + ->addArgument('third_party_policy_id', InputArgument::REQUIRED, 'third_party_policy_id') + ->addArgument('mobile_policy_id', InputArgument::REQUIRED, 'mobile_policy_id') + ->addArgument('promo_policy_id', InputArgument::REQUIRED, 'promo_policy_id' ) + ->setHelp('Set customer private policy. Order of ids: third party mobile promo'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $third_party_policy_id = $input->getArgument('third_party_policy_id'); + $mobile_policy_id = $input->getArgument('mobile_policy_id'); + $promo_policy_id = $input->getArgument('promo_policy_id'); + + // get third party policy + $third_party_policy = $this->em->getRepository(PrivacyPolicy::class)->findOneBy(['id' => $third_party_policy_id]); + + // get customers on third party + $third_party_customers = $this->em->getRepository(Customer::class)->findBy(['priv_third_party' => true]); + foreach ($third_party_customers as $cust) + { + $cust->setPrivacyPolicyThirdParty($third_party_policy); + } + + // get promo policy + $promo_policy = $this->em->getRepository(PrivacyPolicy::class)->findOneBy(['id' => $promo_policy_id]); + + // get customers on promo + $promo_customers = $this->em->getRepository(Customer::class)->findBy(['priv_promo' => true]); + foreach ($promo_customers as $cust) + { + $cust->setPrivacyPolicyPromo($promo_policy); + } + + $this->em->flush(); + + // get mobile policy + $mobile_policy = $this->em->getRepository(PrivacyPolicy::class)->findOneBy(['id' => $mobile_policy_id]); + + // get mobile sessions + $mobile_sessions = $this->em->getRepository(MobileSession::class)->findAll(); + foreach ($mobile_sessions as $session) + { + $cust = $session->getCustomer(); + if (!(is_null($cust))) + { + $cust->setPrivacyPolicyMobile($mobile_policy); + } + } + + $this->em->flush(); + } +}