Пример #1
0
def set_roles(
        user_id, is_recruiter=None, is_senior_recruiter=None, is_admin=None,
        current_user=None):
    user_admin_access_check(current_user)
    user = User.get(user_id)
    if is_senior_recruiter:
        if not user.recruiter:
            db.session.add(Recruiter(id=user.id, is_senior=True))
        elif not user.recruiter.is_senior:
            user.recruiter.is_senior = True
    elif is_recruiter:
        if not user.recruiter:
            db.session.add(Recruiter(id=user.id, is_senior=False))
    elif is_recruiter == False and user.recruiter:
        remove_recruiter(user.recruiter)
    if is_senior_recruiter == False and user.recruiter and user.recruiter.is_senior:
        user.recruiter.is_senior = False

    if is_admin and not user.admin:
        db.session.add(Admin(id=user.id))
    elif is_admin == False and user.admin:
        db.session.delete(user.admin)
    db.session.commit()
    if is_recruiter or is_senior_recruiter or is_admin:
        delete_any_open_application(user_id)
    return {'status': 'ok'}
Пример #2
0
def api_set_mail_character():
    """
    Sends user to ESI to auth a character for sending admin mails.

    Error codes:
        Forbidden (403): If logged in user is not an admin.
    """
    user_admin_access_check(current_user)
    return sso.call_sso('mail')
Пример #3
0
def get_admin_list(kind, current_user=None):
    user_admin_access_check(current_user)
    if kind not in kind_dict:
        raise BadRequestException(f'Unknown Redlist {kind}')
    response = []
    redlisted_items = db.session.query(
        kind_dict[kind]).filter_by(redlisted=True)
    for item in redlisted_items:
        response.append({'id': item.id, 'name': item.name})
    return {'info': response}
Пример #4
0
def set_mail_template(name, subject, text, current_user=None):
    user_admin_access_check(current_user)
    template = MailTemplate.query.get(name)
    if template is None:
        template = MailTemplate(name=name, subject=subject, text=text)
        db.session.add(template)
    else:
        template.subject = subject
        template.text = text
    db.session.commit()
Пример #5
0
def set_mail_character(character, current_user=None):
    user_admin_access_check(current_user)
    config = db.session.query(ConfigItem).filter_by(
        key='mail_character_id').one_or_none()
    if config is None:
        config = ConfigItem(key='mail_character_id', value=str(character.id))
        db.session.add(config)
    else:
        config.value = str(character.id)
    db.session.commit()
Пример #6
0
def remove_question(question_id, current_user=None):
    user_admin_access_check(current_user)
    question = db.session.query(Question).filter_by(
        id=question_id).one_or_none()
    if question is None:
        raise BadRequestException('No question with id {}'.format(id))
    else:
        db.session.delete(question)
        db.session.commit()
    return {'status': 'ok'}
Пример #7
0
def put_admin_list(kind, item_id_list, do_replace, current_user=None):
    user_admin_access_check(current_user)
    if kind not in kind_dict:
        raise BadRequestException('Unknown Redlist')
    if do_replace:
        for item in db.session.query(kind_dict[kind]).filter_by(redlisted=True):
            item.redlisted = False
    item_list = kind_dict[kind].get_multi(item_id_list).values()
    for item in item_list:
        item.redlisted = True
    db.session.commit()
    return {'status': 'ok'}
Пример #8
0
def api_admin_refresh_db():
    """
    Refreshes database entities using ESI.

    Returns:
        {'status': 'ok'}

    Error codes:
        Forbidden (403): If logged in user is not an admin
    """
    user_admin_access_check(current_user)
    Corporation.refresh_from_esi()
    Character.refresh_from_esi()
    return jsonify({'status': 'ok'})
Пример #9
0
def remove_admin_list_item(kind, item_id, current_user=None):
    user_admin_access_check(current_user)
    if kind not in kind_dict:
        raise BadRequestException('Unknown Redlist')
    item = db.session.query(kind_dict[kind]).filter_by(
        id=item_id).one_or_none()
    if item is None:
        raise BadRequestException(f'Item {item_id} not found in List {kind}')
    elif not item.redlisted:
        raise BadRequestException(f'Item {item_id} not found in List {kind}')
    else:
        item.redlisted = False
        db.session.commit()
        return {'status': 'ok'}
Пример #10
0
def set_questions(data, current_user=None):
    user_admin_access_check(current_user)

    for question_data in data:
        id = question_data.get('question_id', None)
        text = question_data['text']
        if id is None:
            db.session.add(Question(text=text))
        else:
            question = db.session.query(Question).filter_by(
                id=id).one_or_none()
            if question is None:
                raise BadRequestException('No question with id {}'.format(id))
            question.text = text
    db.session.commit()
    return {'status': 'ok'}
Пример #11
0
def get_mail_character_data(current_user=None):
    user_admin_access_check(current_user)
    character = get_mail_character()
    if character:
        return {
            'info': {
                'id': character.id,
                'name': character.name,
            }
        }
    else:
        return {
            'info': {
                'id': None,
                'name': '',
            }
        }
Пример #12
0
def api_get_mail_character():
    """
    Retrieves info about the current character used to send mail.

    Example:

        {
            'info': {
                'id': 102830721,
                'name': Mailman Mark,
            }
        }

    Error codes:
        Forbidden (403): If logged in user is not an admin.
    """
    user_admin_access_check(current_user)
    return jsonify(get_mail_character_data(current_user=current_user))
Пример #13
0
def get_mail_template(name, current_user=None):
    user_admin_access_check(current_user)
    template = MailTemplate.query.get(name)
    if template is not None:
        return {
            'info': {
                'name': name,
                'subject': template.subject,
                'text': template.text,
            }
        }
    else:
        return {
            'info': {
                'name': name,
                'subject': '',
                'text': '',
            }
        }
Пример #14
0
def get_recently_invited_applicants(current_user=None):
    user_admin_access_check(current_user)
    result = db.session.query(Application).filter(
        Application.is_invited
    ).join(Note).filter(
        Note.timestamp >= datetime.utcnow() - timedelta(days=90)
    )
    return_data = []
    for application in result:
        last_note_time = sorted([n.timestamp for n in application.notes])[-1]
        return_data.append(
            {
                'user_id': application.user_id,
                'user_name': application.user.name,
                'last_note_time': last_note_time.isoformat(),
                'recruiter_id': application.recruiter_id,
                'recruiter_name': application.recruiter.user.name,
            }
        )
    return_data.sort(key=lambda x: x['last_note_time'], reverse=True)
    return {'info': return_data}