             requests.remove
             utils.unlockRequest
         ]
-    'request/:type/:req_name/destroy/': put: [
-        utils.checkPermissionsByType
-        requests.removeResults
-    ]
+    'request/:type/:req_name/destroy/':
+        put: [
+            utils.checkPermissionsByType
+            requests.removeResults
+        ]
+
 
     # Tags API
-    'tags': get: requests.tags
+    'tags':
+        get: [
+            requests.tags
+        ]
+
 
     # Doctypes API
-    'doctypes': get: requests.doctypes
+    'doctypes':
+        get: [
+            requests.doctypes
+        ]
+
 
     # File management
     # attachment API is deprecated
-    'data/:id/attachments/': post: [
-        utils.lockRequest
-        utils.getDoc
-        utils.checkPermissionsByDoc
-        attachments.add
-        utils.unlockRequest
-    ]
+    'data/:id/attachments/':
+        post: [
+            utils.lockRequest
+            utils.getDoc
+            utils.checkPermissionsByDoc
+            attachments.add
+            utils.unlockRequest
+        ]
     'data/:id/attachments/:name':
-        get: [utils.getDoc, utils.checkPermissionsByDoc, attachments.get]
+        get: [
+            utils.getDoc
+            utils.checkPermissionsByDoc
+            attachments.get
+        ]
         delete: [
             utils.lockRequest
             utils.getDoc

requests = require './requests'
attachments = require './attachments'
binaries = require './binaries'
connectors = require './connectors'
indexer = require './indexer'
mails = require './mails'
user = require './user'
account = require './accounts'
access = require './access'
replication = require './replication'

utils = require '../middlewares/utils'

module.exports =

    # Information page
    '':  get: data.index

    # Data management
    'data/': post: [
            utils.checkPermissionsByBody
            data.encryptPassword
            data.create
        ]
    'data/:id/':
        get: [

            utils.unlockRequest
        ]


    # Access management
    'access/':
        post: [
            utils.checkPermissionsFactory 'access'
            access.create
        ]
    'access/:id/':
        put: [
            utils.checkPermissionsFactory 'access'
            access.update
        ]
        delete: [
            utils.checkPermissionsFactory 'access'
            utils.lockRequest
            utils.getDoc
            access.remove
            utils.unlockRequest
        ]


    # Filter Management
    'filters/:id':
        get: [
            filters.checkDevice
            utils.getDoc
            data.find
        ]
        post: [
            filters.checkDevice
            filters.fixBody
            data.create
        ]
        put: [
            filters.checkDevice
            filters.fixBody
            utils.lockRequest
            data.upsert
            utils.unlockRequest
        ]
        delete: [
            filters.checkDevice
            utils.lockRequest
            utils.getDoc
            data.delete
            utils.unlockRequest
        ]


    # Get attachment in a replication
    # Remove route as replication/_local/:id
    'replication/:id([^_]*)/:name*':
        get: [
            utils.getDoc
            utils.checkPermissionsByDoc
            replication.proxy
        ]
    'replication/*':
        post: [
            utils.checkPermissionsPostReplication
            replication.proxy
        ]
        get: [
            replication.proxy
            # Permissions manage in request
        ]
        put:[
            utils.checkPermissionsPutReplication
            replication.proxy
        ]


    # Indexer management
    'data/index/clear-all/':
        delete: [
            utils.checkPermissionsFactory 'all'
            indexer.removeAll
        ]
    'data/index/status':
        get: [
            indexer.indexingStatus
        ]
    'data/index/define/:type':
        post: [
            utils.checkPermissionsByType
            indexer.defineIndex
        ]
    'data/index/:id':
        post: [
            indexer.index
        ]
        delete: [
            indexer.remove
        ]
    'data/search/:type':
        post: [
            utils.checkPermissionsByType
            indexer.search
        ]


    # Mail management
    'mail/':
        post: [
            utils.checkPermissionsFactory 'send mail'
            mails.send
        ]
    'mail/to-user':
        post: [
            utils.checkPermissionsFactory 'send mail to user'
            mails.sendToUser
        ]
    'mail/from-user':
        post: [
            utils.checkPermissionsFactory 'send mail from user'
            mails.sendFromUser
        ]


    # User management
    'user/':
        post: [
            utils.checkPermissionsFactory 'User'
            user.create
        ]
    'user/merge/:id':
        put: [
            utils.lockRequest
            utils.checkPermissionsFactory('User')
            utils.getDoc
            user.merge
            utils.unlockRequest
        ]


    # Account management
    'accounts/password/':
        post: [
            account.checkPermissions
            account.initializeKeys
        ]
        put: [
            account.checkPermissions
            account.updateKeys
        ]
    'accounts/reset/':
        delete: [
            account.checkPermissions
            account.resetKeys
        ]


    # Sharing management
    'services/sharing/':
        post: [
            utils.checkPermissionsFactory 'sharing'
            sharing.create
            sharing.sendSharingRequests
        ]
    'services/sharing/:id':
        delete: [
            utils.checkPermissionsFactory 'sharing'
            sharing.delete
            sharing.stopReplications
            sharing.sendDeleteNotifications
        ]
    'services/sharing/sendAnswer':
        post: [
            utils.checkPermissionsFactory 'sharing'
            sharing.handleRecipientAnswer
            sharing.sendAnswer
        ]
    'services/sharing/answer':
        post: [
            utils.checkPermissionsFactory 'sharing'
            sharing.validateTarget
            sharing.replicate
        ]

