index.php 10.8 KB
Newer Older
Florian Azizian's avatar
Florian Azizian committed
1
2
3
<?php

/**
4
5
* Copyright Maarch since 2008 under license.
* See LICENSE.txt file at the root folder for more details.
Florian Azizian's avatar
Florian Azizian committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
* This file is part of Maarch software.
*
*/

/**
* @brief Rest Routes File
* @author dev@maarch.org
*/

require '../vendor/autoload.php';

//Root application position
chdir('..');
date_default_timezone_set(\SrcCore\models\CoreConfigModel::getTimezone());

$app = new \Slim\App(['settings' => ['displayErrorDetails' => true, 'determineRouteBeforeAppMiddleware' => true]]);

//Authentication
Alex ORLUC's avatar
Alex ORLUC committed
24
$app->add(function (\Slim\Http\Request $request, \Slim\Http\Response $response, callable $next) {
25
26
27
28
    $configPath = \SrcCore\models\CoreConfigModel::getConfigPath();
    if (!is_file($configPath . '/config.xml')) {
        return $response->withStatus(400)->withJson(['errors' => 'Configuration file is missing']);
    }
Alex ORLUC's avatar
Alex ORLUC committed
29
30
31
    $route = $request->getAttribute('route');
    $currentMethod = empty($route) ? '' : $route->getMethods()[0];
    $currentRoute = empty($route) ? '' : $route->getPattern();
Damien's avatar
Damien committed
32

33
    if (in_array($currentMethod.$currentRoute, \SrcCore\controllers\AuthenticationController::ROUTES_WITHOUT_AUTHENTICATION)) {
Alex ORLUC's avatar
Alex ORLUC committed
34
35
        $response = $next($request, $response);
    } else {
Damien's avatar
Damien committed
36
37
        $authorizationHeaders = $request->getHeader('Authorization');
        $id = \SrcCore\controllers\AuthenticationController::authentication($authorizationHeaders);
Damien's avatar
Damien committed
38
39
        if (!empty($id)) {
            $GLOBALS['id'] = $id;
40
41
42
43
44
45
            if (!empty($currentRoute)) {
                $r = \SrcCore\controllers\AuthenticationController::isRouteAvailable(['userId' => $id, 'currentRoute' => $currentRoute]);
                if (!$r['isRouteAvailable']) {
                    return $response->withStatus(403)->withJson(['errors' => $r['errors']]);
                }
            }
Alex ORLUC's avatar
Alex ORLUC committed
46
47
48
49
50
            $response = $next($request, $response);
        } else {
            $response = $response->withStatus(401)->withJson(['errors' => 'Authentication Failed']);
        }
    }
Damien's avatar
Damien committed
51

Alex ORLUC's avatar
Alex ORLUC committed
52
53
    return $response;
});
Damien's avatar
Damien committed
54
55

//Authentication
56
$app->get('/authenticationInformations', \SrcCore\controllers\AuthenticationController::class . ':getInformations');
Damien's avatar
Damien committed
57
$app->post('/authenticate', \SrcCore\controllers\AuthenticationController::class . ':authenticate');
Damien's avatar
Damien committed
58
$app->get('/authenticate/token', \SrcCore\controllers\AuthenticationController::class . ':getRefreshedToken');
59
$app->get('/authenticate/logout', \SrcCore\controllers\AuthenticationController::class . ':logout');
Florian Azizian's avatar
Florian Azizian committed
60

Damien's avatar
Damien committed
61
62
//Attachments
$app->get('/attachments/{id}', \Attachment\controllers\AttachmentController::class . ':getById');
63
$app->get('/attachments/{id}/thumbnails/{page}', \Attachment\controllers\AttachmentController::class . ':getThumbnailContent');
Damien's avatar
Damien committed
64

65
66
67
//AutoComplete
$app->get('/autocomplete/users', \SrcCore\controllers\AutoCompleteController::class . ':getUsers');

Damien's avatar
Damien committed
68
//Configurations
69
70
71
72
73
$app->get('/configurations', \Configuration\controllers\ConfigurationController::class . ':get');
$app->post('/configurations', \Configuration\controllers\ConfigurationController::class . ':create');
$app->get('/configurations/{id}', \Configuration\controllers\ConfigurationController::class . ':getById');
$app->patch('/configurations/{id}', \Configuration\controllers\ConfigurationController::class . ':update');
$app->delete('/configurations/{id}', \Configuration\controllers\ConfigurationController::class . ':delete');
74
$app->get('/configurations/{id}/connection', \Configuration\controllers\ConfigurationController::class . ':testConnection');
Damien's avatar
Damien committed
75

76
77
78
// CommitInformation
$app->get('/commitInformation', \SrcCore\controllers\AuthenticationController::class . ':getGitCommitInformation');

79
80
81
82
83
84
//Connectors
$app->post('/connectors', \ExternalSignatoryBook\controllers\ExternalSignatoryBookController::class . ':create');
$app->get('/connectors', \ExternalSignatoryBook\controllers\ExternalSignatoryBookController::class . ':get');
$app->get('/connectors/{id}', \ExternalSignatoryBook\controllers\ExternalSignatoryBookController::class . ':getById');
$app->delete('/connectors/{id}', \ExternalSignatoryBook\controllers\ExternalSignatoryBookController::class . ':delete');
$app->put('/connectors/{id}', \ExternalSignatoryBook\controllers\ExternalSignatoryBookController::class . ':update');
85
$app->get('/connectors/{id}/currentVisa', \ExternalSignatoryBook\controllers\ExternalSignatoryBookController::class . ':getCurrentVisa');
86

87
88
//Customization
$app->put('/customization', \Configuration\controllers\ConfigurationController::class . ':updateCustomization');
89
$app->get('/customization/watermark', \Configuration\controllers\ConfigurationController::class . ':getWatermarkConfiguration');
90

Damien's avatar
Damien committed
91
//Documents
Damien's avatar
Damien committed
92
$app->post('/documents', \Document\controllers\DocumentController::class . ':create');
Damien's avatar
Damien committed
93
$app->get('/documents', \Document\controllers\DocumentController::class . ':get');
94
$app->get('/documents/{id}', \Document\controllers\DocumentController::class . ':getById');
95
$app->get('/documents/{id}/content', \Document\controllers\DocumentController::class . ':getContent');
96
$app->get('/documents/{id}/proof', \History\controllers\HistoryController::class . ':getHistoryProofByDocumentId');
Damien's avatar
Damien committed
97
$app->get('/documents/{id}/history', \History\controllers\HistoryController::class . ':getByDocumentId');
Damien's avatar
Damien committed
98
$app->put('/documents/{id}/actions/{actionId}', \Document\controllers\DocumentController::class . ':setAction');
99
$app->get('/documents/{id}/workflow', \Workflow\controllers\WorkflowController::class . ':getByDocumentId');
100
$app->get('/documents/{id}/workflows/{workflowId}/files/{fileId}', \Workflow\controllers\YousignController::class . ':getByFileId');
101
$app->get('/documents/{id}/linkedMailing', \Document\controllers\DocumentController::class . ':getLinkedMailing');
102
$app->get('/documents/{id}/thumbnails/{page}', \Document\controllers\DocumentController::class . ':getThumbnailContent');
103
$app->put('/documents/{id}/workflows/interrupt', \Workflow\controllers\WorkflowController::class . ':interrupt');
Damien's avatar
Damien committed
104

105
106
107
//Emails
$app->post('/emails', \Email\controllers\EmailController::class . ':send');

108
109
110
111
112
//Groups
$app->post('/groups', \Group\controllers\GroupController::class . ':create');
$app->get('/groups', \Group\controllers\GroupController::class . ':get');
$app->get('/groups/{id}', \Group\controllers\GroupController::class . ':getById');
$app->delete('/groups/{id}', \Group\controllers\GroupController::class . ':delete');
113
$app->put('/groups/{id}', \Group\controllers\GroupController::class . ':update');
114
$app->put('/groups/{id}/privilege/{privilegeId}', \Group\controllers\GroupController::class . ':updateGroupPrivilege');
115
$app->get('/groups/{id}/privilege/{privilegeId}', \Group\controllers\GroupController::class . ':getGroupPrivilege');
116
117
$app->put('/groups/{id}/users', \Group\controllers\GroupController::class . ':addUser');
$app->delete('/groups/{id}/users/{userId}', \Group\controllers\GroupController::class . ':removeUser');
118

Damien's avatar
Damien committed
119
120
121
122
123
124
125
126
127
128
129
130
131
//History
$app->post('/history', \History\controllers\HistoryController::class . ':get');
$app->get('/history/messageTypes', \History\controllers\HistoryController::class . ':getMessageTypes');

//Languages
$app->get('/languages', \SrcCore\controllers\LanguageController::class . ':getAvailableCoreLanguages');
$app->get('/languages/{lang}', \SrcCore\controllers\LanguageController::class . ':getByLang');
$app->put('/languages', \SrcCore\controllers\LanguageController::class . ':generateLang');

//PasswordRules
$app->get('/passwordRules', \SrcCore\controllers\PasswordController::class . ':get');
$app->put('/passwordRules', \SrcCore\controllers\PasswordController::class . ':updateRules');

Damien's avatar
Damien committed
132
//Users
Florian Azizian's avatar
Florian Azizian committed
133
$app->post('/users', \User\controllers\UserController::class . ':create');
Damien's avatar
Damien committed
134
$app->get('/users', \User\controllers\UserController::class . ':get');
135
$app->get('/users/{id}', \User\controllers\UserController::class . ':getById');
Damien's avatar
Damien committed
136
$app->put('/users/{id}', \User\controllers\UserController::class . ':update');
Damien's avatar
Damien committed
137
$app->delete('/users/{id}', \User\controllers\UserController::class . ':delete');
Damien's avatar
Damien committed
138
$app->get('/users/{id}/picture', \User\controllers\UserController::class . ':getPictureById');
139
$app->put('/users/{id}/picture', \User\controllers\UserController::class . ':updatePicture');
Damien's avatar
Damien committed
140
$app->get('/users/{id}/substitute', \User\controllers\UserController::class . ':getSubstituteById');
141
$app->put('/users/{id}/preferences', \User\controllers\UserController::class . ':updatePreferences');
142
$app->put('/users/{id}/substitute', \User\controllers\UserController::class . ':updateSubstitute');
Damien's avatar
Damien committed
143
$app->put('/users/{id}/password', \User\controllers\UserController::class . ':updatePassword');
Damien's avatar
Damien committed
144
$app->get('/users/{id}/history', \History\controllers\HistoryController::class . ':getByUserId');
Damien's avatar
Damien committed
145
146
$app->post('/password', \User\controllers\UserController::class . ':forgotPassword');
$app->put('/password', \User\controllers\UserController::class . ':updateForgottenPassword');
147
$app->put('/users/{id}/accountActivationNotification', \User\controllers\UserController::class . ':sendAccountActivationNotification');
Damien's avatar
Damien committed
148

149
//Search
150
$app->post('/search/documents', \Search\controllers\SearchController::class . ':getDocuments');
151

Damien's avatar
Damien committed
152
153
154
155
156
//Signatures
$app->get('/users/{id}/signatures', \User\controllers\SignatureController::class . ':get');
$app->post('/users/{id}/signatures', \User\controllers\SignatureController::class . ':create');
$app->delete('/users/{id}/signatures/{signatureId}', \User\controllers\SignatureController::class . ':delete');
$app->put('/users/{id}/externalSignatures', \User\controllers\SignatureController::class . ':updateExternalSignatures');
157
$app->patch('/users/{id}/signatures/{signatureId}/substituted', \User\controllers\SignatureController::class . ':updateSubstituted');
158
$app->get('/signatureModes', \User\controllers\SignatureController::class . ':getSignatureModes');
Damien's avatar
Damien committed
159

160
161
162
163
164
//WorkflowTemplates
$app->post('/workflowTemplates', \Workflow\controllers\WorkflowTemplateController::class . ':create');
$app->get('/workflowTemplates', \Workflow\controllers\WorkflowTemplateController::class . ':get');
$app->get('/workflowTemplates/{id}', \Workflow\controllers\WorkflowTemplateController::class . ':getById');
$app->delete('/workflowTemplates/{id}', \Workflow\controllers\WorkflowTemplateController::class . ':delete');
165

166
//NotificationsSchedule
167
168
169
170
171
172
173
174
$app->post('/schedule/initialization', \Notification\controllers\NotificationsScheduleController::class . ':initializeSchedulerScript');
$app->get('/schedule/initialization', \Notification\controllers\NotificationsScheduleController::class . ':checkSchedulerScriptInitialized');
$app->delete('/schedule', \Notification\controllers\NotificationsScheduleController::class . ':deleteSchedulerScript');
$app->post('/schedule', \Notification\controllers\NotificationsScheduleController::class . ':create');
$app->get('/schedule', \Notification\controllers\NotificationsScheduleController::class . ':get');
$app->get('/schedule/{id}', \Notification\controllers\NotificationsScheduleController::class . ':getById');
$app->put('/schedule/{id}', \Notification\controllers\NotificationsScheduleController::class . ':update');
$app->delete('/schedule/{id}', \Notification\controllers\NotificationsScheduleController::class . ':delete');
175

Florian Azizian's avatar
Florian Azizian committed
176
$app->run();