def invite_applicant(applicant_user_id, current_user=current_user): if not is_senior_recruiter(current_user): raise ForbiddenException( 'User {} cannot invite applicants.'.format(current_user.id)) else: application = Application.get_submitted_for_user(applicant_user_id) if application is None: raise BadRequestException( 'User {} is not in an open application.'.format( applicant_user_id ) ) elif not application.is_accepted: raise BadRequestException( 'User {} application is not accepted.'.format( applicant_user_id ) ) elif application.is_invited: raise BadRequestException( 'User {} application is already invited.'.format( applicant_user_id ) ) else: send_mail(applicant_user_id, 'invite') application.is_invited = True db.session.commit() add_status_note( application, 'Application invited by {}.'.format(current_user.name))
def add_applicant_note(applicant_user_id, text, title=None, is_chat_log=False, current_user=None): application = Application.get_submitted_for_user(applicant_user_id) if application is None: raise BadRequestException('User {} is not an applicant'.format( User.get(applicant_user_id).name)) else: if not is_recruiter(current_user): raise ForbiddenException('Current user is not a recruiter') elif (application.recruiter_id != current_user.id and not is_senior_recruiter(current_user)): raise ForbiddenException( 'Current recruiter has not claimed applicant {}'.format( applicant_user_id)) note = Note( text=text, title=title, application_id=application.id, is_chat_log=is_chat_log, author_id=current_user.id, ) db.session.add(note) db.session.commit() return {'status': 'ok'}
def get_user_roles(current_user=None): res = { 'info': { 'is_admin': is_admin(current_user), 'is_recruiter': is_recruiter(current_user), 'is_senior_recruiter': is_senior_recruiter(current_user), 'user_id': current_user.id, } } return res
def get_applicant_list(current_user=None): if not (is_recruiter(current_user) or is_admin(current_user)): raise ForbiddenException('User must be recruiter or admin.') result = {} for user in User.query.join( Application, Application.user_id == User.id).filter( db.and_( Application.is_submitted, db.or_( db.not_(Application.is_concluded), db.and_(Application.is_accepted, db.not_(Application.is_invited))))): recruiter_name = None application = Application.query.filter_by( user_id=user.id, is_concluded=False).one_or_none() if application is None: application = Application.query.filter_by( user_id=user.id, is_accepted=True, is_invited=False).one_or_none() application_status = 'new' if application: recruiter_id = application.recruiter_id if recruiter_id: recruiter = User.get(recruiter_id) recruiter_name = recruiter.name application_status = 'claimed' if application.is_accepted: application_status = 'accepted' applicant_visible = False # senior recruiters see all if is_senior_recruiter(current_user) or is_admin(current_user): applicant_visible = True elif is_recruiter(current_user): if application and application.recruiter_id == current_user.id: applicant_visible = True else: applicant_visible = application_status == 'new' if applicant_visible: result[user.id] = { 'user_id': user.id, 'recruiter_id': application.recruiter_id if application else None, 'recruiter_name': recruiter_name, 'status': application_status, 'name': user.name, } return {'info': result}
def start_application(current_user=None): if is_admin(current_user) or is_recruiter(current_user) or is_senior_recruiter(current_user): raise BadRequestException('Recruiters cannot apply') character = Character.get(current_user.id) if character.blocked_from_applying: raise ForbiddenException('User is blocked') application = Application.get_for_user(current_user.id) if application: raise BadRequestException('An application is already open') # no application, start one application = Application(user_id=current_user.id, is_concluded=False) db.session.add(application) db.session.commit() add_status_note(application, 'Application created.') return {'status': 'ok'}
def application_history(applicant_id, current_user=None): user = User.get(applicant_id) if not (is_senior_recruiter(current_user) or is_admin(current_user)): user_application_access_check(current_user, user) applications = {} for application in user.applications: app_dict = {} app_dict['recruiter_id'] = application.recruiter_id if application.recruiter_id is None: app_dict['recruiter_name'] = None else: app_dict['recruiter_name'] = User.get( application.recruiter_id).name app_dict['status'] = get_application_status(application) app_dict['notes'] = get_application_note_data(application, current_user) applications[application.id] = app_dict return {'info': applications}
def unaccept_applicant(applicant_user_id, current_user=current_user): if not is_senior_recruiter(current_user): raise ForbiddenException( 'User {} is not a senior recruiter'.format(current_user.id)) application = Application.get_submitted_for_user(applicant_user_id) if application is None: raise BadRequestException( 'User {} is not in an open application.'.format( applicant_user_id )) elif not application.is_accepted: raise ForbiddenException( 'User {} cant unaccept app from user {} as its not accepted'.format( current_user.id, applicant_user_id )) else: add_status_note( application, 'Application un-accepted by {}.'.format(current_user.name)) application.is_accepted = False application.is_concluded = False db.session.commit() return {'status': 'ok'}
def test_is_senior_recruiter(self): self.assertFalse(is_senior_recruiter(self.user))