Skip to content

Commit

Permalink
Finish offer and begin internship
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisP committed Feb 24, 2010
1 parent b7a3118 commit fec255f
Show file tree
Hide file tree
Showing 15 changed files with 496 additions and 116 deletions.
4 changes: 2 additions & 2 deletions fixtures/internships.groovy
Expand Up @@ -9,6 +9,6 @@ include "companies"
include "millesimes"

fixture {
firstInternship(Internship, subject: "First Internship", beginAt: new Date(), isApproval: true, student: nadirRole, academicTutor: hclRole, companyTutor: jobsRole, company: apple, report: firstInternshipReport, convocation: firstConvocation, length:6, millesime:m2009)
secondInternship(Internship, subject: "Second Internship", beginAt: new Date(), isApproval: true, student: thomasRole, academicTutor: hclRole, companyTutor: balmerRole, company: microsoft, report: secondInternshipReport, convocation: secondConvocation, length:6, millesime:m2008)
firstInternship(Internship, subject: "First Internship", beginAt: new Date(), isApproval: false, student: nadirRole, academicTutor: hclRole, companyTutor: jobsRole, company: apple, report: firstInternshipReport, convocation: firstConvocation, length:6, millesime:m2009)
secondInternship(Internship, subject: "Second Internship", beginAt: new Date(), isApproval: false, reason: "it's not a good internship", student: alexisRole, academicTutor: hclRole, companyTutor: balmerRole, company: microsoft, report: secondInternshipReport, convocation: secondConvocation, length:6, millesime:m2008)
}
2 changes: 1 addition & 1 deletion fixtures/users.groovy
Expand Up @@ -48,7 +48,7 @@ fixture {
lastName : "Maurel" ,
address : thomasAddress,
phone : "0102030405",
authorities : [thomasRole, adminRole],
authorities : [adminRole],
showEmail : true
)

Expand Down
Expand Up @@ -10,30 +10,85 @@ import me.hcl.seekin.Auth.UserController
import me.hcl.seekin.Auth.Role.External
import me.hcl.seekin.Util.Address
import me.hcl.seekin.Company
import me.hcl.seekin.Formation.Millesime
import me.hcl.seekin.Formation.Promotion
import org.hibernate.LockMode

class InternshipController {

def dateService

def authenticateService
def sessionFactory

def index = { redirect(action: "list", params: params) }

// the delete, save and update actions only accept POST requests
static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

def list = {

/* Controls if some internships which wait for Validation are validated by examinate params */
def internship
params.each {
if(it.key.contains("validate_") && it.value == "on") {
/* Get the offer and do the mofification before saving */
internship = Internship.get(it.key.split("_")[1].toInteger())
internship.isApproval = true
internship.save(flush:true)
}
}

/* If the user is not logged in, we redirect him at the index of seekin */
def status = new HashSet()
if(!authenticateService.isLoggedIn()) {
redirect(controller: "user", action: "index")
}
else {
if(authenticateService.ifAnyGranted("ROLE_ADMIN,ROLE_FORMATIONMANAGER")) {
//status.add 'internship.validated'
//status.add 'internship.unvalidated'
//status.add 'internship.waitForValidation'
Internship.list().each {
status.add it.getStatus(new Staff())
}
}
else if(authenticateService.ifAnyGranted("ROLE_STAFF")) {
def userInstance = authenticateService.userDomain()
sessionFactory.currentSession.refresh(userInstance, LockMode.NONE)
def statusStaff = userInstance.authorities.find {
it.authority == "ROLE_STAFF"
}
Internship.list().each {
if(it.getStatus(new Staff()) == 'internship.validated')
status.add it.getStatus(new Staff())
if(it.getStatus(statusStaff) == 'internship.mine')
status.add it.getStatus(statusStaff)
}
//status.add 'internship.validated'
//status.add 'internship.mine'

}
else {
Internship.list().each {
if(it.getStatus(new Staff()) == 'internship.validated')
status.add 'internship.validated'
}
}

render(view: "list", model: [status: status])
}
}

def create = {
def staff = Staff.list().collect {
[
id: it.id,
value: it.user.firstName + " " + it.user.lastName
value: it.user?.firstName + " " + it.user?.lastName
]
}
def student = Student.list().collect {
[
id: it.id,
value: it.user.firstName + " " + it.user.lastName
value: it.user?.firstName + " " + it.user?.lastName
]
}
def offer = Offer.list().collect {
Expand All @@ -52,6 +107,7 @@ class InternshipController {
internshipInstance.length = offerFromSelection.length
internshipInstance.company = offerFromSelection.company
internshipInstance.fromOffer = true
internshipInstance.description = offerFromSelection.description
}
else {
internshipInstance = new Internship()
Expand Down Expand Up @@ -97,6 +153,16 @@ class InternshipController {

internshipInstance.properties = params
internshipInstance.company = company
internshipInstance.millesime = Millesime.getCurrent()
if(authenticateService.ifAnyGranted("ROLE_STUDENT")) {
def userInstance = authenticateService.userDomain()
sessionFactory.currentSession.refresh(userInstance, LockMode.NONE)
def statusStudent = userInstance.authorities.find {
it.authority == "ROLE_STUDENT"
}
internshipInstance.student = statusStudent
internshipInstance.isApproval = false
}
if (!internshipInstance.hasErrors() && internshipInstance.save()) {
flash.message = "internship.created"
flash.args = [internshipInstance.id]
Expand All @@ -117,7 +183,7 @@ class InternshipController {
redirect(action: "list")
}
else {
return [internshipInstance: internshipInstance, beginAt: dateService.formatDate(request, internshipInstance.beginAt), convocation: dateService.formatDate(request, internshipInstance?.convocation?.date)]
return [internshipInstance: internshipInstance]
}
}

Expand All @@ -130,7 +196,7 @@ class InternshipController {
redirect(action: "list")
}
else {
return [internshipInstance: internshipInstance, convocation: dateService.formatDate(request, internshipInstance?.convocation?.date)]
return [internshipInstance: internshipInstance]
}
}

Expand Down Expand Up @@ -191,9 +257,57 @@ class InternshipController {
}

def dataTableDataAsJSON = {
def list = Internship.list(params)
def list = []
def status = new HashMap()
def ret = []
response.setHeader("Cache-Control", "no-store")
if(authenticateService.ifAnyGranted("ROLE_ADMIN,ROLE_FORMATIONMANAGER")) {
Internship.list().each() {
it.each() { it2 ->
if(it2.getStatus(new Staff()) == params.status) {
list.add it2
}
}
}
}
if(authenticateService.ifAnyGranted("ROLE_STUDENT")) {
def userInstance = authenticateService.userDomain()
sessionFactory.currentSession.refresh(userInstance, LockMode.NONE)
Internship.list().each() {
it.each() { it2 ->
if(it2.getStatus(new Staff()) == params.status && it2.student.user == userInstance) {
list.add it2
}
}
}
}
if(authenticateService.ifAnyGranted("ROLE_EXTERNAL")) {
def userInstance = authenticateService.userDomain()
sessionFactory.currentSession.refresh(userInstance, LockMode.NONE)
Internship.list().each() {
it.each() { it2 ->
if(it2.getStatus(new Staff()) == params.status && it2.companyTutor.user == userInstance) {
list.add it2
}
}
}
}
if(authenticateService.ifAnyGranted("ROLE_STAFF")) {
def userInstance = authenticateService.userDomain()
sessionFactory.currentSession.refresh(userInstance, LockMode.NONE)
def statusStaff = userInstance.authorities.find {
it.authority == "ROLE_STAFF"
}
println statusStaff
Internship.list().each() {
it.each() { it2 ->
if(it2.getStatus(statusStaff) == params.status && (it2.companyTutor.user == userInstance || it2.isApproval == true)) {
println params
list.add it2
}
}
}
}

list.each {
ret << [
Expand All @@ -209,7 +323,7 @@ class InternshipController {
}

def data = [
totalRecords: Internship.count(),
totalRecords: list.size(),
results: ret
]

Expand Down

0 comments on commit fec255f

Please sign in to comment.