def post(self, grantable, args): email = args['email'] name = args['name'] role = args['role'] dept = grantable.department uu = UnverifiedUser(email=email, name=name, role=role, department=dept) try: uu.save() except: resp = {'success' : False, 'message' : 'failed to create UnverifiedUser'} return bcap.bcapResponse(resp) create_belay = bcap.Capability(settings.BELAY_CREATE) response = create_belay.post(bcap.dataPreProcess({'email': args['email']})) logger.error('Successfully got response for account creation: %s' % response) create_cap = response['create'] ub = UnverifiedBelayAccount(uu=uu, create=create_cap.serialize()) ub.save() if role == 'admin': create_cap = bcap.grant('get-admin-email-and-create', uu) elif role == 'reviewer': create_cap = bcap.grant('get-reviewer-email-and-create', uu) else: return logWith404(logger, 'UnverifiedUserAddRevHandler: role type not allowed: %s' % role) activate_url = '%s/new-account/#%s' % \ (bcap.this_server_url_prefix(), create_cap.serialize()) return_url = bcap.this_server_url_prefix() emailstr = u"""Dear %s, A new Resume account is being created for you. To activate it, visit: %s To regain access your account once it has been created, visit: %s """ emailstr = emailstr % (name, activate_url, return_url) fromaddr = fromAddr(dept) emailResponse = sendLogEmail('[Resume] New Account', emailstr, email, fromaddr) if emailResponse: return emailResponse resp = {\ 'success' : True,\ 'email' : email,\ 'name' : name,\ 'role' : role,\ } return bcap.bcapResponse(resp)
def post(self, grantable, args): refs = grantable.department.findRefs(args['email']) for r in refs: ref = r['reference'] submitcap = bcap.regrant('launch-reference', ref) submitlink = '%s/submit-reference/#%s' % (bcap.this_server_url_prefix(), submitcap.serialize()) r['submitlink'] = submitlink del r['reference'] launchCap = bcap.regrant('stash-applicant', ref.applicant) launchurl = '%s/applicant/#%s' % \ (bcap.this_server_url_prefix(), launchCap.serialize()) r['launch'] = launchurl return bcap.bcapResponse(refs)
def post(self, granted, args): unverified_user = granted.unverifieduser if granted is None: return HttpResponseNotFound() auth_info = AuthInfo( email=unverified_user.email, \ name=unverified_user.name, \ role='reviewer', \ department=unverified_user.department) auth_info.save() reviewer = Reviewer(auth=auth_info, department=unverified_user.department) reviewer.save() # Remove the unverified_user---this is a one-shot request unverified_user.delete() # This is the capability to put in launch_info launch = bcap.grant('launch-reviewer', reviewer) return bcap.bcapResponse({ 'public_data': 'Reviewer account for %s' % auth_info.name, 'private_data': launch, 'domain': bcap.this_server_url_prefix(), 'url': '/review' })
def post(self, granted, args): if granted is None: return HttpResponseNotFound() ua = granted.unverifiedapplicant auth_info = AuthInfo( email=ua.email, \ # TODO(matt): fix or remove name from AuthInfo? name='',\ role='applicant', \ department=ua.department) auth_info.save() applicant = Applicant(\ auth = auth_info,\ firstname='',\ lastname='',\ country='',\ department=ua.department,\ position=ua.position\ ) applicant.save() ua.delete() launch = bcap.grant('launch-applicant', applicant) return bcap.bcapResponse({ 'public_data': 'Edit application for %s' % ua.email, 'private_data': launch, 'domain': bcap.this_server_url_prefix(), 'url': '/applicant/' })
def makeReferenceRequest(applicant, ref, launch_cap, orgname, shortname): return u"""Dear %(name)s, %(appname)s has requested that you provide a letter of reference to the %(orgname)s. To submit your letter, please visit this URL: %(servername)s/submit-reference/#%(launch_cap)s You can revisit this URL any number of times to resubmit your letter for %(appname)s. If you run into any trouble, get help here: %(servername)s/contact/%(shortname)s Thanks! %(orgname)s """ % { 'appname' : applicant.fullname(), 'name' : ref.name, 'launch_cap' : launch_cap.serialize(), 'servername' : bcap.this_server_url_prefix(), 'orgname' : orgname, 'shortname' : shortname }
def post(self, grantable, args): reviewer = grantable.reviewer applicant_json = [] for applicant in reviewer.getApplicants(): pairs = applicant.getPairsOfReviewer(reviewer) if len(pairs) > 0: pair = pairs[0] else: pair = AppRevPair(applicant=applicant, reviewer=reviewer) pair.save() a_json = applicant.cached_json() launchCap = bcap.cachegrant('launch-app-review', pair) a_json['launchURL'] = '%s/appreview/#%s' % \ (bcap.this_server_url_prefix(), launchCap.serialize()) components = applicant.get_component_objects() component_caps = dict(\ [(c.type.id, bcap.cachegrant('get-statement', c))\ for c in components if c.type.type == 'statement']) a_json['components'] = component_caps references = applicant.getReferencesModel() refjson = [] for r in references: rjson = r.to_json() rjson['getLetter'] = bcap.cachegrant('get-letter', r) refjson.append(rjson) a_json['refletters'] = refjson applicant_json.append(a_json) a_json['getCombined'] = bcap.cachegrant('get-combined', applicant) if reviewer.auth.role == 'head-reviewer': a_json['reject'] = bcap.cachegrant('reject-applicant', applicant) return bcap.bcapResponse({ 'changed': True, 'lastChange': reviewer.getLastChange(), 'value': applicant_json })
def setup(adminName): cses = Department.objects.filter(shortname='cs') if len(cses) == 0: cs = Department(name='Computer Science', shortname='cs', lastChange=0,\ headerImage='', logoImage='', resumeImage='', headerBgImage='',\ brandColor='blue', contactName='Donald Knuth', contactEmail='*****@*****.**',\ techEmail='*****@*****.**') cs.save() else: cs = cses[0] make_some_applicants(cs) unverified_user = UnverifiedUser( \ role='admin', name=adminName, email='%s@fake' % adminName, department=cs) unverified_user.save() ResumeInit().process_request(None) create_account = bcap.grant('get-admin-email-and-create', unverified_user) print("To get started, go here: %s/static/new_account.html#%s" % \ (bcap.this_server_url_prefix(), create_account.serialize()))
def get(self, granted): applicant = granted.applicant return bcap.bcapResponse({ 'public_data' : 'Applicant review page for %s' % applicant.fullname(), 'private_data' : bcap.regrant('launch-app-review', applicant), 'domain': bcap.this_server_url_prefix(), 'url' : '/appreview', })
def post(self, grantable, args): response = self.checkPostArgs(args) if response != 'OK': return response email = args['email'] name = args['name'] role = args['role'] dept = grantable.department uu = UnverifiedUser(email=email, name=name, role=role, department=dept) try: uu.save() except: resp = {'success' : False, 'message' : 'failed to create UnverifiedUser'} return bcap.bcapResponse(resp) if role == 'admin': create_cap = bcap.grant('add-admin', uu) elif role == 'reviewer': create_cap = bcap.grant('add-reviewer', uu) else: return logWith404(logger, 'UnverifiedUserAddRevHandler: role type not allowed: %s' % role) activate_url = '%s/new-account/#%s' % \ (bcap.this_server_url_prefix(), create_cap.serialize()) return_url = bcap.this_server_url_prefix() emailstr = u"""Dear %s, A new Apply account is being created for you. To activate it, visit: %s To regain access your account once it has been created, visit: %s """ emailstr = emailstr % (name, activate_url, return_url) sendLogEmail(emailstr, email) delCap = bcap.grant('unverifieduser-delete', uu) resp = {\ 'success' : True,\ 'email' : email,\ 'name' : name,\ 'role' : role,\ } return bcap.bcapResponse(resp)
def post(self, grantable, args): applicants = grantable.department.findApplicants(args['email']) apps = [] for a in applicants: a_json = {} a_json['name'] = a.fullname() launchCap = bcap.regrant('stash-applicant', a) launchurl = '%s/applicant/#%s' % \ (bcap.this_server_url_prefix(), launchCap.serialize()) a_json['launch'] = launchurl apps.append(a_json) return bcap.bcapResponse(apps)
def post(self, granted, args): posn = granted.applicantposition email = args['email'] uu = UnverifiedApplicant(email=email, department=posn.department, position=posn) try: uu.save() except Exception as e: logger.error('Error: %s' % e) resp = {'success' : False, 'message' : 'failed to create UnverifiedApplicant'} return bcap.bcapResponse(resp) create_cap = bcap.grant('get-applicant-email-and-create', uu) activate_url = '%s/new-account/#%s' % \ (bcap.this_server_url_prefix(), create_cap.serialize()) return_url = bcap.this_server_url_prefix() emailstr = u"""Dear Applicant, A new Resume account is being created for you. To activate it, visit: %s To regain access your account once it has been created, visit: %s """ emailstr = emailstr % (activate_url, return_url) # emailResponse = sendLogEmail('[Resume] New Account', emailstr, email) # if emailResponse: return emailResponse resp = {\ 'success' : True,\ 'email' : email,\ 'create_cap' : create_cap } return bcap.bcapResponse(resp)
def startDeptDefault(adminName, adminEmail, techEmail, deptname, shortname): dept = Department( name=deptname, shortname=shortname, lastChange=0, headerImage='', logoImage='', resumeImage='', headerBgImage='', contactName=adminName, contactEmail=adminEmail, techEmail=techEmail) dept.save() unverified_user = UnverifiedUser( \ role='admin', name=adminName, email=adminEmail, department=dept) unverified_user.save() ResumeInit().process_request(None) create_account = bcap.grant('get-admin-email-and-create', unverified_user) posn = ApplicantPosition(department=dept, name='Assistant Professor', shortform='AsstProf', autoemail=True) posn.save() c = ComponentType(department=dept,type='statement',name='Cover Letter',short='Cover') c.save() c = ComponentType(department=dept,type='statement',name='Curriculum Vitae',short='CV') c.save() c = ComponentType(department=dept,type='statement',name='Research Statement',short='Research') c.save() c = ComponentType(department=dept,type='statement',name='Teaching Statement',short='Teaching') c.save() c = ComponentType(department=dept,type='contactweb',name='Home Page',short='home') c.save() c = ComponentType(department=dept,type='contactweb',name='Application Web Page',short='app') c.save() c = ComponentType(department=dept,type='contactlong',name='Optional Notes',short='addtl') c.save() return "To get started, go here: %s/new-account/#%s" % \ (bcap.this_server_url_prefix(), create_account.serialize())
def newAdmin(deptshortname, adminName, adminEmail): depts = Department.objects.filter(shortname=deptshortname) if len(depts) == 1: dept = depts[0] else: raise Exception('Couldn\'t find department %s' % deptshortname) unverified_user = UnverifiedUser( role='admin', name=adminName, email=adminEmail, department=dept) unverified_user.save() ResumeInit().process_request(None) create_account = bcap.grant('get-admin-email-and-create', unverified_user) return "To get started, go here: %s/new-account/#%s" % \ (bcap.this_server_url_prefix(), create_account.serialize())