-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added checkbox to registration form for University Supervisor
- new Domain class RoleRequest - RoleRequest is created when registrating, but is enabled after confirming account. - Added new notifications when creating, approving or declining RoleRequest - RoleRequests can be found under Members tab - Members tab now has 2 tabs inside, Members and RoleRequests - Only Admin can approve, decline RoleRequest
- Loading branch information
Showing
21 changed files
with
704 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,13 +82,17 @@ class BootStrap { | |
enabled: true, | ||
roles: [Role.STUDENT] | ||
).save(flush: true) | ||
new RoleRequest(applicant: example2, status: AppStatus.PENDING, enabled: true).save(flush: true) | ||
|
||
def example3 = new User( | ||
email: '[email protected]', | ||
fullName: 'Example Tri', | ||
password: "example3", | ||
enabled: true, | ||
roles: [Role.STUDENT] | ||
).save(flush: true) | ||
new RoleRequest(applicant: example3, status: AppStatus.PENDING, enabled: true).save(flush: true) | ||
|
||
def supervisor1 = new User( | ||
email: '[email protected]', | ||
fullName: 'Supervisor Jedna', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
grails-app/controllers/com/redhat/theses/RoleRequestController.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package com.redhat.theses | ||
|
||
import com.redhat.theses.auth.User | ||
import com.redhat.theses.auth.Role | ||
import com.redhat.theses.events.RoleRequestEvent | ||
import grails.plugins.springsecurity.Secured | ||
import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils | ||
|
||
class RoleRequestController { | ||
|
||
/** | ||
* Dependency injection of com.redhat.theses.FilterService | ||
*/ | ||
def filterService | ||
|
||
/** | ||
* Dependency injection of grails.plugins.springsecurity.SpringSecurityService | ||
*/ | ||
def springSecurityService | ||
|
||
static defaultAction = "list" | ||
|
||
@Secured(['ROLE_ADMIN']) | ||
def list() { | ||
if (!params.filter) { | ||
params.filter = [:] | ||
} | ||
if (!params?.filtering) { | ||
params.filter << [status: AppStatus.PENDING] | ||
} | ||
else { | ||
params.type = [applicant: [fullName: "ilike"]] | ||
} | ||
params.filter << [enabled: true] | ||
|
||
def requestInstanceList = filterService.filter(params, RoleRequest) | ||
def requestInstanceTotal = filterService.count(params, RoleRequest) | ||
|
||
[requestInstanceList: requestInstanceList, requestInstanceTotal: requestInstanceTotal] | ||
} | ||
|
||
def show(Integer id) { | ||
def requestInstance = RoleRequest.get(id) | ||
|
||
if (!requestInstance) { | ||
flash.message = message(code: 'request.not.found', args: [id]) | ||
redirect(action: "list") | ||
return | ||
} | ||
|
||
def user = springSecurityService.currentUser | ||
|
||
if (!SpringSecurityUtils.ifAnyGranted('ROLE_ADMIN') && user != requestInstance.applicant) { | ||
flash.message = message(code: 'security.denied.message') | ||
redirect(action: 'list') | ||
return | ||
} | ||
|
||
def canManage = SpringSecurityUtils.ifAnyGranted('ROLE_ADMIN') | ||
|
||
[requestInstance: requestInstance, canManage: canManage] | ||
} | ||
|
||
@Secured('ROLE_ADMIN') | ||
def decline(Long id) { | ||
def requestInstance = RoleRequest.get(id) | ||
if (!requestInstance) { | ||
flash.message = message(code: 'request.not.found', args: [id]) | ||
redirect(action: 'list') | ||
return | ||
} | ||
|
||
User user = springSecurityService.currentUser | ||
|
||
if (!SpringSecurityUtils.ifAnyGranted('ROLE_ADMIN')) { | ||
|
||
flash.message = message(code: 'security.denied.message') | ||
redirect(action: 'list') | ||
return | ||
} | ||
|
||
requestInstance.status = AppStatus.DECLINED | ||
|
||
if (!requestInstance.save()) { | ||
flash.message = message(code: 'request.save.error') | ||
redirect(uri:'/') | ||
return | ||
} | ||
|
||
event("RoleRequestDeclined", new RoleRequestEvent(requestInstance, user)) | ||
flash.message = message(code: 'request.declined', args: [id]) | ||
redirect(action: 'list') | ||
} | ||
|
||
@Secured('ROLE_ADMIN') | ||
def approve(Long id) { | ||
def requestInstance = RoleRequest.get(id) | ||
if (!requestInstance) { | ||
flash.message = message(code: 'request.not.found', args: [id]) | ||
redirect(action: 'list') | ||
return | ||
} | ||
|
||
User user = springSecurityService.currentUser | ||
|
||
if (!SpringSecurityUtils.ifAnyGranted('ROLE_ADMIN')) { | ||
|
||
flash.message = message(code: 'security.denied.message') | ||
redirect(action: 'list') | ||
return | ||
} | ||
|
||
requestInstance.status = AppStatus.APPROVED | ||
|
||
requestInstance.applicant.roles.add(Role.SUPERVISOR) | ||
|
||
if (!requestInstance.save() || !requestInstance.applicant.save()) { | ||
flash.message = message(code: 'request.save.error') | ||
redirect(uri:'/') | ||
return | ||
} | ||
|
||
event("RoleRequestApproved", new RoleRequestEvent(requestInstance, user)) | ||
flash.message = message(code: 'request.approved', args: [id]) | ||
redirect(action: 'list') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.redhat.theses; | ||
|
||
import com.redhat.theses.auth.User | ||
|
||
class RoleRequest { | ||
|
||
User applicant | ||
AppStatus status | ||
boolean enabled | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
databaseChangeLog = { | ||
|
||
changeSet(author: "phala (generated)", id: "1472640506724-1") { | ||
createTable(tableName: "role_request") { | ||
column(name: "id", type: "int8") { | ||
constraints(nullable: "false", primaryKey: "true", primaryKeyName: "role_requestPK") | ||
} | ||
|
||
column(name: "version", type: "int8") { | ||
constraints(nullable: "false") | ||
} | ||
|
||
column(name: "applicant_id", type: "int8") { | ||
constraints(nullable: "false") | ||
} | ||
|
||
column(name: "enabled", type: "bool") { | ||
constraints(nullable: "false") | ||
} | ||
|
||
column(name: "status", type: "varchar(255)") { | ||
constraints(nullable: "false") | ||
} | ||
} | ||
} | ||
|
||
changeSet(author: "phala (generated)", id: "1472640506724-3") { | ||
dropIndex(indexName: "unique_applicant_id", tableName: "application") | ||
} | ||
|
||
changeSet(author: "phala (generated)", id: "1472640506724-2") { | ||
addForeignKeyConstraint(baseColumnNames: "applicant_id", baseTableName: "role_request", constraintName: "FK581F43C67E712562", deferrable: "false", initiallyDeferred: "false", referencedColumnNames: "id", referencedTableName: "user", referencesUniqueColumn: "false") | ||
} | ||
} |
Oops, something went wrong.