Commit 7c062d2d authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Merge branch 'connor' into connor-api

parents a09b6df8 13cca65c
Loading
Loading
Loading
Loading
Loading
+32 −6
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ use Laminas\View\Model\JsonModel;
use Oscar\Entity\ActivityMotCle;
use Oscar\Provider\Privileges;
use Oscar\Service\ProjectGrantService;
use Oscar\Service\ProjectService;
use Oscar\Traits\UseLoggerService;
use Oscar\Traits\UseLoggerServiceTrait;
use Throwable;
@@ -31,6 +32,22 @@ class ActivityMotsClesController extends AbstractOscarController implements UseL
        $this->activityService = $activityService;
    }

    /**
     * @return ProjectService
     */
    public function getProjectService(): ProjectService
    {
        return $this->projectService;
    }

    /**
     * @param ProjectService $projectService
     */
    public function setProjectService(ProjectService $projectService): void
    {
        $this->projectService = $projectService;
    }

    public function apiAction()
    {
        try {
@@ -40,19 +57,24 @@ class ActivityMotsClesController extends AbstractOscarController implements UseL
            if ($activityId) {
                $activity = $this->getActivityService()->getGrant($activityId);
            }
            $project = NULL;
            $projectId = $this->params()->fromQuery('project_id');
            if ($projectId) {
                $project = $this->getProjectService()->getProject($projectId);
            }

            if ($this->getRequest()->getMethod() == "GET") {
                $includeActivityCountQueryParam = $this->params()->fromQuery('include_activity_count');
                $includeActivityCount = $includeActivityCountQueryParam && $includeActivityCountQueryParam === "true";

                return $this->getMotsCles($includeActivityCount, $activity);
                return $this->getMotsCles($includeActivityCount, $activity, $project);
            }

            if ($this->getRequest()->getMethod() == "POST") {
                $action_mot_cle_json = json_decode($this->getRequest()->getContent());

                if ($action_mot_cle_json->action == "create") {
                    return $this->createMotCle($action_mot_cle_json, $activity);
                    return $this->createMotCle($action_mot_cle_json, $activity, $project);
                }

                if ($action_mot_cle_json->action == "delete") {
@@ -81,9 +103,11 @@ class ActivityMotsClesController extends AbstractOscarController implements UseL
        }
    }

    private function getMotsCles($includeCount, $activity) {
    private function getMotsCles($includeCount, $activity, $project) {

        if ($activity) {
        if ($project) {
            $this->getOscarUserContextService()->check(Privileges::PROJECT_ACTIVITY_ADD, $project);
        } else if ($activity) {
            $this->getOscarUserContextService()->check(Privileges::ACTIVITY_EDIT, $activity);
        } else {
            $this->getOscarUserContextService()->check(Privileges::ACTIVITY_CREATE);
@@ -117,9 +141,11 @@ class ActivityMotsClesController extends AbstractOscarController implements UseL
        return $response;
    }

    private function createMotCle($action_mot_cle_json, $activity) {
    private function createMotCle($action_mot_cle_json, $activity, $project) {

        if ($activity) {
        if ($project) {
            $this->getOscarUserContextService()->check(Privileges::PROJECT_ACTIVITY_ADD, $project);
        } else if ($activity) {
            $this->getOscarUserContextService()->check(Privileges::ACTIVITY_EDIT, $activity);
        } else {
            $this->getOscarUserContextService()->check(Privileges::ACTIVITY_CREATE);
+2 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Oscar\Service\OscarUserContext;
use Oscar\Service\ProjectGrantService;
use Oscar\Service\ProjectService;

class ActivityMotsClesControllerFactory implements FactoryInterface
{
@@ -17,6 +18,7 @@ class ActivityMotsClesControllerFactory implements FactoryInterface
        $c->setOscarUserContextService($container->get(OscarUserContext::class));
        $c->setLoggerService($container->get('Logger'));
        $c->setActivityService($container->get(ProjectGrantService::class));
        $c->setProjectService($container->get(ProjectService::class));
        return $c;
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -1750,8 +1750,8 @@ class AdministrationController extends AbstractOscarController implements
                        if (array_key_exists($t->getId(), $infos)) {
                            $dt['documents_total'] = $infos[$t->getId()];
                            if ($hasSearchAccess) {
                                $dt['documents_view'] = $this->url()->fromRoute('contract/advancedsearch')
                                    . '?q=&criteria[]=td%3B' . $t->getId() . '%3B0';
                                $dt['documents_view'] = $this->url()->fromRoute('contract/search-global')
                                    . '?q=&f[]=dt%3B' . $t->getId() . '%3B0';
                            }
                        }
                        $out['types'][] = $dt;
+20 −1
Original line number Diff line number Diff line
@@ -573,8 +573,27 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
            }
        }

        $connectorsConf = $this->getOrganizationService()->getConnectorsList();
        $connectorsConfEntity = $entity->getConnectors();
        $connectorsInfos = [];
        foreach ($connectorsConf as $connector) {
            $connectorsInfos[$connector] = [
                'value' => null,
                'native' => true
            ];
        }
        foreach ($connectorsConfEntity as $connector=>$value) {
            if( !array_key_exists($connector, $connectorsInfos) ){
                $connectorsInfos[$connector] = [
                    'native' => false
                ];
            }
            $connectorsInfos[$connector]['value'] = $value;
        }


        $output = [
            'connectors'     => $this->getOrganizationService()->getConnectorsList(),
            'connectors'     => $connectorsInfos,
            'organization'   => $this->getOrganizationService()->getOrganization($organizationId),
            'ancestors'      => $this->getOrganizationService()->getAncestors($organizationId),
            'subStructures'  => $this->getOrganizationService()->getSubStructure($organizationId),
+110 −97
Original line number Diff line number Diff line
@@ -93,23 +93,47 @@ class PersonController extends AbstractOscarController
            return $this->jsonError($e->getMessage());
        }
    }
    public function deleteAction(): array

    public function deleteAction(): array|Response
    {
        $method = $this->getHttpXMethod();
        $this->getOscarUserContextService()->check(Privileges::PERSON_EDIT);
        $personId = $this->params()->fromRoute('id');
        $error = null;
        $person = null;

        try {
            if ($method != 'POST') {
                return $this->getResponseBadRequest("Opération non-authorisée");
            $person = $this->getPersonService()->getPerson($personId);
        } catch (\Exception $e) {
            return [
                'person' => $person,
                'error' => "Impossible de charger la personne : " . $e->getMessage()
            ];
        }

            $this->getPersonDeleteService()->delete($this->params()->fromRoute('id'));
        if ($method != 'POST') {
            return [
                'person' => $person,
                'error' => $error
            ];
        }

            if ($this->getOscarUserContextService()->check(Privileges::PERSON_INDEX)) {
                $this->redirect()->toRoute('person/index');
        try {
            $request = $this->getRequest();
            if ($request->getPost('confirm') === 'Confirmer') {
                $this->getPersonDeleteService()->delete($personId);
                $this->getFlashMessenger()->addSuccessMessage("Suppression de '$person' effectuée");
                if ($this->getOscarUserContextService()->hasPrivileges(Privileges::PERSON_INDEX)) {
                    return $this->redirect()->toRoute('person');
                }
            } else {
                return $this->redirect()->toRoute('person/show', array('id' => $personId));
            }
            $this->redirect()->toRoute('home');
        } catch (\Exception $e) {
            throw new OscarException("PAS POSSIBLE : " . $e->getMessage());
            return [
                'person' => $person,
                'error' => "La procédure de suppression a échouée : " . $e->getMessage()
            ];
        }
    }

@@ -197,8 +221,7 @@ class PersonController extends AbstractOscarController
        $extended = $this->params()->fromQuery('extended', 0);
        if ($extended) {
            $datas = $this->getPersonService()->searchPersonnel($q, $page, $params);
        }
        else {
        } else {
            $datas = $this->getPersonService()->getPersonsSearchPaged($q, $page, $params);
        }

@@ -297,8 +320,7 @@ class PersonController extends AbstractOscarController
        if ($this->getOscarUserContextService()->hasPrivileges(Privileges::PERSON_SHOW)) {
            $allow = true;
            $justXHR = false;
        }
        else {
        } else {
            $context = $this->getRequest()->getQuery("context");
            $context_param = $this->getRequest()->getQuery("context_param");
            if ($context) {
@@ -311,8 +333,7 @@ class PersonController extends AbstractOscarController
                        return new JsonModel($persons);
                        break;
                }
            }
            else {
            } else {
                $allow = $this->getOscarUserContextService()->hasOneOfPrivilegesInAnyRoles(
                    [
                        Privileges::ACTIVITY_INDEX,
@@ -330,8 +351,7 @@ class PersonController extends AbstractOscarController
            );
            if ($justXHR) {
                return $this->getResponseUnauthorized();
            }
            else {
            } else {
                throw new UnAuthorizedException();
            }
        }
@@ -585,8 +605,7 @@ class PersonController extends AbstractOscarController
    {
        if (array_key_exists($key, $array)) {
            return $array[$key];
        }
        else {
        } else {
            return null;
        }
    }
@@ -615,8 +634,7 @@ class PersonController extends AbstractOscarController
        if ($person) {
            $this->getPersonService()->synchronize($person);
            return $this->redirect()->toRoute('person/show', ['id' => $person->getId()]);
        }
        else {
        } else {
            return $this->getResponseNotFound('Personne introuvable');
        }
    }
@@ -640,8 +658,7 @@ class PersonController extends AbstractOscarController
                    if ($declarerId) {
                        // Détails pour le déclarant
                        return $this->getResponseNotImplemented("Fonctionnalité à venir");
                    }
                    else {
                    } else {
                        $output = $this->baseJsonResponse();
                        $period = DateTimeUtils::extractPeriodDatasFromString(
                            $this->params()->fromQuery('period', date('Y-m'))
@@ -783,12 +800,10 @@ class PersonController extends AbstractOscarController
                                $person->setCustomSettingsObj($custom);
                                $this->getEntityManager()->flush($person);
                                $this->getLoggerService()->info(print_r($custom, true));
                            }
                            elseif ($daysLength != null) {
                            } elseif ($daysLength != null) {
                                $this->getUserParametersService()->performChangeSchedule($daysLength, $person);
                                return $this->getResponseOk("Heures enregistrées");
                            }
                            else {
                            } else {
                                if (!array_key_exists($model, $models)) {
                                    return $this->getResponseBadRequest("Modèle inconnu");
                                }
@@ -879,8 +894,7 @@ class PersonController extends AbstractOscarController
                        default:
                            throw new OscarException("Opération inconnue");
                    }
                }
                else {
                } else {
                    return $this->getResponseUnauthorized(
                        "Vous n'avez pas le droit de déléguer la déclaration d'une personne à une autre."
                    );
@@ -908,8 +922,7 @@ class PersonController extends AbstractOscarController
                    if ($mode == 'replace') {
                        $this->getPersonService()->refererentReplaceBy($newReferent, $referent);
                        return $this->redirect()->toRoute('person/show', ['id' => $newReferent->getId()]);
                    }
                    else {
                    } else {
                        $this->getPersonService()->refererentAddFromReferent($newReferent, $referent);
                        return $this->redirect()->toRoute('person/show', ['id' => $newReferent->getId()]);
                    }
Loading