             controller: 'ScanSingleObjectCtrl as scanSingleObject'
             params:
                 scanInputValue: ''
+            onEnter: permissionDeniedCheck
 
         .state  'listPersons',
             url: '/list/persons'

            url: '/import'
            templateUrl: 'static/templates/import.html'
            controller: 'ImportCtrl as import'

        .state  'database',
            url: '/database'
            templateUrl: 'static/templates/database.html'
            controller: 'DatabaseCtrl as database'

        return
]

        # For any unmatched url, redirect to /
        $urlRouterProvider.otherwise '/'

        permissionDeniedCheck = [
            '$state'
            '$rootScope'
            ($state, $rootScope) ->
                if not $rootScope.config.writePermissionGranted
                    alert 'Permission denied'
                    $state.go 'home'
                return
        ]

        # Set up the states
        $stateProvider
        .state 'home',
