@@ -40,39 +40,41 @@ suspend fun doAuth(
4040 return HttpStatusCode .Unauthorized
4141 }
4242
43- val user = suspendTransaction {
44- UsersTable
43+ val status = suspendTransaction {
44+ val user = UsersTable
4545 .selectAll()
4646 .where { (UsersTable .username eq session.name) and (UsersTable .uniqueId eq session.id) }
4747 .firstOrNull()
48- }
4948
50- if (user == null ) {
51- unauthorized()
52- return HttpStatusCode .Unauthorized
53- }
49+ if (user == null ) {
50+ return @suspendTransaction HttpStatusCode .Unauthorized
51+ }
5452
55- if (user[UsersTable .admin]) {
56- success()
57- return HttpStatusCode .OK
58- }
53+ if (user[UsersTable .admin]) {
54+ return @suspendTransaction HttpStatusCode .OK
55+ }
5956
60- val permission: ResultRow =
61- try {
57+ val permission: ResultRow = try {
6258 UserPermissionsTable
6359 .selectAll()
6460 .where { (UserPermissionsTable .userId eq user[UsersTable .id]) and (UserPermissionsTable .permissionName eq permission) }
6561 .first()
6662 } catch (_: NoSuchElementException ) {
67- forbidden()
68- return HttpStatusCode .Forbidden
63+ return @suspendTransaction HttpStatusCode .Forbidden
6964 }
7065
71- if (permission[UserPermissionsTable .permissionState]) {
72- success()
73- return HttpStatusCode .OK
74- } else {
75- forbidden()
76- return HttpStatusCode .Forbidden
66+ if (permission[UserPermissionsTable .permissionState]) {
67+ return @suspendTransaction HttpStatusCode .OK
68+ } else {
69+ return @suspendTransaction HttpStatusCode .Forbidden
70+ }
7771 }
72+
73+ when (status) {
74+ HttpStatusCode .Unauthorized -> unauthorized()
75+ HttpStatusCode .Forbidden -> forbidden()
76+ HttpStatusCode .OK -> success()
77+ }
78+
79+ return status
7880}
0 commit comments