Ejemplo n.º 1
0
def handler(event, context):
    # check authorization
    authorized_user_types = [
        UserType.ADMIN, UserType.MENTOR, UserType.PAID, UserType.FREE
    ]
    success, _ = check_auth(event['headers']['Authorization'],
                            authorized_user_types)
    if not success:
        return http_status.unauthorized()

    search = event["queryStringParameters"].get(
        "search", "") if event["queryStringParameters"] else ""
    fuzzy = event["queryStringParameters"].get(
        "fuzzy", "") if event["queryStringParameters"] else ""

    session = Session()
    if fuzzy.lower() == "true":
        industry_tags = session.query(IndustryTag).filter(
            IndustryTag.tag.ilike("%{}%".format(search))).all()
    else:
        industry_tags = session.query(IndustryTag).filter(
            IndustryTag.tag.ilike("{}%".format(search))).all()
    session.close()

    return http_status.success(
        json.dumps({
            "industry_tags": [row2dict(r) for r in industry_tags],
            "count": len(industry_tags)
        }))
Ejemplo n.º 2
0
def handler(event, context):

    authorized_user_types = [
        UserType.ADMIN, UserType.MENTOR, UserType.PAID, UserType.FREE
    ]
    success, _ = check_auth(event['headers']['Authorization'],
                            authorized_user_types)
    if not success:
        return http_status.unauthorized()

    session = Session()
    jobId = event["pathParameters"]["jobId"]
    job = session.query(Job).get(jobId)

    if job != None:
        job_apps_id = []
        for app in job.job_applications:
            job_apps_id.append(app.job_application_id)
        jobdict = row2dict(job)
        jobdict['job_applications'] = job_apps_id
        session.close()
        return http_status.success(json.dumps(jobdict))
    else:
        session.close()
        return http_status.not_found()
Ejemplo n.º 3
0
def handler(event, context):
    # check authorization
    authorized_user_types = [
        UserType.ADMIN,
        UserType.MENTOR,
        UserType.FREE,
        UserType.PAID
    ]
    success, _ = check_auth(event['headers']['Authorization'], authorized_user_types)
    if not success:
        return http_status.unauthorized()

    status_filter = event["queryStringParameters"].get("status", "") if event["queryStringParameters"] else ""
    requestor_filter = event["queryStringParameters"].get("requestor", "") if event["queryStringParameters"] else ""
    requestee_filter = event["queryStringParameters"].get("requestee", "") if event["queryStringParameters"] else ""

    session = Session()
    filtered_query = session.query(Connection)
    if status_filter:
        filtered_query = filtered_query.filter(Connection.connection_status == status_filter)
    if requestor_filter:
        filtered_query = filtered_query.filter(Connection.requestor == requestor_filter)
    if requestee_filter:
        filtered_query = filtered_query.filter(Connection.requestee == requestee_filter)

    connections = filtered_query.all()
    session.close()

    return http_status.success(json.dumps({
            "connections": [row2dict(r) for r in connections],
            "count": len(connections)
        }))
Ejemplo n.º 4
0
def handler(event, context):
    chatId = event["pathParameters"].get("chatId") if event["pathParameters"] else None
    if not chatId:
        return http_status.bad_request("missing path parameter(s): 'chatId'")

    session = Session()
    chat = session.query(Chat).get(chatId)
    session.close()
    if not chat:
        return http_status.not_found("chat with id '{}' not found".format(chatId))

    return http_status.success(json.dumps(
            row2dict(chat)
        ))
Ejemplo n.º 5
0
def handler(event, context):
    # check authorization
    authorized_user_types = [
        UserType.ADMIN, UserType.MENTOR, UserType.FREE, UserType.PAID
    ]
    success, _ = check_auth(event['headers']['Authorization'],
                            authorized_user_types)
    if not success:
        return http_status.unauthorized()

    connectId = event["pathParameters"].get(
        "connectId") if event["pathParameters"] else None
    if not connectId:
        return http_status.bad_request(
            "missing path parameter(s): 'connectId'")

    session = Session()
    connection = session.query(Connection).get(connectId)
    if not connection:
        session.close()
        return http_status.not_found()

    body = json.loads(event["body"])
    new_connection_status = body.get('connect_status')
    if new_connection_status and new_connection_status not in ConnectionStatus.__members__:
        session.close()
        return http_status.bad_request(
            "invalid parameter(s): 'connect_status'")

    if new_connection_status:
        if connection.connection_status == ConnectionStatus.PENDING and new_connection_status == 'ACCEPTED':
            # TODO: dynamic user_email
            # TODO: update email subject/body
            user_email = "*****@*****.**"
            email_subject = "Your Senior Executive connection request was accepted"
            email_body = "<name> has accepted your connection request!"
            send_email(to_addresses=user_email,
                       subject=email_subject,
                       body_text=email_body)

        connection.connection_status = ConnectionStatus[new_connection_status]

    session.commit()
    session.refresh(connection)
    session.close()

    return http_status.success(json.dumps(row2dict(connection)))
Ejemplo n.º 6
0
def handler(event, context):
    session = Session()
    page = None
    user_id = None
    status = None
    tag = None
    page_size = 20
    if event["queryStringParameters"]:
        page = event["queryStringParameters"].get(
            'page')  #returns None if 'page' not in dict
        user_id = event["queryStringParameters"].get('user_id')
        tag = event["queryStringParameters"].get('tag')
        status = event["queryStringParameters"].get('status')
        page_size = int(event["queryStringParameters"].get('page_size', 3))

    jobs = session.query(Job)
    if user_id != None:
        jobs = jobs.filter(Job.posted_by == user_id)
    if status != None:
        status_list = [x.upper() for x in status.split(',')]
        jobs = jobs.filter(Job.job_status.in_(status_list))
    if page != None:
        jobs = jobs.offset((int(page) * page_size) -
                           page_size).limit(page_size)

    joblist = []
    for job in jobs:
        job_apps_id = []
        for app in job.job_applications:
            job_apps_id.append(app.job_application_id)
        jobdict = row2dict(job)
        jobdict['job_applications'] = job_apps_id
        if tag == None or tag.upper() in jobdict['job_tags']:
            joblist.append(jobdict)

    joblist = sorted(joblist, key=lambda i: i['job_id'], reverse=True)

    session.close()

    return http_status.success(
        json.dumps({
            "jobs": joblist,
            "count": len(joblist)
        }))
Ejemplo n.º 7
0
def handler(event, context):
    # check authorization
    authorized_user_types = [
        UserType.ADMIN, UserType.MENTOR, UserType.PAID, UserType.FREE
    ]
    success, _ = check_auth(event['headers']['Authorization'],
                            authorized_user_types)
    if not success:
        return http_status.unauthorized()

    industryTagId = event["pathParameters"].get(
        "industryTagId") if event["pathParameters"] else None
    if not industryTagId:
        return http_status.bad_request(
            "missing path parameter(s): 'industryTagId'")

    session = Session()
    industry_tag = session.query(IndustryTag).get(industryTagId.lower())
    session.close()
    if not industry_tag:
        return http_status.not_found()

    return http_status.success(json.dumps(row2dict(industry_tag)))
Ejemplo n.º 8
0
def handler(event, context):
    # check authorization
    authorized_user_types = [UserType.ADMIN, UserType.MENTOR]
    success, user = check_auth(event['headers']['Authorization'],
                               authorized_user_types)
    if not success:
        return http_status.unauthorized()

    chatId = event["pathParameters"].get(
        "chatId") if event["pathParameters"] else None
    if not chatId:
        return http_status.bad_request("missing path parameter(s): 'chatId'")

    session = Session()
    chat = session.query(Chat).get(chatId)
    if not chat:
        session.close()
        return http_status.not_found(
            "chat with id '{}' not found".format(chatId))

    success = edit_auth(user, chat.senior_executive)
    if not success:
        session.close()
        return http_status.unauthorized()

    # TODO: allow updating description, tags and fixed_date?
    # if fixed_date => what if it's active or pending with expiry_date specified?
    body = json.loads(event["body"])
    description_new = body.get('description')
    tags_new = body.get('tags')
    fixed_date_new = body.get('fixed_date')

    session.commit()
    session.refresh(chat)
    session.close()

    return http_status.success(json.dumps(row2dict(chat)))
Ejemplo n.º 9
0
def handler(event, context):
    # check authorization
    authorized_user_types = [
        UserType.ADMIN, UserType.MENTOR, UserType.FREE, UserType.PAID
    ]
    success, _ = check_auth(event['headers']['Authorization'],
                            authorized_user_types)
    if not success:
        return http_status.unauthorized()

    connectId = event["pathParameters"].get(
        "connectId") if event["pathParameters"] else None
    if not connectId:
        return http_status.bad_request(
            "missing path parameter(s): 'connectId'")

    session = Session()
    connection = session.query(Connection).get(connectId)
    session.close()
    if not connection:
        session.close()
        return http_status.not_found()

    return http_status.success(json.dumps(row2dict(connection)))
Ejemplo n.º 10
0
def handler(event, context):

    # check authorization
    authorized_user_types = [UserType.ADMIN, UserType.MENTOR, UserType.PAID]
    success, user = check_auth(event['headers']['Authorization'],
                               authorized_user_types)
    if not success:
        return http_status.unauthorized(
            "You have to be a paid member to be able to apply to jobs")

    email = user['email']
    candidate_name = user["given_name"] + " " + user["family_name"]

    session = Session()
    info = json.loads(event["body"])
    job_id = info.get('job_id')
    resumes = info.get('resumes')
    cover_letters = info.get('cover_letters')

    #Validate Body
    if not (job_id and resumes and cover_letters):
        return http_status.bad_request(
            "missing parameter(s): 'job_id, resumes, cover_letters'")
    else:
        try:
            job_id = int(job_id)
        except ValueError:
            return http_status.bad_request(
                "invalid parameter: 'job_id must be an integer'")

    job = session.query(Job).get(job_id)
    hiring_manager = job.posted_by
    if hiring_manager == email:
        return http_status.forbidden("Hiring manager cannot apply to the job")

    existing_job_application = session.query(JobApplication).filter(
        JobApplication.applicant_id == email).filter(
            JobApplication.job_id == job_id).all()
    if len(existing_job_application) > 0:
        return http_status.forbidden("You have already applied to this job")

    job_rs = JobApplication(job_id=job_id,
                            applicant_id=email,
                            job_application_status=JobApplicationStatus.SUBMIT,
                            resumes=resumes,
                            cover_letters=cover_letters)
    session.add(job_rs)
    session.commit()

    job_title = job.title
    today = datetime.today().strftime("%Y-%m-%d")
    hiring_manager = str(job.posted_by)

    # The send_email_templated function requires JSON Formatted Data with " strings "
    template_data = {
        "candidate_name": str(candidate_name),
        "job_title": str(job_title),
        "today": str(today)
    }
    template_data = json.dumps(template_data)
    recipients = [hiring_manager]
    send_templated_email(recipients, "JobApplication-Creation-HiringManager",
                         template_data)

    template_data = {"job_title": str(job_title), "today": str(today)}
    template_data = json.dumps(template_data)
    recipients = [email]
    send_templated_email(recipients, "JobApplication-Creation-Applicant",
                         template_data)

    resp = row2dict(job_rs)
    session.close()

    return http_status.success(json.dumps(resp))
Ejemplo n.º 11
0
def handler(event, context):
    status_filter = event["queryStringParameters"].get(
        "status", "") if event["queryStringParameters"] else ""
    type_filter = event["queryStringParameters"].get(
        "type", "") if event["queryStringParameters"] else ""
    user_filter = event["queryStringParameters"].get(
        "email", "") if event["queryStringParameters"] else ""

    session = Session()
    # TODO: more filters? (tags)
    filtered_query = session.query(Chat)
    if status_filter:
        status_filter = [
            ChatStatus[x.strip()] for x in status_filter.split(',')
            if x in ChatStatus.__members__
        ]
        filtered_query = filtered_query.filter(
            Chat.chat_status.in_(status_filter))
    if type_filter:
        type_filter = [
            ChatType[x.strip()] for x in type_filter.split(',')
            if x in ChatType.__members__
        ]
        filtered_query = filtered_query.filter(Chat.chat_type.in_(type_filter))
    if user_filter:
        user, _ = get_users(filter_=('email', user_filter),
                            attributes_filter=['custom:user_type'])
        user_type = user['attributes']['custom:user_type']
        if user_type == 'PAID' or user_type == 'FREE':
            filtered_query = filtered_query.filter(
                Chat.aspiring_professionals.any(user_filter))
        elif user_type == 'MENTOR':
            filtered_query = filtered_query.filter(
                Chat.senior_executive == user_filter)

    chats = filtered_query.all()
    session.close()

    chats_modified = [row2dict(r) for r in chats]
    for chat in chats_modified:
        se = chat['senior_executive']
        user = users[se]
        chat['given_name'] = user['attributes']['given_name']
        chat['family_name'] = user['attributes']['family_name']
        chat['picture'] = user['attributes']['picture']
        chat['custom:company'] = user['attributes'].get("custom:company", "")
        chat['position'] = user['attributes'].get("custom:position", "")
        chat['region'] = json.loads(user['attributes']['address'])['region']
        chat['industry_tags'] = user['attributes'].get("custom:industry_tags",
                                                       "")
        chat['industry'] = user['attributes'].get("custom:industry", "")

    sorted_chats = []
    sorted_chats = sorted(chats_modified,
                          key=lambda x: x['chat_type'],
                          reverse=True)

    return http_status.success(
        json.dumps({
            "chats": sorted_chats,
            "count": len(chats_modified)
        }))
Ejemplo n.º 12
0
def handler(event, context):
    # check authorization
    authorized_user_types = [UserType.ADMIN, UserType.MENTOR, UserType.PAID]
    success, _ = check_auth(event['headers']['Authorization'],
                            authorized_user_types)
    if not success:
        return http_status.unauthorized()

    session = Session()

    info = json.loads(event["body"])

    tags = []
    salary = 0

    tag = info.get('job_tags')
    job_title = info.get('title')
    company = info.get('company')
    region = info.get('region')
    city = info.get('city')
    country = info.get('country')
    job_type = info.get('job_type')
    description = info.get('description')
    requirements = info.get('requirements')
    posted_by = info.get('posted_by')
    poster_family_name = info.get('poster_family_name')
    poster_given_name = info.get('poster_given_name')
    salary = str(info.get('salary'))
    deadline = info.get('deadline')
    can_contact = str(info.get('can_contact'))

    if salary is None or salary == '':
        salary = "0"

    #Validate body
    if not (job_title and company and region and city and country and job_type
            and description and requirements and posted_by
            and poster_family_name and poster_given_name and salary
            and deadline and can_contact):
        return http_status.bad_request("missing parameter(s)")
    else:
        # If no attributes are missing, cast types as required.
        try:
            salary = int(salary)
            deadline = datetime.fromtimestamp(deadline).replace(hour=0,
                                                                minute=0,
                                                                second=0,
                                                                microsecond=0)

            if can_contact.lower() == 'true':
                can_contact = True
            elif can_contact.lower() == 'false':
                can_contact = False
            else:
                raise ValueError

            job_type = JobType[job_type]
            for tag in info["job_tags"]:
                tags.append(JobTags[tag])
        except:
            return http_status.bad_request(
                "invalid parameter(s): 'salary must be an integer, deadline must be a datetime, can_contact must be a bool, and JobType & JobTags must be from their enum types'"
            )

    Job_row = Job(title=job_title,
                  company=company,
                  region=region,
                  city=city,
                  country=country,
                  job_type=job_type,
                  description=description,
                  requirements=requirements,
                  posted_by=posted_by,
                  poster_family_name=poster_family_name,
                  poster_given_name=poster_given_name,
                  job_status='UNDER_REVIEW',
                  job_tags=tags,
                  salary=salary,
                  deadline=deadline,
                  can_contact=can_contact)

    session.add(Job_row)
    session.commit()
    res = row2dict(Job_row)
    session.close()

    ##email hiring manager
    job_title = info["title"]
    today = datetime.today().strftime("%Y-%m-%d")
    hiring_manager = str(info["posted_by"])

    # The send_email_templated function requires JSON Formatted Data with " strings "
    template_data = {"job_title": str(job_title), "today": str(today)}
    template_data = json.dumps(template_data)
    recipients = [hiring_manager]
    send_templated_email(recipients, "Job-Creation", template_data)

    return http_status.success(json.dumps(res))