@@ -10,44 +10,44 @@ |
||
10 | 10 | |
11 | 11 | class UserLogsController extends AbstractController |
12 | 12 | { |
13 | - /** |
|
14 | - * list all user logs |
|
15 | - * @Route("/user-logs/{page}", requirements={"page" = "\d+"}, name="ribsadmin_userlogs") |
|
16 | - * @param ParameterBagInterface $parameterBag |
|
17 | - * @param int $page |
|
18 | - * @return Response |
|
19 | - */ |
|
20 | - public function list(ParameterBagInterface $parameterBag, int $page = 1): Response |
|
21 | - { |
|
22 | - $em = $this->getDoctrine()->getManager(); |
|
23 | - $max_per_page = $parameterBag->get("ribs_admin.paginator_element_per_page"); |
|
13 | + /** |
|
14 | + * list all user logs |
|
15 | + * @Route("/user-logs/{page}", requirements={"page" = "\d+"}, name="ribsadmin_userlogs") |
|
16 | + * @param ParameterBagInterface $parameterBag |
|
17 | + * @param int $page |
|
18 | + * @return Response |
|
19 | + */ |
|
20 | + public function list(ParameterBagInterface $parameterBag, int $page = 1): Response |
|
21 | + { |
|
22 | + $em = $this->getDoctrine()->getManager(); |
|
23 | + $max_per_page = $parameterBag->get("ribs_admin.paginator_element_per_page"); |
|
24 | 24 | |
25 | - $logs = $em->getRepository(UserLogs::class)->findAllPaginated($page, $max_per_page); |
|
26 | - $pagination = array( |
|
27 | - "page" => $page, |
|
28 | - "page_number" => ceil(count($logs) / 20), |
|
29 | - "route" => "ribsadmin_userlogs", |
|
30 | - "parameters" => array() |
|
31 | - ); |
|
25 | + $logs = $em->getRepository(UserLogs::class)->findAllPaginated($page, $max_per_page); |
|
26 | + $pagination = array( |
|
27 | + "page" => $page, |
|
28 | + "page_number" => ceil(count($logs) / 20), |
|
29 | + "route" => "ribsadmin_userlogs", |
|
30 | + "parameters" => array() |
|
31 | + ); |
|
32 | 32 | |
33 | - return $this->render("@RibsAdmin/userlogs/list.html.twig", [ |
|
34 | - "logs" => $logs, |
|
35 | - "pagination" => $pagination |
|
36 | - ]); |
|
37 | - } |
|
33 | + return $this->render("@RibsAdmin/userlogs/list.html.twig", [ |
|
34 | + "logs" => $logs, |
|
35 | + "pagination" => $pagination |
|
36 | + ]); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * show detail of a user log |
|
41 | - * @Route("/user-logs/show/{guid}", name="ribsadmin_userlogs_show") |
|
42 | - * @param string $guid |
|
43 | - * @return Response |
|
44 | - */ |
|
45 | - public function show(string $guid): Response |
|
46 | - { |
|
47 | - $log = $this->getDoctrine()->getRepository(UserLogs::class)->findOneByGuid($guid); |
|
39 | + /** |
|
40 | + * show detail of a user log |
|
41 | + * @Route("/user-logs/show/{guid}", name="ribsadmin_userlogs_show") |
|
42 | + * @param string $guid |
|
43 | + * @return Response |
|
44 | + */ |
|
45 | + public function show(string $guid): Response |
|
46 | + { |
|
47 | + $log = $this->getDoctrine()->getRepository(UserLogs::class)->findOneByGuid($guid); |
|
48 | 48 | |
49 | - return $this->render("@RibsAdmin/userlogs/show.html.twig", [ |
|
50 | - "log" => $log, |
|
51 | - ]); |
|
52 | - } |
|
49 | + return $this->render("@RibsAdmin/userlogs/show.html.twig", [ |
|
50 | + "log" => $log, |
|
51 | + ]); |
|
52 | + } |
|
53 | 53 | } |
@@ -9,41 +9,41 @@ |
||
9 | 9 | |
10 | 10 | class UploaderType extends AbstractType |
11 | 11 | { |
12 | - /** |
|
13 | - * @param FormBuilderInterface $builder |
|
14 | - * @param array $options |
|
15 | - */ |
|
16 | - public function buildForm(FormBuilderInterface $builder, array $options) |
|
17 | - { |
|
18 | - $builder |
|
19 | - ->add($options["uploader_name"], FileType::class, [ |
|
20 | - "label" => false, |
|
21 | - "attr" => [ |
|
22 | - "class" => "input-autocomplete", |
|
23 | - "data-ribs-fileuploader" => "", |
|
24 | - "data-url-param" => $options["data_url_param"], |
|
25 | - "data-retrieve-url-param" => $options["data_retrieve_url_param"], |
|
26 | - "data-delete-url-param" => $options["data_delete_url_param"], |
|
27 | - "accept" => $options["accept"], |
|
28 | - "multiple" => $options["multiple"], |
|
29 | - "autocomplete" => "off", |
|
30 | - ], |
|
31 | - "mapped" => false |
|
32 | - ]); |
|
33 | - } |
|
12 | + /** |
|
13 | + * @param FormBuilderInterface $builder |
|
14 | + * @param array $options |
|
15 | + */ |
|
16 | + public function buildForm(FormBuilderInterface $builder, array $options) |
|
17 | + { |
|
18 | + $builder |
|
19 | + ->add($options["uploader_name"], FileType::class, [ |
|
20 | + "label" => false, |
|
21 | + "attr" => [ |
|
22 | + "class" => "input-autocomplete", |
|
23 | + "data-ribs-fileuploader" => "", |
|
24 | + "data-url-param" => $options["data_url_param"], |
|
25 | + "data-retrieve-url-param" => $options["data_retrieve_url_param"], |
|
26 | + "data-delete-url-param" => $options["data_delete_url_param"], |
|
27 | + "accept" => $options["accept"], |
|
28 | + "multiple" => $options["multiple"], |
|
29 | + "autocomplete" => "off", |
|
30 | + ], |
|
31 | + "mapped" => false |
|
32 | + ]); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param OptionsResolver $resolver |
|
37 | - */ |
|
38 | - public function configureOptions(OptionsResolver $resolver) |
|
39 | - { |
|
40 | - $resolver->setDefaults([ |
|
41 | - "uploader_name" => null, |
|
42 | - "data_url_param" => null, |
|
43 | - "data_retrieve_url_param" => null, |
|
44 | - "data_delete_url_param" => null, |
|
45 | - "accept" => "*", |
|
46 | - "multiple" => false, |
|
47 | - ]); |
|
48 | - } |
|
35 | + /** |
|
36 | + * @param OptionsResolver $resolver |
|
37 | + */ |
|
38 | + public function configureOptions(OptionsResolver $resolver) |
|
39 | + { |
|
40 | + $resolver->setDefaults([ |
|
41 | + "uploader_name" => null, |
|
42 | + "data_url_param" => null, |
|
43 | + "data_retrieve_url_param" => null, |
|
44 | + "data_delete_url_param" => null, |
|
45 | + "accept" => "*", |
|
46 | + "multiple" => false, |
|
47 | + ]); |
|
48 | + } |
|
49 | 49 | } |
@@ -14,125 +14,125 @@ |
||
14 | 14 | |
15 | 15 | class UploaderController extends AbstractController |
16 | 16 | { |
17 | - /** |
|
18 | - * @Route("/upload", name="ribsadmin_upload") |
|
19 | - * @param Request $request |
|
20 | - * @param ParameterBagInterface $parameter |
|
21 | - * @return JsonResponse |
|
22 | - * @throws Exception |
|
23 | - */ |
|
24 | - public function upload(Request $request, ParameterBagInterface $parameter): JsonResponse |
|
25 | - { |
|
26 | - $success = false; |
|
27 | - $new_filename = null; |
|
28 | - $file = null; |
|
29 | - $upload_dir = null; |
|
30 | - |
|
31 | - if ($request->files && $request->files->has("file")) { |
|
32 | - $upload_dir = $parameter->get("ribs_admin.upload_dir"); |
|
33 | - /** @var UploadedFile $file */ |
|
34 | - $file = $request->files->get("file"); |
|
35 | - $date = new \DateTime(); |
|
36 | - $extension = explode(".", $file->getFilename()); |
|
37 | - $new_filename = uniqid() . "-" . $date->getTimestamp() . "." . end($extension); |
|
38 | - |
|
39 | - if (!is_dir($upload_dir)) { |
|
40 | - $this->createRecursiveDirFromRoot($upload_dir); |
|
41 | - } |
|
42 | - |
|
43 | - if ($file->move($upload_dir, $new_filename)) { |
|
44 | - $success = true; |
|
45 | - } |
|
46 | - } |
|
47 | - |
|
48 | - return new JsonResponse([ |
|
49 | - "original_filename" => $file ? $file->getClientOriginalName() : null, |
|
50 | - "new_filename" => $new_filename, |
|
51 | - "file_path" => $upload_dir . "/" . $new_filename, |
|
52 | - "success" => $success |
|
53 | - ]); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @Route("/delete-uploaded-file", name="ribsadmin_delete_uploaded_file") |
|
58 | - * @param Request $request |
|
59 | - * @param ParameterBagInterface $parameter |
|
60 | - * @return JsonResponse |
|
61 | - */ |
|
62 | - public function deleteUploadedFile(Request $request, ParameterBagInterface $parameter): JsonResponse |
|
63 | - { |
|
64 | - $success = false; |
|
65 | - if ($request->get("file_path") && $request->get("file_name")) { |
|
66 | - $fs = new Filesystem(); |
|
67 | - $upload_dir = $parameter->get("ribs_admin.upload_dir"); |
|
68 | - |
|
69 | - if (is_file($request->get("file_path"))) { |
|
70 | - $fs->remove($request->get("file_path")); |
|
71 | - } elseif (is_file($upload_dir . "/" . $request->get("file_name"))) { |
|
72 | - $fs->remove($upload_dir . "/" . $request->get("file_name")); |
|
73 | - } |
|
74 | - $success = true; |
|
75 | - } |
|
76 | - |
|
77 | - return new JsonResponse([ |
|
78 | - "success" => $success |
|
79 | - ]); |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * @Route("/retrieve-uploaded-files", name="ribsadmin_retrieve_uploaded_file") |
|
84 | - * @param Request $request |
|
85 | - * @param ParameterBagInterface $parameter |
|
86 | - * @return JsonResponse |
|
87 | - */ |
|
88 | - public function retrieveUploadedFile(Request $request, ParameterBagInterface $parameter): JsonResponse |
|
89 | - { |
|
90 | - $success = true; |
|
91 | - $fs = new Filesystem(); |
|
92 | - $finder = new Finder(); |
|
93 | - $finder->files()->in($parameter->get("ribs_admin.upload_dir")); |
|
94 | - $files = []; |
|
95 | - $index = 0; |
|
96 | - |
|
97 | - foreach ($finder as $file) { |
|
98 | - $files[] = [ |
|
99 | - "file_path" => $parameter->get("ribs_admin.base_upload_url") . $file->getFilename(), |
|
100 | - "filename" => $file->getFilename(), |
|
101 | - "index" => $index |
|
102 | - ]; |
|
103 | - |
|
104 | - $index++; |
|
105 | - } |
|
106 | - |
|
107 | - return new JsonResponse([ |
|
108 | - "success" => $success, |
|
109 | - "files" => $files |
|
110 | - ]); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * method that create a tree of folders on each slash |
|
115 | - * @param $path |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - private function createRecursiveDirFromRoot($path) |
|
119 | - { |
|
120 | - $fs = new Filesystem(); |
|
121 | - $new_path = $path; |
|
122 | - $folders = explode("/", $path); |
|
123 | - |
|
124 | - foreach ($folders as $index => $folder) { |
|
125 | - $new_path .= $folder; |
|
126 | - |
|
127 | - if (!$fs->exists($new_path)) { |
|
128 | - $fs->mkdir($new_path); |
|
129 | - } |
|
130 | - |
|
131 | - if ($index + 1 < count($folders)) { |
|
132 | - $new_path .= "/"; |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - return $new_path; |
|
137 | - } |
|
17 | + /** |
|
18 | + * @Route("/upload", name="ribsadmin_upload") |
|
19 | + * @param Request $request |
|
20 | + * @param ParameterBagInterface $parameter |
|
21 | + * @return JsonResponse |
|
22 | + * @throws Exception |
|
23 | + */ |
|
24 | + public function upload(Request $request, ParameterBagInterface $parameter): JsonResponse |
|
25 | + { |
|
26 | + $success = false; |
|
27 | + $new_filename = null; |
|
28 | + $file = null; |
|
29 | + $upload_dir = null; |
|
30 | + |
|
31 | + if ($request->files && $request->files->has("file")) { |
|
32 | + $upload_dir = $parameter->get("ribs_admin.upload_dir"); |
|
33 | + /** @var UploadedFile $file */ |
|
34 | + $file = $request->files->get("file"); |
|
35 | + $date = new \DateTime(); |
|
36 | + $extension = explode(".", $file->getFilename()); |
|
37 | + $new_filename = uniqid() . "-" . $date->getTimestamp() . "." . end($extension); |
|
38 | + |
|
39 | + if (!is_dir($upload_dir)) { |
|
40 | + $this->createRecursiveDirFromRoot($upload_dir); |
|
41 | + } |
|
42 | + |
|
43 | + if ($file->move($upload_dir, $new_filename)) { |
|
44 | + $success = true; |
|
45 | + } |
|
46 | + } |
|
47 | + |
|
48 | + return new JsonResponse([ |
|
49 | + "original_filename" => $file ? $file->getClientOriginalName() : null, |
|
50 | + "new_filename" => $new_filename, |
|
51 | + "file_path" => $upload_dir . "/" . $new_filename, |
|
52 | + "success" => $success |
|
53 | + ]); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @Route("/delete-uploaded-file", name="ribsadmin_delete_uploaded_file") |
|
58 | + * @param Request $request |
|
59 | + * @param ParameterBagInterface $parameter |
|
60 | + * @return JsonResponse |
|
61 | + */ |
|
62 | + public function deleteUploadedFile(Request $request, ParameterBagInterface $parameter): JsonResponse |
|
63 | + { |
|
64 | + $success = false; |
|
65 | + if ($request->get("file_path") && $request->get("file_name")) { |
|
66 | + $fs = new Filesystem(); |
|
67 | + $upload_dir = $parameter->get("ribs_admin.upload_dir"); |
|
68 | + |
|
69 | + if (is_file($request->get("file_path"))) { |
|
70 | + $fs->remove($request->get("file_path")); |
|
71 | + } elseif (is_file($upload_dir . "/" . $request->get("file_name"))) { |
|
72 | + $fs->remove($upload_dir . "/" . $request->get("file_name")); |
|
73 | + } |
|
74 | + $success = true; |
|
75 | + } |
|
76 | + |
|
77 | + return new JsonResponse([ |
|
78 | + "success" => $success |
|
79 | + ]); |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * @Route("/retrieve-uploaded-files", name="ribsadmin_retrieve_uploaded_file") |
|
84 | + * @param Request $request |
|
85 | + * @param ParameterBagInterface $parameter |
|
86 | + * @return JsonResponse |
|
87 | + */ |
|
88 | + public function retrieveUploadedFile(Request $request, ParameterBagInterface $parameter): JsonResponse |
|
89 | + { |
|
90 | + $success = true; |
|
91 | + $fs = new Filesystem(); |
|
92 | + $finder = new Finder(); |
|
93 | + $finder->files()->in($parameter->get("ribs_admin.upload_dir")); |
|
94 | + $files = []; |
|
95 | + $index = 0; |
|
96 | + |
|
97 | + foreach ($finder as $file) { |
|
98 | + $files[] = [ |
|
99 | + "file_path" => $parameter->get("ribs_admin.base_upload_url") . $file->getFilename(), |
|
100 | + "filename" => $file->getFilename(), |
|
101 | + "index" => $index |
|
102 | + ]; |
|
103 | + |
|
104 | + $index++; |
|
105 | + } |
|
106 | + |
|
107 | + return new JsonResponse([ |
|
108 | + "success" => $success, |
|
109 | + "files" => $files |
|
110 | + ]); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * method that create a tree of folders on each slash |
|
115 | + * @param $path |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + private function createRecursiveDirFromRoot($path) |
|
119 | + { |
|
120 | + $fs = new Filesystem(); |
|
121 | + $new_path = $path; |
|
122 | + $folders = explode("/", $path); |
|
123 | + |
|
124 | + foreach ($folders as $index => $folder) { |
|
125 | + $new_path .= $folder; |
|
126 | + |
|
127 | + if (!$fs->exists($new_path)) { |
|
128 | + $fs->mkdir($new_path); |
|
129 | + } |
|
130 | + |
|
131 | + if ($index + 1 < count($folders)) { |
|
132 | + $new_path .= "/"; |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + return $new_path; |
|
137 | + } |
|
138 | 138 | } |
@@ -13,120 +13,120 @@ |
||
13 | 13 | |
14 | 14 | class AccessRightsController extends AbstractController |
15 | 15 | { |
16 | - /** |
|
17 | - * @Route("/access-rights-management/", name="ribsadmin_access_rights") |
|
18 | - * @return Response |
|
19 | - */ |
|
20 | - public function list(): Response |
|
21 | - { |
|
22 | - $em = $this->getDoctrine()->getManager(); |
|
23 | - $acces_right = $em->getRepository("RibsAdminBundle:AccessRight")->findAll(); |
|
24 | - |
|
25 | - return $this->render("@RibsAdmin/access-rights/list.html.twig", [ |
|
26 | - "access_right" => $acces_right |
|
27 | - ]); |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * @Route("/access-rights-management/create/", name="ribsadmin_access_rights_create") |
|
32 | - * @Route("/access-rights-management/show/{guid}", name="ribsadmin_access_rights_show") |
|
33 | - * @Route("/access-rights-management/edit/{guid}", name="ribsadmin_access_rights_edit") |
|
34 | - * @param Request $request |
|
35 | - * @param Globals $globals |
|
36 | - * @param ModuleService $module |
|
37 | - * @param string|null $guid |
|
38 | - * @return Response |
|
39 | - */ |
|
40 | - public function edit(Request $request, Globals $globals, ModuleService $module, string $guid = null): Response |
|
41 | - { |
|
42 | - $em = $this->getDoctrine()->getManager(); |
|
43 | - $list_rights_user = []; |
|
44 | - $disabled_form = strpos($request->get("_route"), "_show") ? true : false; |
|
45 | - |
|
46 | - if ($guid === null) { |
|
47 | - $access_right = new AccessRight(); |
|
48 | - } else { |
|
49 | - $access_right = $em->getRepository("RibsAdminBundle:AccessRight")->findOneBy(["guid" => $guid]); |
|
50 | - $list_rights_user = explode(",", $access_right->getAccessRights()); |
|
51 | - } |
|
52 | - |
|
53 | - $admins = $em->getRepository("RibsAdminBundle:User")->findBy(["admin" => true, "archived" => false]); |
|
54 | - |
|
55 | - $form = $this->createForm("PiouPiou\RibsAdminBundle\Form\AccessRight", $access_right, ["disabled" => $disabled_form]); |
|
56 | - $form->handleRequest($request); |
|
57 | - |
|
58 | - if ($form->isSubmitted() && $form->isValid()) { |
|
59 | - return $this->handleEditForm($request, $access_right); |
|
60 | - } |
|
61 | - |
|
62 | - return $this->render("@RibsAdmin/access-rights/edit.html.twig", [ |
|
63 | - "access_right" => $access_right, |
|
64 | - "form" => $form->createView(), |
|
65 | - "form_errors" => $form->getErrors(), |
|
66 | - "list_rights_user" => $list_rights_user, |
|
67 | - "admins" => $admins, |
|
68 | - "ribs_admin_rights" => json_decode(file_get_contents($globals->getBaseBundlePath() . "/Resources/json/ribsadmin_rights.json")), |
|
69 | - "modules" => $module->getAllInfosModules(), |
|
70 | - "disabled_form" => $disabled_form |
|
71 | - ]); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @Route("/access-rights-management/delete/{guid}", name="ribsadmin_access_rights_delete") |
|
76 | - * @param string $guid |
|
77 | - * @return RedirectResponse function that delete an access right list |
|
78 | - */ |
|
79 | - public function delete(string $guid): RedirectResponse |
|
80 | - { |
|
81 | - $em = $this->getDoctrine()->getManager(); |
|
82 | - $list = $em->getRepository("RibsAdminBundle:AccessRight")->findOneBy(["guid" => $guid]); |
|
83 | - |
|
84 | - if ($list) { |
|
85 | - foreach ($list->getUsers() as $user) { |
|
86 | - $user->setAccessRightList(null); |
|
87 | - } |
|
88 | - |
|
89 | - $em->remove($list); |
|
90 | - $em->flush(); |
|
91 | - |
|
92 | - $this->addFlash("success-flash", "The right list was deleted"); |
|
93 | - } else { |
|
94 | - $this->addFlash("error-flash", "The right list wasn't found"); |
|
95 | - } |
|
96 | - |
|
97 | - return $this->redirectToRoute("ribsadmin_access_rights"); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * @param Request $request |
|
102 | - * @param AccessRight $access_right |
|
103 | - * @return RedirectResponse function that handle the form request |
|
104 | - */ |
|
105 | - private function handleEditForm(Request $request, AccessRight $access_right): RedirectResponse |
|
106 | - { |
|
107 | - $em = $this->getDoctrine()->getManager(); |
|
108 | - |
|
109 | - if ($request->get("right") === null) { |
|
110 | - $rights = ""; |
|
111 | - } else { |
|
112 | - $rights = implode(",", $request->get("right")); |
|
113 | - } |
|
114 | - |
|
115 | - $access_right->setAccessRights($rights); |
|
116 | - $em->persist($access_right); |
|
117 | - $em->flush(); |
|
118 | - |
|
119 | - $em->getRepository("RibsAdminBundle:AccessRight")->deleteAllUsersList($access_right); |
|
120 | - $admins = $request->get("admins"); |
|
121 | - |
|
122 | - if ($admins !== null) { |
|
123 | - foreach ($admins as $admin) { |
|
124 | - $em->getRepository("RibsAdminBundle:AccessRight")->setAccessRightListUser($access_right->getId(), $admin); |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - $this->addFlash("success-flash", "The right list was correctly edited"); |
|
129 | - |
|
130 | - return $this->redirectToRoute("ribsadmin_access_rights"); |
|
131 | - } |
|
16 | + /** |
|
17 | + * @Route("/access-rights-management/", name="ribsadmin_access_rights") |
|
18 | + * @return Response |
|
19 | + */ |
|
20 | + public function list(): Response |
|
21 | + { |
|
22 | + $em = $this->getDoctrine()->getManager(); |
|
23 | + $acces_right = $em->getRepository("RibsAdminBundle:AccessRight")->findAll(); |
|
24 | + |
|
25 | + return $this->render("@RibsAdmin/access-rights/list.html.twig", [ |
|
26 | + "access_right" => $acces_right |
|
27 | + ]); |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * @Route("/access-rights-management/create/", name="ribsadmin_access_rights_create") |
|
32 | + * @Route("/access-rights-management/show/{guid}", name="ribsadmin_access_rights_show") |
|
33 | + * @Route("/access-rights-management/edit/{guid}", name="ribsadmin_access_rights_edit") |
|
34 | + * @param Request $request |
|
35 | + * @param Globals $globals |
|
36 | + * @param ModuleService $module |
|
37 | + * @param string|null $guid |
|
38 | + * @return Response |
|
39 | + */ |
|
40 | + public function edit(Request $request, Globals $globals, ModuleService $module, string $guid = null): Response |
|
41 | + { |
|
42 | + $em = $this->getDoctrine()->getManager(); |
|
43 | + $list_rights_user = []; |
|
44 | + $disabled_form = strpos($request->get("_route"), "_show") ? true : false; |
|
45 | + |
|
46 | + if ($guid === null) { |
|
47 | + $access_right = new AccessRight(); |
|
48 | + } else { |
|
49 | + $access_right = $em->getRepository("RibsAdminBundle:AccessRight")->findOneBy(["guid" => $guid]); |
|
50 | + $list_rights_user = explode(",", $access_right->getAccessRights()); |
|
51 | + } |
|
52 | + |
|
53 | + $admins = $em->getRepository("RibsAdminBundle:User")->findBy(["admin" => true, "archived" => false]); |
|
54 | + |
|
55 | + $form = $this->createForm("PiouPiou\RibsAdminBundle\Form\AccessRight", $access_right, ["disabled" => $disabled_form]); |
|
56 | + $form->handleRequest($request); |
|
57 | + |
|
58 | + if ($form->isSubmitted() && $form->isValid()) { |
|
59 | + return $this->handleEditForm($request, $access_right); |
|
60 | + } |
|
61 | + |
|
62 | + return $this->render("@RibsAdmin/access-rights/edit.html.twig", [ |
|
63 | + "access_right" => $access_right, |
|
64 | + "form" => $form->createView(), |
|
65 | + "form_errors" => $form->getErrors(), |
|
66 | + "list_rights_user" => $list_rights_user, |
|
67 | + "admins" => $admins, |
|
68 | + "ribs_admin_rights" => json_decode(file_get_contents($globals->getBaseBundlePath() . "/Resources/json/ribsadmin_rights.json")), |
|
69 | + "modules" => $module->getAllInfosModules(), |
|
70 | + "disabled_form" => $disabled_form |
|
71 | + ]); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @Route("/access-rights-management/delete/{guid}", name="ribsadmin_access_rights_delete") |
|
76 | + * @param string $guid |
|
77 | + * @return RedirectResponse function that delete an access right list |
|
78 | + */ |
|
79 | + public function delete(string $guid): RedirectResponse |
|
80 | + { |
|
81 | + $em = $this->getDoctrine()->getManager(); |
|
82 | + $list = $em->getRepository("RibsAdminBundle:AccessRight")->findOneBy(["guid" => $guid]); |
|
83 | + |
|
84 | + if ($list) { |
|
85 | + foreach ($list->getUsers() as $user) { |
|
86 | + $user->setAccessRightList(null); |
|
87 | + } |
|
88 | + |
|
89 | + $em->remove($list); |
|
90 | + $em->flush(); |
|
91 | + |
|
92 | + $this->addFlash("success-flash", "The right list was deleted"); |
|
93 | + } else { |
|
94 | + $this->addFlash("error-flash", "The right list wasn't found"); |
|
95 | + } |
|
96 | + |
|
97 | + return $this->redirectToRoute("ribsadmin_access_rights"); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * @param Request $request |
|
102 | + * @param AccessRight $access_right |
|
103 | + * @return RedirectResponse function that handle the form request |
|
104 | + */ |
|
105 | + private function handleEditForm(Request $request, AccessRight $access_right): RedirectResponse |
|
106 | + { |
|
107 | + $em = $this->getDoctrine()->getManager(); |
|
108 | + |
|
109 | + if ($request->get("right") === null) { |
|
110 | + $rights = ""; |
|
111 | + } else { |
|
112 | + $rights = implode(",", $request->get("right")); |
|
113 | + } |
|
114 | + |
|
115 | + $access_right->setAccessRights($rights); |
|
116 | + $em->persist($access_right); |
|
117 | + $em->flush(); |
|
118 | + |
|
119 | + $em->getRepository("RibsAdminBundle:AccessRight")->deleteAllUsersList($access_right); |
|
120 | + $admins = $request->get("admins"); |
|
121 | + |
|
122 | + if ($admins !== null) { |
|
123 | + foreach ($admins as $admin) { |
|
124 | + $em->getRepository("RibsAdminBundle:AccessRight")->setAccessRightListUser($access_right->getId(), $admin); |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + $this->addFlash("success-flash", "The right list was correctly edited"); |
|
129 | + |
|
130 | + return $this->redirectToRoute("ribsadmin_access_rights"); |
|
131 | + } |
|
132 | 132 | } |
@@ -12,129 +12,129 @@ |
||
12 | 12 | |
13 | 13 | class AccountsController extends AbstractController |
14 | 14 | { |
15 | - /** |
|
16 | - * @Route("/accounts/", name="ribsadmin_accounts") |
|
17 | - * @return Response |
|
18 | - */ |
|
19 | - public function list(): Response |
|
20 | - { |
|
21 | - $em = $this->getDoctrine()->getManager(); |
|
22 | - $current_account = $this->getUser()->getUser(); |
|
23 | - |
|
24 | - $users = $em->getRepository("RibsAdminBundle:Account")->findAllUserArchived($current_account); |
|
25 | - $users_archived = $em->getRepository("RibsAdminBundle:Account")->findAllUserArchived($current_account, true); |
|
26 | - |
|
27 | - return $this->render('@RibsAdmin/accounts/list.html.twig', [ |
|
28 | - "users" => $users, |
|
29 | - "users_archived" => $users_archived |
|
30 | - ]); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @Route("/accounts/create/", name="ribsadmin_accounts_create") |
|
35 | - * @Route("/accounts/show/{guid}", name="ribsadmin_accounts_show") |
|
36 | - * @Route("/accounts/edit/{guid}", name="ribsadmin_accounts_edit") |
|
37 | - * @param Request $request |
|
38 | - * @param string|null $guid |
|
39 | - * @return Response |
|
40 | - */ |
|
41 | - public function edit(Request $request, string $guid = null): Response |
|
42 | - { |
|
43 | - $em = $this->getDoctrine()->getManager(); |
|
44 | - $disabled_form = strpos($request->get("_route"), "_show") ? true : false; |
|
45 | - |
|
46 | - if ($guid === null) { |
|
47 | - $account = new Account(); |
|
48 | - $old_password = null; |
|
49 | - $user = null; |
|
50 | - } else { |
|
51 | - $user = $em->getRepository(User::class)->findOneBy(["guid" => $guid]); |
|
52 | - $account = $em->getRepository(Account::class)->findOneBy(["user" => $user->getId()]); |
|
53 | - $old_password = $account->getPassword(); |
|
54 | - } |
|
55 | - |
|
56 | - $form = $this->createForm("PiouPiou\RibsAdminBundle\Form\Account", $account, ["disabled" => $disabled_form]); |
|
57 | - |
|
58 | - $form->handleRequest($request); |
|
59 | - |
|
60 | - if ($form->isSubmitted() && $form->isValid()) { |
|
61 | - /** |
|
62 | - * @var Account |
|
63 | - */ |
|
64 | - $data = $form->getData(); |
|
65 | - |
|
66 | - $account_exist = $em->getRepository(Account::class)->findOneBy(["username" => $data->getUsername()]); |
|
67 | - |
|
68 | - if ($account_exist && $account_exist === $account) { |
|
69 | - $account_exist = null; |
|
70 | - } |
|
71 | - |
|
72 | - if (!$account_exist) { |
|
73 | - if ($guid === null) { |
|
74 | - $temp_password = $this->get("security.password_encoder")->encodePassword($data, $form->get("password")->getData()); |
|
75 | - $data->setPassword($temp_password); |
|
76 | - } else if ($form->get("password")->getData()) { |
|
77 | - $temp_password = $this->get("security.password_encoder")->encodePassword($data, $form->get("password")->getData()); |
|
78 | - $data->setPassword($temp_password); |
|
79 | - } else { |
|
80 | - $data->setPassword($old_password); |
|
81 | - } |
|
82 | - |
|
83 | - $em->persist($data); |
|
84 | - $em->flush(); |
|
85 | - |
|
86 | - $username = $data->getUser()->getFirstName() . " " . $data->getUser()->getLastName(); |
|
87 | - |
|
88 | - if ($guid === null) { |
|
89 | - $this->addFlash("success-flash", "the account of " . $username . " was created"); |
|
90 | - } else { |
|
91 | - $this->addFlash("success-flash", "the account of " . $username . " was edited"); |
|
92 | - } |
|
93 | - |
|
94 | - return $this->redirectToRoute("ribsadmin_accounts"); |
|
95 | - } else { |
|
96 | - $this->addFlash("error-flash", "An account with username " . $data->getUsername() . " already exist"); |
|
97 | - return $this->redirectToRoute($request->get("_route"), ["guid" => $guid]); |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - return $this->render("@RibsAdmin/accounts/edit.html.twig", [ |
|
102 | - "form" => $form->createView(), |
|
103 | - "form_errors" => $form->getErrors(), |
|
104 | - "user" => $user, |
|
105 | - "disabled_form" => $disabled_form |
|
106 | - ]); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * method to disable or enable a user |
|
111 | - * @Route("/accounts/archive/{guid}/{activate}", name="ribsadmin_accounts_archive") |
|
112 | - * @param string $guid |
|
113 | - * @param bool $activate |
|
114 | - * @return RedirectResponse |
|
115 | - */ |
|
116 | - public function archive(string $guid, bool $activate = false): RedirectResponse |
|
117 | - { |
|
118 | - $em = $this->getDoctrine()->getManager(); |
|
119 | - |
|
120 | - $user = $em->getRepository("RibsAdminBundle:User")->findOneBy(["guid" => $guid]); |
|
121 | - |
|
122 | - if ($user) { |
|
123 | - if ($activate === true) { |
|
124 | - $user->setArchived(false); |
|
125 | - $word = "activated"; |
|
126 | - } else { |
|
127 | - $user->setArchived(true); |
|
128 | - $word = "disabled"; |
|
129 | - } |
|
130 | - |
|
131 | - $em->persist($user); |
|
132 | - $em->flush(); |
|
133 | - |
|
134 | - $this->addFlash("success-flash", "The user " . $user->getFirstname() . " " . $user->getLastname() . |
|
135 | - " was " . $word . " sucessfuly"); |
|
136 | - } |
|
137 | - |
|
138 | - return $this->redirectToRoute("ribsadmin_accounts"); |
|
139 | - } |
|
15 | + /** |
|
16 | + * @Route("/accounts/", name="ribsadmin_accounts") |
|
17 | + * @return Response |
|
18 | + */ |
|
19 | + public function list(): Response |
|
20 | + { |
|
21 | + $em = $this->getDoctrine()->getManager(); |
|
22 | + $current_account = $this->getUser()->getUser(); |
|
23 | + |
|
24 | + $users = $em->getRepository("RibsAdminBundle:Account")->findAllUserArchived($current_account); |
|
25 | + $users_archived = $em->getRepository("RibsAdminBundle:Account")->findAllUserArchived($current_account, true); |
|
26 | + |
|
27 | + return $this->render('@RibsAdmin/accounts/list.html.twig', [ |
|
28 | + "users" => $users, |
|
29 | + "users_archived" => $users_archived |
|
30 | + ]); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @Route("/accounts/create/", name="ribsadmin_accounts_create") |
|
35 | + * @Route("/accounts/show/{guid}", name="ribsadmin_accounts_show") |
|
36 | + * @Route("/accounts/edit/{guid}", name="ribsadmin_accounts_edit") |
|
37 | + * @param Request $request |
|
38 | + * @param string|null $guid |
|
39 | + * @return Response |
|
40 | + */ |
|
41 | + public function edit(Request $request, string $guid = null): Response |
|
42 | + { |
|
43 | + $em = $this->getDoctrine()->getManager(); |
|
44 | + $disabled_form = strpos($request->get("_route"), "_show") ? true : false; |
|
45 | + |
|
46 | + if ($guid === null) { |
|
47 | + $account = new Account(); |
|
48 | + $old_password = null; |
|
49 | + $user = null; |
|
50 | + } else { |
|
51 | + $user = $em->getRepository(User::class)->findOneBy(["guid" => $guid]); |
|
52 | + $account = $em->getRepository(Account::class)->findOneBy(["user" => $user->getId()]); |
|
53 | + $old_password = $account->getPassword(); |
|
54 | + } |
|
55 | + |
|
56 | + $form = $this->createForm("PiouPiou\RibsAdminBundle\Form\Account", $account, ["disabled" => $disabled_form]); |
|
57 | + |
|
58 | + $form->handleRequest($request); |
|
59 | + |
|
60 | + if ($form->isSubmitted() && $form->isValid()) { |
|
61 | + /** |
|
62 | + * @var Account |
|
63 | + */ |
|
64 | + $data = $form->getData(); |
|
65 | + |
|
66 | + $account_exist = $em->getRepository(Account::class)->findOneBy(["username" => $data->getUsername()]); |
|
67 | + |
|
68 | + if ($account_exist && $account_exist === $account) { |
|
69 | + $account_exist = null; |
|
70 | + } |
|
71 | + |
|
72 | + if (!$account_exist) { |
|
73 | + if ($guid === null) { |
|
74 | + $temp_password = $this->get("security.password_encoder")->encodePassword($data, $form->get("password")->getData()); |
|
75 | + $data->setPassword($temp_password); |
|
76 | + } else if ($form->get("password")->getData()) { |
|
77 | + $temp_password = $this->get("security.password_encoder")->encodePassword($data, $form->get("password")->getData()); |
|
78 | + $data->setPassword($temp_password); |
|
79 | + } else { |
|
80 | + $data->setPassword($old_password); |
|
81 | + } |
|
82 | + |
|
83 | + $em->persist($data); |
|
84 | + $em->flush(); |
|
85 | + |
|
86 | + $username = $data->getUser()->getFirstName() . " " . $data->getUser()->getLastName(); |
|
87 | + |
|
88 | + if ($guid === null) { |
|
89 | + $this->addFlash("success-flash", "the account of " . $username . " was created"); |
|
90 | + } else { |
|
91 | + $this->addFlash("success-flash", "the account of " . $username . " was edited"); |
|
92 | + } |
|
93 | + |
|
94 | + return $this->redirectToRoute("ribsadmin_accounts"); |
|
95 | + } else { |
|
96 | + $this->addFlash("error-flash", "An account with username " . $data->getUsername() . " already exist"); |
|
97 | + return $this->redirectToRoute($request->get("_route"), ["guid" => $guid]); |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + return $this->render("@RibsAdmin/accounts/edit.html.twig", [ |
|
102 | + "form" => $form->createView(), |
|
103 | + "form_errors" => $form->getErrors(), |
|
104 | + "user" => $user, |
|
105 | + "disabled_form" => $disabled_form |
|
106 | + ]); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * method to disable or enable a user |
|
111 | + * @Route("/accounts/archive/{guid}/{activate}", name="ribsadmin_accounts_archive") |
|
112 | + * @param string $guid |
|
113 | + * @param bool $activate |
|
114 | + * @return RedirectResponse |
|
115 | + */ |
|
116 | + public function archive(string $guid, bool $activate = false): RedirectResponse |
|
117 | + { |
|
118 | + $em = $this->getDoctrine()->getManager(); |
|
119 | + |
|
120 | + $user = $em->getRepository("RibsAdminBundle:User")->findOneBy(["guid" => $guid]); |
|
121 | + |
|
122 | + if ($user) { |
|
123 | + if ($activate === true) { |
|
124 | + $user->setArchived(false); |
|
125 | + $word = "activated"; |
|
126 | + } else { |
|
127 | + $user->setArchived(true); |
|
128 | + $word = "disabled"; |
|
129 | + } |
|
130 | + |
|
131 | + $em->persist($user); |
|
132 | + $em->flush(); |
|
133 | + |
|
134 | + $this->addFlash("success-flash", "The user " . $user->getFirstname() . " " . $user->getLastname() . |
|
135 | + " was " . $word . " sucessfuly"); |
|
136 | + } |
|
137 | + |
|
138 | + return $this->redirectToRoute("ribsadmin_accounts"); |
|
139 | + } |
|
140 | 140 | } |
@@ -53,7 +53,7 @@ |
||
53 | 53 | $old_password = $account->getPassword(); |
54 | 54 | } |
55 | 55 | |
56 | - $form = $this->createForm("PiouPiou\RibsAdminBundle\Form\Account", $account, ["disabled" => $disabled_form]); |
|
56 | + $form = $this->createForm("PiouPiou\RibsAdminBundle\Form\Account", $account, ["disabled" => $disabled_form]); |
|
57 | 57 | |
58 | 58 | $form->handleRequest($request); |
59 | 59 |