Beispiel #1
0
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}
Beispiel #2
0
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'}
Beispiel #3
0
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
Beispiel #4
0
def get_character_search_list(search_text, current_user=None):
    # list of all chars with name beginning with search_text
    if not (is_recruiter(current_user) or is_admin(current_user)):
        raise ForbiddenException('User must be recruiter or admin.')
    result = {}
    if len(search_text) == 0:
        return result
    for character in Character.query.\
            filter(Character.name.ilike(f'%{search_text}%')):
        result[character.id] = {
            'user_id': character.id,
            'name': character.name,
        }
    return result
Beispiel #5
0
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'}
Beispiel #6
0
def get_names_to_ids(category, name_list, current_user=None):
    if not is_admin(current_user) and not is_recruiter(current_user):
        raise ForbiddenException('User not permitted to use search.')
    elif category not in category_dict:
        raise BadRequestException(
            'Category {} is not one of the valid categories {}'.format(
                category, list(category_dict.keys())))
    else:
        result = esi.get_op('post_universe_ids',
                            names=name_list,
                            disable_multi=True)
        category_key = f'{category}s'
        if category_key in result:
            result = result[category_key]
            return {'info': {item['name']: item['id'] for item in result}}
        else:
            return {'info': {}}
Beispiel #7
0
def get_search_results(category, search, current_user=None):
    if category == 'system':
        category = 'solar_system'
    if not is_admin(current_user) and not is_recruiter(current_user):
        raise ForbiddenException('User not permitted to use search.')
    elif category not in category_dict:
        raise BadRequestException(
            'Category {} is not one of the valid categories {}'.format(
                category, list(category_dict.keys())))
    else:
        response = esi.get_op('get_search',
                              categories=[category],
                              search=search,
                              disable_multi=True)
        if category in response:
            id_list = response[category]
            item_dict = category_dict[category].get_multi(id_list)
            return {'info': {row.id: row.name for _, row in item_dict.items()}}
        else:
            return {'info': {}}
Beispiel #8
0
def release_applicant(applicant_user_id, current_user=current_user):
    if not is_recruiter(current_user):
        raise ForbiddenException(
            'User {} is not a 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 has_applicant_access(current_user, User.get(applicant_user_id)):
        raise ForbiddenException('User {} does not have access to user {}'.format(
            current_user.id, applicant_user_id
        ))
    else:
        application.recruiter_id = None
        db.session.commit()
        add_status_note(
            application, 'Application released by {}.'.format(current_user.name))
        return {'status': 'ok'}
Beispiel #9
0
def get_ids_to_names(id_list, current_user=None):
    if not is_admin(current_user) and not is_recruiter(current_user):
        raise ForbiddenException('User not permitted to use search.')
    elif len(id_list) > 0:
        result = esi.get_op('post_universe_names',
                            ids=id_list,
                            disable_multi=True)
        return_dict = {}
        for data in result:
            entry = {
                'name': data['name'],
            }
            if data['category'] in category_dict:
                entry['redlisted'] = category_dict[data['category']].get(
                    data['id']).is_redlisted
            else:
                entry['redlisted'] = False
            return_dict[data['id']] = entry
        return {'info': return_dict}
    else:
        return {'info': {}}
Beispiel #10
0
def claim_applicant(applicant_user_id, current_user=current_user):
    if not is_recruiter(current_user):
        raise ForbiddenException(
            'User {} is not a 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 application.recruiter_id is not None:
        raise BadRequestException(
            'User {} has already been claimed by a recruiter.'.format(
                applicant_user_id
            )
        )
    else:
        application.recruiter_id = current_user.id
        db.session.commit()
        add_status_note(
            application, 'Application claimed by {}.'.format(current_user.name))
        return {'status': 'ok'}
Beispiel #11
0
 def test_is_recruiter(self):
     self.assertFalse(is_recruiter(self.user))
Beispiel #12
0
 def test_is_recruiter(self):
     self.assertTrue(is_recruiter(self.user))