Commit 789baf05 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Merge branch 'macclane' into macclane-lille (sauf le composer.lock)

parents 87a2607a 1598edc4
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -505,7 +505,7 @@ class ConnectorActivityJSON implements ConnectorInterface
                ->setStatus($status)
                ->setAmount(((double)$data->amount));

            if (property_exists($data, 'datestart') ){
            if (property_exists($data, 'datestart') && $data->datestart != null ){
                try {
                    $dateStart = new \DateTime($data->datestart);
                } catch (\Exception $e) {
@@ -519,7 +519,7 @@ class ConnectorActivityJSON implements ConnectorInterface
                }
            }

            if ($data->dateend) {
            if (property_exists($data, 'dateend') && $data->dateend != null ){
                try {
                    $dateEnd = new \DateTime($data->dateend);
                } catch (\Exception $e) {
+172 −112
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
 *
 * @copyright Certic (c) 2015
 */

namespace Oscar\Controller;

use BjyAuthorize\Exception\UnAuthorizedException;
@@ -43,7 +44,8 @@ use UnicaenApp\ServiceManager\ServiceLocatorAwareInterface;
use Zend\View\Model\JsonModel;
use Zend\View\Model\ViewModel;

class OrganizationController extends AbstractOscarController implements UseOrganizationService, UseProjectService, UseProjectGrantService, UseActivityLogService
class OrganizationController extends AbstractOscarController implements UseOrganizationService, UseProjectService,
                                                                        UseProjectGrantService, UseActivityLogService
{
    use UseOrganizationServiceTrait, UseProjectServiceTrait, UseProjectGrantServiceTrait, UseActivityLogServiceTrait;

@@ -69,12 +71,8 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
    }






    public function deleteAction(){

    public function deleteAction()
    {
        $this->getOscarUserContextService()->check(Privileges::ORGANIZATION_DELETE);

        $id = $this->params()->fromRoute('id');
@@ -89,10 +87,13 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
                    $this->getOrganizationService()->deleteOrganization($id);
                    $this->redirect()->toRoute("organization");
                } catch (ForeignKeyConstraintViolationException $e) {
                    throw new OscarException("Vous devez supprimer cette organisation des activités et supprimer ces membres avant de la supprimer.", 0, $e);
                    throw new OscarException(
                        "Vous devez supprimer cette organisation des activités et supprimer ces membres avant de la supprimer.",
                        0,
                        $e
                    );
                }
            }

        } else {
            $token = $this->getSessionService()->createToken();
        }
@@ -110,19 +111,29 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
     */
    public function indexAction()
    {

        $format = $this->getRequestFormat();
        $allow = false;
        $justXHR = true;

        // On test les accès
        if( $this->getOscarUserContextService()->hasPrivileges(Privileges::ORGANIZATION_SHOW) ){
        if ($this->getOscarUserContextService()->hasPrivileges(Privileges::ORGANIZATION_INDEX)) {
            $allow = true;
            $justXHR = false;
        } else {
            $allow = $this->getOscarUserContextService()->hasOneOfPrivilegesInAnyRoles([
            $allow = $this->getOscarUserContextService()->hasOneOfPrivilegesInAnyRoles(
                [
                    Privileges::ORGANIZATION_INDEX,
                    Privileges::ACTIVITY_INDEX,
                    Privileges::ACTIVITY_ORGANIZATION_MANAGE,
                Privileges::PROJECT_ORGANIZATION_MANAGE]);
                    Privileges::PROJECT_ORGANIZATION_MANAGE
                ]
            );

            $justXHR = !$this->getOscarUserContextService()->hasOneOfPrivilegesInAnyRoles(
                [
                    Privileges::ORGANIZATION_INDEX
                ]
            );
        }

        if (!$allow) {
@@ -149,7 +160,6 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
        }



        if ($this->getRequest()->isXmlHttpRequest()) {
            $result = ['datas' => []];
            foreach ($organizations as $data) {
@@ -195,12 +205,31 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
        $filename = uniqid('oscar_export_organization_') . '.csv';
        $handler = fopen('/tmp/' . $filename, 'w');

        $headers = ['ID','NomCourt','NomLong','Code','Email','URL','rue1','rue2','rue3','CP','BP','ville','Pays','CodePays','Téléphone','SIFAC','SIRET','Type','TVA'];
        $headers = [
            'ID',
            'NomCourt',
            'NomLong',
            'Code',
            'Email',
            'URL',
            'rue1',
            'rue2',
            'rue3',
            'CP',
            'BP',
            'ville',
            'Pays',
            'CodePays',
            'Téléphone',
            'SIFAC',
            'SIRET',
            'Type',
            'TVA'
        ];

        fputcsv($handler, $headers);



        $i = 0;
        /** @var Organization $organization */
        foreach ($organizations as $organization) {
@@ -256,12 +285,26 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
     */
    public function searchAction()
    {
        $allow = false;

        // On test les accès
        if ($this->getOscarUserContextService()->hasPrivileges(Privileges::ORGANIZATION_INDEX)) {
            $allow = true;
        } else {
            $allow = $this->getOscarUserContextService()->hasOneOfPrivilegesInAnyRoles(
                [
                    Privileges::ACTIVITY_ORGANIZATION_MANAGE,
                    Privileges::PROJECT_ORGANIZATION_MANAGE,
                    Privileges::ORGANIZATION_EDIT,
                    Privileges::ORGANIZATION_INDEX
                ]
            );
        }

        if(
            !$this->getOscarUserContextService()->hasPrivilegeDeep(Privileges::PROJECT_ORGANIZATION_MANAGE) &&
            !$this->getOscarUserContextService()->hasPrivilegeDeep(Privileges::ACTIVITY_ORGANIZATION_MANAGE)
        ){
            return $this->getResponseUnauthorized("Vous n'avez pas l'authorisation d'accéder à la  liste des organisations");
        if (!$allow) {
            return $this->getResponseUnauthorized(
                "Vous n'avez pas l'authorisation d'accéder à la  liste des organisations"
            );
        }

        $page = (int)$this->params()->fromQuery('page', 1);
@@ -367,8 +410,7 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
                        $this->getEntityManager()->persist($newPartner);
                        $newPartner->setRoleObj($organizationPerson->getRoleObj())
                            ->setOrganization($newOrganization)
                            ->setPerson($organizationPerson->getPerson())
                            ;
                            ->setPerson($organizationPerson->getPerson());
                        $this->getEntityManager()->remove($organizationPerson);
                    }
                    $this->getEntityManager()->remove($organization);
@@ -422,14 +464,19 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
        return [
            'connectors' => $this->getOrganizationService()->getConnectorsList(),
            'organization' => $this->getOrganizationService()->getOrganization($organizationId),
            'projects' => new UnicaenDoctrinePaginator($this->getProjectService()->getProjectOrganization($organizationId), $page),
            'projects' => new UnicaenDoctrinePaginator(
                $this->getProjectService()->getProjectOrganization($organizationId), $page
            ),
            'activities' => $this->getProjectGrantService()->byOrganizationWithoutProject($organizationId),
        ];
    }

    public function newAction()
    {
        $form = new OrganizationIdentificationForm($this->getOrganizationService()->getConnectorsList(), $this->getOrganizationService()->getOrganizationTypesSelect());
        $form = new OrganizationIdentificationForm(
            $this->getOrganizationService()->getConnectorsList(),
            $this->getOrganizationService()->getOrganizationTypesSelect()
        );
        $entity = new Organization();
        $form->init();
        $form->bind($entity);
@@ -446,18 +493,21 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
            }
        }

        $view = new ViewModel(array(
        $view = new ViewModel(
            array(
                'form' => $form,
                'id' => null,
                'types' => $this->getOrganizationService()->getTypes(),
                'connectors' => $this->getOrganizationService()->getConnectorsList(),
        ));
            )
        );
        $view->setTemplate('oscar/organization/form');

        return $view;
    }

    public function synchronizeConnectorAction(){
    public function synchronizeConnectorAction()
    {
        $idOrganization = $this->params()->fromRoute('id');
        $connector = $this->params()->fromRoute('connector');

@@ -474,15 +524,16 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
                $organization = $connector->syncOrganization($organization);
                $this->getEntityManager()->flush($organization);

                return $this->redirect()->toRoute('organization/show',
                    ['id' => $organization->getId()]);
                return $this->redirect()->toRoute(
                    'organization/show',
                    ['id' => $organization->getId()]
                );
            } catch (\Exception $e) {
                throw $e;
            }
        } else {
            die('Bad connector ' . $connector);
        }

    }

    public function scissionAction()
@@ -516,10 +567,12 @@ class OrganizationController extends AbstractOscarController implements UseOrgan


        if ($request->isPost()) {

            if ($this->params()->fromPost('etape', 1) == 3) {
                die('DO');
                if( isset($_SESSION['fusion_hash']) && $_SESSION['fusion_hash'] == $this->params()->fromPost('hash', '') ){
                if (isset($_SESSION['fusion_hash']) && $_SESSION['fusion_hash'] == $this->params()->fromPost(
                        'hash',
                        ''
                    )) {
                    if (!isset($_SESSION['fusion_data'])) {
                        $this->flashMessenger()->addErrorMessage("Erreur de transmission des données.");
                        $this->redirect()->toRoute('organization/fusion');
@@ -532,7 +585,9 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
                            ->getQuery()
                            ->getResult();

                        $to = $this->getEntityManager()->getRepository(Organization::class)->find($_SESSION['fusion_data']['to']);
                        $to = $this->getEntityManager()->getRepository(Organization::class)->find(
                            $_SESSION['fusion_data']['to']
                        );

                        $date = $_SESSION['fusion_data']['at'];

@@ -550,14 +605,12 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
                        $this->getEntityManager()->flush();
                        $this->flashMessenger()->addSuccessMessage("Fusion des organisations réussie.");
                        $this->redirect()->toRoute('organization/show', ['id' => $to->getId()]);

                    }
                } else {
                    $this->flashMessenger()->addErrorMessage("La procédure de fusion a été interrompue.");
                    $this->redirect()->toRoute('organization/fusion');
                    return;
                }

            } else {
                $etape = 2;
                $hash = uniqid('fusion_');
@@ -593,7 +646,9 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
                $_SESSION['fusion_data'] = $fusionDatas;
                $activities = [];

                $organisationsTo = $this->getEntityManager()->getRepository(Organization::class)->createQueryBuilder('a')->where('a.id IN (:ids)')
                $organisationsTo = $this->getEntityManager()->getRepository(Organization::class)->createQueryBuilder(
                    'a'
                )->where('a.id IN (:ids)')
                    ->setParameter('ids', $to)
                    ->getQuery()
                    ->getResult();
@@ -604,7 +659,6 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
                foreach ($organisationFrom->getActivities() as $activity) {
                    $activities[$activity->getActivity()->getId()] = $activity;
                }

            }
        }
        return [
@@ -646,9 +700,11 @@ class OrganizationController extends AbstractOscarController implements UseOrgan


        if ($request->isPost()) {

            if ($this->params()->fromPost('etape', 1) == 3) {
                if( isset($_SESSION['fusion_hash']) && $_SESSION['fusion_hash'] == $this->params()->fromPost('hash', '') ){
                if (isset($_SESSION['fusion_hash']) && $_SESSION['fusion_hash'] == $this->params()->fromPost(
                        'hash',
                        ''
                    )) {
                    if (!isset($_SESSION['fusion_data'])) {
                        $this->flashMessenger()->addErrorMessage("Erreur de transmission des données.");
                        $this->redirect()->toRoute('organization/fusion');
@@ -661,7 +717,9 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
                            ->getQuery()
                            ->getResult();

                        $to = $this->getEntityManager()->getRepository(Organization::class)->find($_SESSION['fusion_data']['to']);
                        $to = $this->getEntityManager()->getRepository(Organization::class)->find(
                            $_SESSION['fusion_data']['to']
                        );

                        $date = $_SESSION['fusion_data']['at'];

@@ -684,19 +742,16 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
                                $newPartner = $projectPartner->fusionTo($to, $date);
                                $this->getEntityManager()->persist($newPartner);
                            }

                        }
                        $this->getEntityManager()->flush();
                        $this->flashMessenger()->addSuccessMessage("Fusion des organisations réussie.");
                        $this->redirect()->toRoute('organization/show', ['id' => $to->getId()]);

                    }
                } else {
                    $this->flashMessenger()->addErrorMessage("La procédure de fusion a été interrompue.");
                    $this->redirect()->toRoute('organization/fusion');
                    return;
                }

            } else {
                $etape = 2;
                $hash = uniqid('fusion_');
@@ -732,7 +787,9 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
                $_SESSION['fusion_data'] = $fusionDatas;
                $activities = [];

                $organisations = $this->getEntityManager()->getRepository(Organization::class)->createQueryBuilder('a')->where('a.id IN (:ids)')
                $organisations = $this->getEntityManager()->getRepository(Organization::class)->createQueryBuilder(
                    'a'
                )->where('a.id IN (:ids)')
                    ->setParameter('ids', $from)
                    ->getQuery()
                    ->getResult();
@@ -775,7 +832,6 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
        $referer = $this->getRequest()->getHeader('referer');
        header('Location: ' . $_SERVER['HTTP_REFERER']);
        die();

    }

    /**
@@ -797,20 +853,22 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
            $entity = $result->getQuery()->getSingleResult();
        }

        $form = new OrganizationIdentificationForm($this->getOrganizationService()->getConnectorsList(), $this->getOrganizationService()->getOrganizationTypesSelect());
        $form = new OrganizationIdentificationForm(
            $this->getOrganizationService()->getConnectorsList(),
            $this->getOrganizationService()->getOrganizationTypesSelect()
        );
        $form->init();
        $form->bind($entity);



        if ($this->getRequest()->isPost()) {

            $form->setData($this->getRequest()->getPost());
            if ($form->isValid()) {
                $this->getEntityManager()->flush($entity);
                $this->getActivityLogService()->addUserInfo(
                    sprintf('a modifié les informations pour %s', $entity->log()),
                    $this->getDefaultContext(), $entity->getId(),
                    $this->getDefaultContext(),
                    $entity->getId(),
                    LogActivity::LEVEL_INCHARGE
                );
                $em->flush($entity);
@@ -828,13 +886,15 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
        }


        $view = new ViewModel(array(
        $view = new ViewModel(
            array(
                'id' => $id,
                'organization' => $entity,
                'types' => $this->getOrganizationService()->getTypes(),
                'form' => $form,
                'connectors' => $this->getOrganizationService()->getConnectorsList()
        ));
            )
        );
        $view->setTemplate('oscar/organization/form');

        return $view;
+9 −2
Original line number Diff line number Diff line
@@ -336,11 +336,18 @@ class PersonController extends AbstractOscarController implements UsePersonServi
        $justXHR = true;

        // On test les accès
        if ($this->getOscarUserContextService()->hasPrivileges(Privileges::PERSON_SHOW)) {
        if ($this->getOscarUserContextService()->hasPrivileges(Privileges::PERSON_INDEX)) {
            $allow = true;
            $justXHR = false;
        } else {
            $allow = $this->getOscarUserContextService()->hasOneOfPrivilegesInAnyRoles([Privileges::ACTIVITY_PERSON_MANAGE, Privileges::PROJECT_PERSON_MANAGE, Privileges::ORGANIZATION_EDIT]);
            $allow = $this->getOscarUserContextService()->hasOneOfPrivilegesInAnyRoles([
                Privileges::ACTIVITY_PERSON_MANAGE,
                Privileges::ACTIVITY_INDEX,
                Privileges::PROJECT_PERSON_MANAGE,
                Privileges::ORGANIZATION_EDIT,
                Privileges::PERSON_INDEX]);

            $justXHR = !$this->getOscarUserContextService()->hasOneOfPrivilegesInAnyRoles([Privileges::PERSON_INDEX]);
        }

        if (!$allow) {
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ class ConnectorActivityCSVWithConfTest extends TestCase
    {
        $config = $this->getDemoConfig();
        $this->assertTrue(is_array($config));
        $this->assertEquals(26, count($this->getDemoConfig()), "La configuration de démo contient 25 entrées.");
        $this->assertEquals(27, count($this->getDemoConfig()), "La configuration de démo contient 27 entrées.");
    }