/
ErrorController.groovy
60 lines (47 loc) · 1.06 KB
/
ErrorController.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* NotFoundController Controler
*
* Description of my controller
*
* @author Jeroen Wesbeek <work@osx.eu>
* @since 20120816
*/
package generic
import dbnp.studycapturing.Study
import dbnp.authentication.SecUser
class ErrorController {
def authenticationService
/**
* 404 closure
*/
def notFound = {
// substract shortCode from original request uri
def shortCode = request.forwardURI.replace("${request.contextPath}/", "")
if ( shortCode ) {
def study = Study.findByCode(shortCode)
if ( study ) {
def studyId
if ( study.publicstudy ) {
studyId = study.id
}
else {
SecUser user = authenticationService.getLoggedInUser()
if ( user ) {
// User will see study or get 'unauthorized' message
studyId = study.id
}
else {
// User will be asked to sign in
redirect(controller: "home", action: "gotoStudy", id: study.id )
return
}
}
if ( studyId ) {
redirect(controller: "study", action: "show", id: studyId)
return
}
}
}
render(template: "404")
}
}