commit c28c2bf119ad82193812f3a3381ddb739610fd4f Author: Marc Ducobu Date: Fri Apr 6 17:09:51 2018 +0200 First commit diff --git a/ChillDocStoreBundle.php b/ChillDocStoreBundle.php new file mode 100644 index 000000000..60649a163 --- /dev/null +++ b/ChillDocStoreBundle.php @@ -0,0 +1,9 @@ +getDoctrine()->getManager(); + $categories = $em->getRepository("ChillDocStoreBundle:DocumentCategory")->findAll(); + + return $this->render( + 'ChillDocStoreBundle:DocumentCategory:index.html.twig', + ['document_categories' => $categories]); + } + + /** + * @Route("/new", name="document_category_new", methods="GET|POST") + */ + public function new(Request $request): Response + { + $em = $this->getDoctrine()->getManager(); + $documentCategory = new DocumentCategory(); + $documentCategory + ->setBundleId('Chill\DocStoreBundle\ChillDocStoreBundle'); + $documentCategory + ->setIdInsideBundle( + $em->getRepository("ChillDocStoreBundle:DocumentCategory") + ->nextIdInsideBundle()); + $documentCategory + ->setDocumentClass(PersonDocument::class); + + $form = $this->createForm(DocumentCategoryType::class, $documentCategory); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($documentCategory); + $em->flush(); + + return $this->redirectToRoute('document_category_index'); + } else { + $documentCategory->setBundleId( + 'Chill\DocStoreBundle\ChillDocStoreBundle'); + } + + return $this->render('ChillDocStoreBundle:DocumentCategory:new.html.twig', [ + 'document_category' => $documentCategory, + 'form' => $form->createView(), + ]); + } + + /** + * @Route("/{bundleId}/{idInsideBundle}", name="document_category_show", methods="GET") + */ + public function show($bundleId, $idInsideBundle): Response + { + $em = $this->getDoctrine()->getManager(); + $documentCategory = $em + ->getRepository("ChillDocStoreBundle:DocumentCategory") + ->findOneBy( + ['bundleId' => $bundleId, 'idInsideBundle' => $idInsideBundle]); + + return $this->render( + 'ChillDocStoreBundle:DocumentCategory:show.html.twig', + ['document_category' => $documentCategory]); + } + + /** + * @Route("/{bundleId}/{idInsideBundle}/edit", name="document_category_edit", methods="GET|POST") + */ + public function edit(Request $request, $bundleId, $idInsideBundle): Response + { + $em = $this->getDoctrine()->getManager(); + $documentCategory = $em + ->getRepository("ChillDocStoreBundle:DocumentCategory") + ->findOneBy( + ['bundleId' => $bundleId, 'idInsideBundle' => $idInsideBundle]); + + $form = $this->createForm(DocumentCategoryType::class, $documentCategory); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->getDoctrine()->getManager()->flush(); + + return $this->redirectToRoute('document_category_edit', [ + 'bundleId' => $documentCategory->getBundleId(), + 'idInsideBundle' => $documentCategory->getIdInsideBundle(),]); + } + + return $this->render('ChillDocStoreBundle:DocumentCategory:edit.html.twig', [ + 'document_category' => $documentCategory, + 'form' => $form->createView(), + ]); + } + + /** + * @Route("/{bundleId}/{idInsideBundle}", name="document_category_delete", methods="DELETE") + */ + public function delete(Request $request, $bundleId, $idInsideBundle): Response + { + $em = $this->getDoctrine()->getManager(); + $documentCategory = $em + ->getRepository("ChillDocStoreBundle:DocumentCategory") + ->findOneBy( + ['bundleId' => $bundleId, 'idInsideBundle' => $idInsideBundle]); + + if ($this->isCsrfTokenValid('delete'.$bundleId.$idInsideBundle, $request->request->get('_token'))) { + $em->remove($documentCategory); + $em->flush(); + } + + return $this->redirectToRoute('document_category_index'); + } +} diff --git a/Controller/DocumentPersonController.php b/Controller/DocumentPersonController.php new file mode 100644 index 000000000..5a5464f2c --- /dev/null +++ b/Controller/DocumentPersonController.php @@ -0,0 +1,163 @@ +getDoctrine()->getManager(); + + if ($person === NULL) { + throw $this->createNotFoundException('Person not found'); + } + + $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); + + $reachableScopes = $this->get('chill.main.security.authorization.helper') + ->getReachableScopes( + $this->getUser(), new Role('CHILL_PERSON_DOCUMENT_SEE'), + $person->getCenter()); + + $documents = $em + ->getRepository("ChillDocStoreBundle:PersonDocument") + ->findBy( + array('person' => $person, 'scope' => $reachableScopes), + array('date' => 'DESC') + ); + + return $this->render( + 'ChillDocStoreBundle:PersonDocument:index.html.twig', + [ + 'documents' => $documents, + 'person' => $person + ]); + } + + /** + * @Route("/new", name="person_document_new", methods="GET|POST") + */ + public function new(Request $request, Person $person): Response + { + if ($person === NULL) { + throw $this->createNotFoundException('person not found'); + } + + $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); + + $user = $this->get('security.context')->getToken()->getUser(); + $document = new PersonDocument(); + $document->setUser($user); + $document->setPerson($person); + $document->setDate(new \DateTime('Now')); + + $form = $this->createForm(PersonDocumentType::class, $document, array( + 'center' => $document->getCenter(), + 'role' => new Role('CHILL_PERSON_DOCUMENT_CREATE') + )); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->denyAccessUnlessGranted( + 'CHILL_PERSON_DOCUMENT_CREATE', $document, + 'creation of this activity not allowed'); + + $em = $this->getDoctrine()->getManager(); + $em->persist($document); + $em->flush(); + + return $this->redirectToRoute('person_document_index', ['person' => $person->getId()]); + } + + return $this->render('ChillDocStoreBundle:PersonDocument:new.html.twig', [ + 'document' => $document, + 'form' => $form->createView(), + 'person' => $person, + ]); + } + + /** + * @Route("/{id}", name="person_document_show", methods="GET") + */ + public function show(Person $person, PersonDocument $document): Response + { + $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); + $this->denyAccessUnlessGranted('CHILL_PERSON_DOCUMENT_SEE', $document); + + return $this->render( + 'ChillDocStoreBundle:PersonDocument:show.html.twig', + ['document' => $document, 'person' => $person]); + } + + /** + * @Route("/{id}/edit", name="person_document_edit", methods="GET|POST") + */ + public function edit(Request $request, Person $person, PersonDocument $document): Response + { + $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); + $this->denyAccessUnlessGranted('CHILL_PERSON_DOCUMENT_UPDATE', $document); + + $user = $this->get('security.context')->getToken()->getUser(); + $document->setUser($user); + $document->setDate(new \DateTime('Now')); + + $form = $this->createForm( + PersonDocumentType::class, $document, array( + 'center' => $document->getCenter(), + 'role' => new Role('CHILL_PERSON_DOCUMENT_UPDATE'), + )); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->getDoctrine()->getManager()->flush(); + + return $this->redirectToRoute( + 'person_document_edit', + ['id' => $document->getId(), 'person' => $person->getId()]); + } + + return $this->render( + 'ChillDocStoreBundle:PersonDocument:edit.html.twig', + [ + 'document' => $document, + 'form' => $form->createView(), + 'person' => $person, + ]); + } + + /** + * @Route("/{id}", name="person_document_delete", methods="DELETE") + */ + public function delete(Request $request, Person $person, PersonDocument $document): Response + { + $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); + $this->denyAccessUnlessGranted('CHILL_PERSON_DOCUMENT_DELETE', $document); + + if ($this->isCsrfTokenValid('delete'.$document->getId(), $request->request->get('_token'))) { + $em = $this->getDoctrine()->getManager(); + $em->remove($document); + $em->flush(); + } + + return $this->redirectToRoute( + 'person_document_index', ['person' => $person->getId()]); + } +} diff --git a/DependencyInjection/ChillDocStoreExtension.php b/DependencyInjection/ChillDocStoreExtension.php new file mode 100644 index 000000000..a41e10f7d --- /dev/null +++ b/DependencyInjection/ChillDocStoreExtension.php @@ -0,0 +1,28 @@ +processConfiguration($configuration, $configs); + + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('services.yml'); + } +} diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php new file mode 100644 index 000000000..162f6ce99 --- /dev/null +++ b/DependencyInjection/Configuration.php @@ -0,0 +1,29 @@ +root('chill_doc_store'); + + // Here you should define the parameters that are allowed to + // configure your bundle. See the documentation linked above for + // more information on that topic. + + return $treeBuilder; + } +} diff --git a/Entity/Document.php b/Entity/Document.php new file mode 100644 index 000000000..c1724fd4b --- /dev/null +++ b/Entity/Document.php @@ -0,0 +1,160 @@ +id; + } + + public function getTitle(): ?string + { + return $this->title; + } + + public function setTitle(string $title): self + { + $this->title = $title; + + return $this; + } + + public function getDescription(): ?string + { + return $this->description; + } + + public function setDescription(string $description): self + { + $this->description = $description; + + return $this; + } + + /** + * @return DocumentCategory + */ + public function getCategory(): ?DocumentCategory + { + return $this->category; + } + + public function setCategory(DocumentCategory $category): self + { + $this->category = $category; + + return $this; + } + + public function getContent(): ?string + { + return $this->content; + } + + public function setContent(string $content): self + { + $this->content = $content; + + return $this; + } + + /** + * Get scope + * + * @return \Chill\MainBundle\Entity\Scope + */ + public function getScope() + { + return $this->scope; + } + + public function setScope($scope): self + { + $this->scope = $scope; + + return $this; + } + + public function getUser() + { + return $this->user; + } + + public function setUser($user): self + { + $this->user = $user; + + return $this; + } + + public function getDate(): ?\DateTimeInterface + { + return $this->date; + } + + public function setDate(\DateTimeInterface $date): self + { + $this->date = $date; + + return $this; + } +} diff --git a/Entity/DocumentCategory.php b/Entity/DocumentCategory.php new file mode 100644 index 000000000..82fe30984 --- /dev/null +++ b/Entity/DocumentCategory.php @@ -0,0 +1,98 @@ +bundleId; + } + + public function setBundleId($bundleId) + { + $this->bundleId = $bundleId; + } + + public function getIdInsideBundle() + { + return $this->idInsideBundle; + } + + public function setIdInsideBundle($idInsideBundle): self + { + $this->idInsideBundle = $idInsideBundle; + + return $this; + } + + public function getDocumentClass() + { + return $this->documentClass; + } + + public function setDocumentClass($documentClass): self + { + $this->documentClass = $documentClass; + + return $this; + } + + public function getName($locale = null) + { + if ($locale) { + if (isset($this->name[$locale])) { + return $this->name[$locale]; + } else { + foreach ($this->name as $name) { + if (!empty($name)) { + return $name; + } + } + } + return ''; + } else { + return $this->name; + } + } + + public function setName($name): self + { + $this->name = $name; + + return $this; + } +} diff --git a/Entity/PersonDocument.php b/Entity/PersonDocument.php new file mode 100644 index 000000000..a0aefbb10 --- /dev/null +++ b/Entity/PersonDocument.php @@ -0,0 +1,45 @@ +person; + } + + public function setPerson($person): self + { + $this->person = $person; + + return $this; + } + + public function getCenter() + { + return $this->getPerson()->getCenter(); + } +} diff --git a/EntityRepository/DocumentCategoryRepository.php b/EntityRepository/DocumentCategoryRepository.php new file mode 100644 index 000000000..d803405e4 --- /dev/null +++ b/EntityRepository/DocumentCategoryRepository.php @@ -0,0 +1,39 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\DocStoreBundle\EntityRepository; + +use Doctrine\ORM\EntityRepository; +use Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option; + +/** + * Get an available idInsideBUndle + */ +class DocumentCategoryRepository extends EntityRepository +{ + public function nextIdInsideBundle() + { + $array_res = $this->getEntityManager() + ->createQuery( + 'SELECT MAX(c.idInsideBundle) + 1 FROM ChillDocStoreBundle:DocumentCategory c') + ->getSingleResult(); + + return $array_res[1] ?: 0; + } +} diff --git a/Form/DocumentCategoryType.php b/Form/DocumentCategoryType.php new file mode 100644 index 000000000..9a3f75d8f --- /dev/null +++ b/Form/DocumentCategoryType.php @@ -0,0 +1,50 @@ + $value) { + if(substr($key, 0, 5) === 'Chill') { + $this->chillBundlesFlipped[$value] = $key; + } + } + } + + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder + ->add('bundleId', ChoiceType::class, array( + 'choices' => $this->chillBundlesFlipped, + 'disabled' => true, + )) + ->add('idInsideBundle', null, array( + 'disabled' => true, + )) + ->add('documentClass', null, array( + 'disabled' => true, + )) // cahcerh par default PersonDocument + ->add('name', TranslatableStringFormType::class) + ; + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => DocumentCategory::class, + ]); + } +} diff --git a/Form/PersonDocumentType.php b/Form/PersonDocumentType.php new file mode 100644 index 000000000..b9d68693e --- /dev/null +++ b/Form/PersonDocumentType.php @@ -0,0 +1,104 @@ +getToken()->getUser() instanceof User) { + throw new \RuntimeException("you should have a valid user"); + } + $this->user = $tokenStorage->getToken()->getUser(); + $this->authorizationHelper = $authorizationHelper; + $this->om = $om; + $this->translatableStringHelper = $translatableStringHelper; + } + + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder + ->add('title') + ->add('description') + ->add('content') + //->add('center') + ->add('scope') + ->add('date', 'date', array('required' => false, 'widget' => 'single_text', 'format' => 'dd-MM-yyyy')) + ->add('category', EntityType::class, array( + 'class' => 'ChillDocStoreBundle:DocumentCategory', + 'query_builder' => function (EntityRepository $er) { + return $er->createQueryBuilder('c') + ->where('c.documentClass = :docClass') + ->setParameter('docClass', PersonDocument::class); + }, + 'choice_label' => function ($entity = null) { + return $entity ? $this->translatableStringHelper->localize($entity->getName()) : ''; + }, + )) + ; + + $this->appendScopeChoices($builder, $options['role'], + $options['center'], $this->user, $this->authorizationHelper, + $this->translatableStringHelper, $this->om); + + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => Document::class, + ]); + + $this->appendScopeChoicesOptions($resolver); + } +} diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml new file mode 100644 index 000000000..c02dc76ab --- /dev/null +++ b/Resources/config/routing.yml @@ -0,0 +1,3 @@ +app: + resource: "@ChillDocStoreBundle/Controller/" + type: annotation diff --git a/Resources/config/services.yml b/Resources/config/services.yml new file mode 100644 index 000000000..e8e185fa9 --- /dev/null +++ b/Resources/config/services.yml @@ -0,0 +1,27 @@ +parameters: +# cl_chill_person.example.class: Chill\PersonBundle\Example + +services: + Chill\DocStoreBundle\Form\DocumentCategoryType: + class: Chill\DocStoreBundle\Form\DocumentCategoryType + arguments: ['%kernel.bundles%'] + tags: + - { name: form.type } + + Chill\DocStoreBundle\Form\PersonDocumentType: + class: Chill\DocStoreBundle\Form\PersonDocumentType + arguments: + - "@security.token_storage" + - "@chill.main.security.authorization.helper" + - "@doctrine.orm.entity_manager" + - "@chill.main.helper.translatable_string" + tags: + - { name: form.type, alias: chill_docstorebundle_form_document } + + Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter: + class: Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter + arguments: + - "@chill.main.security.authorization.helper" + tags: + - { name: security.voter } + - { name: chill.role } diff --git a/Resources/migrations/Version20180322123800.php b/Resources/migrations/Version20180322123800.php new file mode 100644 index 000000000..dc77d78c5 --- /dev/null +++ b/Resources/migrations/Version20180322123800.php @@ -0,0 +1,45 @@ +addSql("CREATE SEQUENCE PersonDocument_id_seq INCREMENT BY 1 MINVALUE 1 START 1;"); + $this->addSql("CREATE TABLE DocumentCategory (bundle_id VARCHAR(255) NOT NULL, id_inside_bundle INT NOT NULL, name JSON NOT NULL, document_class VARCHAR(255) NOT NULL, PRIMARY KEY(bundle_id, id_inside_bundle));"); + $this->addSql("COMMENT ON COLUMN DocumentCategory.name IS '(DC2Type:json_array)';"); + $this->addSql("CREATE TABLE PersonDocument (id INT NOT NULL, category_bundle_id VARCHAR(255) DEFAULT NULL, category_id_inside_bundle INT DEFAULT NULL, scope_id INT DEFAULT NULL, user_id INT DEFAULT NULL, person_id INT DEFAULT NULL, title TEXT NOT NULL, description TEXT NOT NULL, content TEXT NOT NULL, date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id));"); + $this->addSql("CREATE INDEX IDX_BAADC20C369A0BE36EF62EFC ON PersonDocument (category_bundle_id, category_id_inside_bundle);"); + $this->addSql("CREATE INDEX IDX_BAADC20C682B5931 ON PersonDocument (scope_id);"); + $this->addSql("CREATE INDEX IDX_BAADC20CA76ED395 ON PersonDocument (user_id);"); + $this->addSql("CREATE INDEX IDX_BAADC20C217BBB47 ON PersonDocument (person_id);"); + $this->addSql("ALTER TABLE PersonDocument ADD CONSTRAINT FK_BAADC20C369A0BE36EF62EFC FOREIGN KEY (category_bundle_id, category_id_inside_bundle) REFERENCES DocumentCategory (bundle_id, id_inside_bundle) NOT DEFERRABLE INITIALLY IMMEDIATE;"); + $this->addSql("ALTER TABLE PersonDocument ADD CONSTRAINT FK_BAADC20C682B5931 FOREIGN KEY (scope_id) REFERENCES scopes (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); + $this->addSql("ALTER TABLE PersonDocument ADD CONSTRAINT FK_BAADC20CA76ED395 FOREIGN KEY (user_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); + $this->addSql("ALTER TABLE PersonDocument ADD CONSTRAINT FK_BAADC20C217BBB47 FOREIGN KEY (person_id) REFERENCES Person (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + $this->addSql("ALTER TABLE PersonDocument DROP CONSTRAINT FK_BAADC20C369A0BE36EF62EFC"); + $this->addSql("ALTER TABLE PersonDocument DROP CONSTRAINT FK_BAADC20C682B5931"); + $this->addSql("ALTER TABLE PersonDocument DROP CONSTRAINT FK_BAADC20CA76ED395"); + $this->addSql("ALTER TABLE PersonDocument DROP CONSTRAINT FK_BAADC20C217BBB47"); + $this->addSql("DROP TABLE DocumentCategory;"); + $this->addSql("DROP TABLE PersonDocument;"); + $this->addSql("DROP SEQUENCE PersonDocument_id_seq;"); + } +} diff --git a/Resources/views/DocumentCategory/_delete_form.html.twig b/Resources/views/DocumentCategory/_delete_form.html.twig new file mode 100644 index 000000000..5d77512dd --- /dev/null +++ b/Resources/views/DocumentCategory/_delete_form.html.twig @@ -0,0 +1,21 @@ +{# + * Copyright (C) 2018, Champs Libres Cooperative SCRLFS, + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . +#} +
+ + + +
diff --git a/Resources/views/DocumentCategory/_form.html.twig b/Resources/views/DocumentCategory/_form.html.twig new file mode 100644 index 000000000..e2a0a004d --- /dev/null +++ b/Resources/views/DocumentCategory/_form.html.twig @@ -0,0 +1,20 @@ +{# + * Copyright (C) 2018, Champs Libres Cooperative SCRLFS, + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . +#} +{{ form_start(form) }} + {{ form_widget(form) }} + +{{ form_end(form) }} diff --git a/Resources/views/DocumentCategory/edit.html.twig b/Resources/views/DocumentCategory/edit.html.twig new file mode 100644 index 000000000..68c74a29d --- /dev/null +++ b/Resources/views/DocumentCategory/edit.html.twig @@ -0,0 +1,31 @@ +{# + * Copyright (C) 2018, Champs Libres Cooperative SCRLFS, + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . +#} +{% extends "ChillMainBundle::Admin/layout.html.twig" %} + +{% block title %}{{ 'Document category edit'|trans }}{% endblock title %} + +{% block admin_content %} +

{{ 'Document category edit'|trans }}

+ + {{ include('ChillDocStoreBundle:DocumentCategory:_form.html.twig', {'button_label': 'Update'}) }} + + + {{ 'Back to the category list' | trans }} + + + {{ include('ChillDocStoreBundle:DocumentCategory:_delete_form.html.twig') }} +{% endblock %} diff --git a/Resources/views/DocumentCategory/index.html.twig b/Resources/views/DocumentCategory/index.html.twig new file mode 100644 index 000000000..3aaa7fcf0 --- /dev/null +++ b/Resources/views/DocumentCategory/index.html.twig @@ -0,0 +1,60 @@ +{# + * Copyright (C) 2018, Champs Libres Cooperative SCRLFS, + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . +#} +{% extends "ChillMainBundle::Admin/layout.html.twig" %} + +{% block title %}{{ 'Document category list' | trans }}{% endblock title %} + +{% block admin_content %} +

{{ 'Document category list' | trans }}

+ + + + + + + + + + + + + {% for document_category in document_categories %} + + + + + + + + + {% else %} + + + + {% endfor %} + +
{{ 'Creator bundle id' | trans }}{{ 'Internal id inside creator bundle' | trans }}{{ 'Document class' | trans }}{{ 'Name' | trans }}{{ 'Actions' | trans }}
{{ document_category.bundleId }}{{ document_category.idInsideBundle }}{{ document_category.documentClass }}{{ document_category.name | localize_translatable_string}} + + {{ 'show' | trans }} + + + {{ 'edit' | trans }} + +
{{ 'no records found' | trans }}
+ + {{ 'Create new' | trans }} +{% endblock %} diff --git a/Resources/views/DocumentCategory/new.html.twig b/Resources/views/DocumentCategory/new.html.twig new file mode 100644 index 000000000..a87d42585 --- /dev/null +++ b/Resources/views/DocumentCategory/new.html.twig @@ -0,0 +1,29 @@ +{# + * Copyright (C) 2018, Champs Libres Cooperative SCRLFS, + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . +#} +{% extends "ChillMainBundle::Admin/layout.html.twig" %} + +{% block title %}{{ 'Create new document category' | trans }}{% endblock title %} + +{% block admin_content %} +

{{ 'Create new DocumentCategory' | trans }}

+ + {{ include('ChillDocStoreBundle:DocumentCategory:_form.html.twig') }} + + + {{ 'Back to the category list' | trans }} + +{% endblock %} diff --git a/Resources/views/DocumentCategory/show.html.twig b/Resources/views/DocumentCategory/show.html.twig new file mode 100644 index 000000000..cf323781d --- /dev/null +++ b/Resources/views/DocumentCategory/show.html.twig @@ -0,0 +1,54 @@ +{# + * Copyright (C) 2018, Champs Libres Cooperative SCRLFS, + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . +#} +{% extends "ChillMainBundle::Admin/layout.html.twig" %} + +{% block title %}{{ 'Document category show'|trans }}{% endblock title %} + +{% block admin_content %} +

Document category

+ + + + + + + + + + + + + + + + + + + + +
{{ 'Creator bundle id' | trans }}{{ document_category.bundleId }}
{{ 'Internal id inside creator bundle' | trans }}{{ document_category.idInsideBundle }}
{{ 'Document class' | trans }}{{ document_category.documentClass }}
{{ 'Name' | trans }}{{ document_category.name | localize_translatable_string }}
+ + + {{ 'Back to the category list' | trans }} + + + + {{ 'Edit' | trans }} + + + {{ include('ChillDocStoreBundle:DocumentCategory:_delete_form.html.twig') }} +{% endblock %} diff --git a/Resources/views/PersonDocument/_delete_form.html.twig b/Resources/views/PersonDocument/_delete_form.html.twig new file mode 100644 index 000000000..80ae22935 --- /dev/null +++ b/Resources/views/PersonDocument/_delete_form.html.twig @@ -0,0 +1,5 @@ +
+ + + +
diff --git a/Resources/views/PersonDocument/_form.html.twig b/Resources/views/PersonDocument/_form.html.twig new file mode 100644 index 000000000..56f80b630 --- /dev/null +++ b/Resources/views/PersonDocument/_form.html.twig @@ -0,0 +1,4 @@ +{{ form_start(form) }} + {{ form_widget(form) }} + +{{ form_end(form) }} diff --git a/Resources/views/PersonDocument/edit.html.twig b/Resources/views/PersonDocument/edit.html.twig new file mode 100644 index 000000000..db39eca56 --- /dev/null +++ b/Resources/views/PersonDocument/edit.html.twig @@ -0,0 +1,33 @@ +{# + * Copyright (C) 2018, Champs Libres Cooperative SCRLFS, + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . +#} + +{% extends "ChillPersonBundle::layout.html.twig" %} + +{% set activeRouteKey = '' %} + +{% block title %}{{ 'Editing document for %name%'|trans({ '%name%': person.firstName|capitalize ~ ' ' ~ person.lastName } )|capitalize }}{% endblock %} +{% block personcontent %} +

{{ 'Edit Document' | trans }}

+ + {{ include('ChillDocStoreBundle:PersonDocument:_form.html.twig', {'button_label': 'Update'}) }} + + + {{ 'Back to list' | trans }} + + + {{ include('ChillDocStoreBundle:PersonDocument:_delete_form.html.twig') }} +{% endblock %} diff --git a/Resources/views/PersonDocument/index.html.twig b/Resources/views/PersonDocument/index.html.twig new file mode 100644 index 000000000..acedd7175 --- /dev/null +++ b/Resources/views/PersonDocument/index.html.twig @@ -0,0 +1,66 @@ +{# + * Copyright (C) 2018, Champs Libres Cooperative SCRLFS, + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . +#} + +{% extends "ChillPersonBundle::layout.html.twig" %} + +{% set activeRouteKey = '' %} + +{% block title %}{{ 'Documents for %name%'|trans({ '%name%': person.firstName|capitalize ~ ' ' ~ person.lastName } )|capitalize }}{% endblock %} + +{% block personcontent %} +

{{ 'Document for %name%'|trans({ '%name%': person.firstName|capitalize ~ ' ' ~ person.lastName } )|capitalize }}

+ + + + + + + + + + + + + + {% for document in documents %} + + + + + + + + + {% else %} + + + + {% endfor %} + +
{{ 'Title' | trans }}{{ 'Description' | trans }}{{ 'Content' | trans }}{{ 'Last modification by' | trans }}{{ 'Last update' | trans }}{{ 'Actions' | trans }}
{{ document.title }}{{ document.description }}{{ document.content }}{{ document.user }}{{ document.date ? document.date|date('Y-m-d H:i:s') : '' }} + + show + + + edit + +
no records found
+ + + {{ 'Create new' | trans }} + +{% endblock %} diff --git a/Resources/views/PersonDocument/new.html.twig b/Resources/views/PersonDocument/new.html.twig new file mode 100644 index 000000000..2a423051d --- /dev/null +++ b/Resources/views/PersonDocument/new.html.twig @@ -0,0 +1,31 @@ +{# + * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . +#} +{% extends "ChillPersonBundle::layout.html.twig" %} + +{% set activeRouteKey = '' %} + +{% block title %}{{ 'New document for %name%'|trans({ '%name%': person.firstName|capitalize ~ ' ' ~ person.lastName } )|capitalize }}{% endblock %} + +{% block personcontent %} +

{{ 'Create new Document' | trans }}

+ + {{ include('ChillDocStoreBundle:PersonDocument:_form.html.twig') }} + + + {{ 'back to list' | trans }} + +{% endblock %} diff --git a/Resources/views/PersonDocument/show.html.twig b/Resources/views/PersonDocument/show.html.twig new file mode 100644 index 000000000..c5b42345e --- /dev/null +++ b/Resources/views/PersonDocument/show.html.twig @@ -0,0 +1,68 @@ +{# + * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . +#} +{% extends "ChillPersonBundle::layout.html.twig" %} + +{% set activeRouteKey = '' %} + +{% block title %}{{ 'Detail of document of %name%'|trans({ '%name%': person.firstName|capitalize ~ ' ' ~ person.lastName } )|capitalize }}{% endblock %} + +{% block personcontent %} +

{{ 'Document' | trans }}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{{ 'Title' | trans }}{{ document.title }}
{{ 'Description' | trans }}{{ document.description }}
{{ 'Content' | trans }}{{ document.content }}
{{ 'Center' | trans}}{{ document.center }}
{{ 'Scope' | trans }}{{ document.scope.name | localize_translatable_string }}
{{ 'Last modificiation by' | trans }}{{ document.user }}
{{ 'Last update' | trans }}{{ document.date ? document.date|date('Y-m-d H:i:s') : '' }}
+ + + {{ 'Back to list' | trans }} + + + + {{ 'Edit' | trans }} + + + {{ include('ChillDocStoreBundle:PersonDocument:_delete_form.html.twig') }} +{% endblock %} diff --git a/Security/Authorization/PersonDocumentVoter.php b/Security/Authorization/PersonDocumentVoter.php new file mode 100644 index 000000000..55302b77c --- /dev/null +++ b/Security/Authorization/PersonDocumentVoter.php @@ -0,0 +1,83 @@ +. + */ + +namespace Chill\DocStoreBundle\Security\Authorization; + +use Chill\MainBundle\Security\Authorization\AbstractChillVoter; +use Chill\MainBundle\Security\Authorization\AuthorizationHelper; +use Chill\MainBundle\Security\ProvideRoleInterface; + +/** + * + */ +class PersonDocumentVoter extends AbstractChillVoter implements ProvideRoleInterface +{ + const CREATE = 'CHILL_PERSON_DOCUMENT_CREATE'; + const SEE = 'CHILL_PERSON_DOCUMENT_SEE'; + const SEE_DETAILS = 'CHILL_PERSON_DOCUMENT_SEE_DETAILS'; + const UPDATE = 'CHILL_PERSON_DOCUMENT_UPDATE'; + const DELETE = 'CHILL_PERSON_DOCUMENT_DELETE'; + + /** + * + * @var AuthorizationHelper + */ + protected $helper; + + public function __construct(AuthorizationHelper $helper) + { + $this->helper = $helper; + } + + protected function getSupportedAttributes() + { + return array(self::CREATE, self::SEE, self::UPDATE, self::DELETE, + self::SEE_DETAILS); + } + + protected function getSupportedClasses() + { + return array('Chill\DocStoreBundle\Entity\PersonDocument'); + } + + protected function isGranted($attribute, $report, $user = null) + { + if (! $user instanceof \Chill\MainBundle\Entity\User){ + return false; + } + + return $this->helper->userHasAccess($user, $report, $attribute); + } + + public function getRoles() + { + return $this->getSupportedAttributes(); + } + + public function getRolesWithoutScope() + { + return array(); + } + + + public function getRolesWithHierarchy() + { + return ['PersonDocument' => $this->getRoles() ]; + } +}