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() session = Session() jobId = event["pathParameters"]["jobId"] job = session.query(Job).get(jobId) if job == None: session.close() return http_status.not_found() user_credits = int(get_users(filter_=("email", user['email']), \ attributes_filter=["custom:credits"])[0]['attributes'].get('custom:credits')) email = user['email'] if job.can_contact: applied = False for job_app in job.job_applications: if job_app.applicant_id == email: applied = True if not applied: session.close() return http_status.forbidden( "You need to apply to the job before requesting contact-information" ) if job.people_contacted >= 4: session.close() return http_status.forbidden( "Limit of contact information requests has been exceeded") if user_credits < 5: session.close() return http_status.forbidden( "You do not have enough credits to request contact information" ) admin_update_credits( email, -5) # deducting credits for requesting contact_info job.people_contacted = job.people_contacted + 1 session.commit() return http_status.success( json.dumps({ "contact_details": { "email": job.posted_by, "given_name": job.poster_given_name, "family_name": job.poster_family_name } })) else: session.close() return http_status.success( json.dumps( {"message": "Hiring manager does not want to be contacted"}))
def handler(event, context): authorized_user_types = [UserType.FREE] success, user = check_auth(event['headers']['Authorization'], authorized_user_types) if not success: return http_status.unauthorized() user_email = user['email'] if not user_email: return http_status.bad_request() success = edit_auth(user, user_email) if not success: return http_status.unauthorized() current_timestamp = int(datetime.now().timestamp()) attributes = { "custom:user_type": "PAID", "custom:start_date": str(current_timestamp), "custom:end_date": str(current_timestamp + 31556952) # 31556952 is the seconds in a year } admin_update_user_attributes(user_email, attributes) user_credits = 25 admin_update_credits(user_email, user_credits) return http_status.success()
def handler(event, context): authorized_user_types = [ UserType.ADMIN, ] success, _ = check_auth(event['headers']['Authorization'], authorized_user_types) if not success: return http_status.unauthorized() body = json.loads(event["body"]) user_email = body.get('email') if not user_email: return http_status.bad_request() chat_freq = 4 attributes = { "custom:user_type": "MENTOR", "custom:declared_chats_freq": str(chat_freq), "custom:remaining_chats_freq": str(chat_freq) } admin_update_user_attributes(user_email, attributes) admin_enable_user(user_email) session = Session() for i in range(chat_freq): chat_type = ChatType["ONE_ON_ONE"] chat = Chat(chat_type=chat_type, chat_status=ChatStatus.PENDING, senior_executive=user_email) session.add(chat) session.commit() session.close() return http_status.success()
def handler(event, context): logging.info('Test') # 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() # # create a new session session = Session() jobId = event["pathParameters"]["jobId"] job = session.query(Job).get(jobId) if job != None: job.job_status = JobStatus.CLOSED session.commit() session.close() return http_status.success() else: session.close() return http_status.not_found()
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) }))
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) }))
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() # DONE state can be achieved from RESERVED_CONFIRMED if chat.chat_status != ChatStatus.RESERVED_CONFIRMED: session.close() return http_status.forbidden("cannot mark DONE unconfirmed reservation of chat with id '{}'".format(chatId)) chat.chat_status = ChatStatus.DONE session.commit() session.close() return http_status.success()
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() session.delete(connection) session.commit() session.close() return http_status.success()
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() jobAppId = event["pathParameters"]["id"] jobApp = session.query(JobApplication).get(jobAppId) if jobApp == None: session.commit() session.close() return http_status.not_found() else: delete = session.query(JobApplication).filter(JobApplication.job_application_id == jobAppId).delete() session.commit() session.close() return http_status.success()
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"]) jobAppId = event["pathParameters"]["id"] jobApp = session.query(JobApplication).get(jobAppId) if jobApp != None: keys = info.keys() for key in keys: setattr(jobApp, key, info[key]) session.commit() session.close() return http_status.success(json.dumps(info)) else: return http_status.not_found()
def handler(event, context): # check authorization authorized_user_types = [ UserType.ADMIN ] success, _ = 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)) admin_update_declared_chats_frequency(chat.senior_executive, -1) if chat.chat_status == ChatStatus.PENDING: admin_update_remaining_chats_frequency(chat.senior_executive, -1) session.delete(chat) session.commit() session.close() return http_status.success()
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() # FOR REFERENCE # # create a new session session = Session() jobId = event["pathParameters"]["jobId"] job = session.query(Job).get(jobId) if job == None: return http_status.not_found() if len(job.job_applications ) != 0: # when there are job applications associated to a job return http_status.forbidden() session.query(Job).filter(Job.job_id == jobId).delete() # # commit and close session session.commit() session.close() return http_status.success()
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()
def handler(event, context): userId = event["pathParameters"].get( "userId") if event["pathParameters"] else None if not userId: return http_status.bad_request() user, _ = get_users(filter_=('email', userId)) if not user: return http_status.not_found() return http_status.success(json.dumps(user))
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() # # create a new session session = Session() jobId = event["pathParameters"]["jobId"] job = session.query(Job).get(jobId) info = json.loads(event["body"]) if job != None: #if it was a valid jobid, and the job was found keys = info.keys() for key in keys: value = info[key] logger.info('key is ' + str(key) + ' and value is ' + str(value)) if key == 'salary': if value is None or value == '': value = 0 else: value = int(value) elif key == 'deadline': value = datetime.fromtimestamp(value).replace(hour=0, minute=0, second=0, microsecond=0) elif key == 'tags': value = [] if key == 'job_applications': continue setattr(job, key, value) session.commit() session.close() if "job_status" in keys and info["job_status"] is "ACTIVE": job_title = job.title today = datetime.today().strftime("%Y-%m-%d") hiring_manager = job.posted_by subject = "[MAX Aspire] Your job is now active!" body = f"Salaam!\r\n\nWe are delighted to confirm that the job posting {job_title} is successfully posted on MAX Aspire job board on {today}. You will frequently be notified about the job applications as and when received. Keep an eye on your member portal/email.\r\n\nWe appreciate you putting your trust in MAX Aspire. We wish you luck in hiring the best possible candidate form our talented pool of aspiring professionals.\r\n\nBest regards,\nTeam MAX Aspire\r\n" send_email(to_addresses=hiring_manager, subject=subject, body_text=body) return http_status.success() else: return http_status.not_found()
def handler(event, context): session = Session() try: default_num_activate = 25 current_date = datetime.strptime(datetime.now().strftime("%d/%m/%Y"), "%d/%m/%Y") scheduling_period = 7 if event.get("queryStringParameters"): if event["queryStringParameters"].get("num_activate"): default_num_activate = int( event["queryStringParameters"]["num_activate"]) if event["queryStringParameters"].get("current_date"): current_date = datetime.strptime( event["queryStringParameters"]["current_date"], "%d/%m/%Y") if event["queryStringParameters"].get("scheduling_period"): scheduling_period = int( event["queryStringParameters"]["scheduling_period"]) next_date = current_date + timedelta(days=scheduling_period) logger.info("num_activate={}, current_date={}, next_date={}"\ .format(default_num_activate, current_date.strftime("%d/%m/%Y"), next_date.strftime("%d/%m/%Y"))) users, _ = get_users(user_type='MENTOR') num_carry_over = 0 total_unbooked = 0 total_expiring_activated = 0 for id in users: user = users[id] num_unbooked, num_expiring_activated = schedule_user( session, user['attributes'], current_date, next_date) total_unbooked += num_unbooked total_expiring_activated += num_expiring_activated logger.info("Carry Forward={}".format(num_carry_over)) logger.info("Number of Unbooked Chats (previous cycle)={}".format( total_unbooked)) logger.info("Number of Activated Expiring Chats={}".format( total_expiring_activated)) schedule_activate(session, default_num_activate, num_carry_over) except Exception as e: session.rollback() session.close() import traceback traceback.print_exc() return http_status.bad_request( "exception caught while running scheduler {}".format(e)) session.commit() session.close() return http_status.success( json.dumps({"next_date": next_date.strftime("%d/%m/%Y")}))
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() applicantId = "" jobId = "" if event["queryStringParameters"] != None: if event["queryStringParameters"].get('jobId') != None: jobId = event["queryStringParameters"].get('jobId') if event["queryStringParameters"].get('userId') != None: applicantId = event["queryStringParameters"].get('userId') if (applicantId != None and applicantId != "" and jobId != None and jobId != ""): jobApps = session.query(JobApplication).filter( JobApplication.applicant_id == applicantId, JobApplication.job_id == jobId).all() elif (jobId != None and jobId != ""): jobApps = session.query(JobApplication).filter( JobApplication.job_id == jobId).all() elif (applicantId != None and applicantId != ""): jobApps = session.query(JobApplication).filter( JobApplication.applicant_id == applicantId).all() else: jobApps = session.query(JobApplication).all() session.close() jobAppsList = [] for jobApp in jobApps: jobApp_json = { "job_application_id": jobApp.job_application_id, "job_id": jobApp.job_id, "applicant_id": jobApp.applicant_id, "resumes": jobApp.resumes, "cover_letters": jobApp.cover_letters, "job_application_status": jobApp.job_application_status.name, "created_on": jobApp.created_on.timestamp(), "updated_on": jobApp.updated_on.timestamp() } jobAppsList.append(jobApp_json) return http_status.success(json.dumps(jobAppsList))
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) ))
def handler(event, context): # check authorization authorized_user_types = [ UserType.ADMIN ] success, _ = check_auth(event['headers']['Authorization'], authorized_user_types) if not success: return http_status.forbidden() # validate body body = json.loads(event["body"]) senior_executive = body.get('senior_executive') chats_new = body.get('chats') if not senior_executive or not chats_new: return http_status.bad_request("invalid parameter(s): 'senior_executive, chats'") session = Session() for chat_new in chats_new: if not chat_new.get('chat_type') or chat_new['chat_type'] not in ChatType.__members__: session.close() return http_status.bad_request("invalid parameter(s): 'chat_type'") chat_type = ChatType[chat_new['chat_type']] description = chat_new.get('description') tags = chat_new.get('tags') fixed_date = chat_new.get('fixed_date') if chat_type in mandatory_date and not fixed_date: session.rollback() session.close() return http_status.bad_request("missing body attribute { fixed_date } with chat_type { %s }" % (chat_type.name)) chat = Chat( chat_type=chat_type, description=description, chat_status=ChatStatus.PENDING, tags=tags, senior_executive=senior_executive ) admin_update_declared_chats_frequency(senior_executive, 1) if fixed_date: chat.fixed_date = datetime.fromtimestamp(fixed_date).replace(hour=0, minute=0,second=0, microsecond=0) chat.chat_status = ChatStatus.ACTIVE else: admin_update_remaining_chats_frequency(senior_executive, 1) session.add(chat) session.commit() session.close() return http_status.success()
def handler(event, context): authorized_user_types = [UserType.ADMIN] success, _ = check_auth(event['headers']['Authorization'], authorized_user_types) if not success: return http_status.unauthorized() body = json.loads(event["body"]) user_email = body.get('email') if not user_email: return http_status.bad_request() admin_disable_user(user_email) # TODO: should we remove the user's chats/jobs etc...? return http_status.success()
def handler(event, context): authorized_user_types = [ UserType.ADMIN ] success, _ = check_auth(event['headers']['Authorization'], authorized_user_types) if not success: return http_status.unauthorized() # validate body body = json.loads(event["body"]) user_email = body.get('email') if not user_email: return http_status.bad_request() admin_enable_user(user_email) return http_status.success()
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)))
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) }))
def handler(event, context): authorized_user_types = [UserType.ADMIN, UserType.PAID, UserType.FREE] success, user = check_auth(event['headers']['Authorization'], authorized_user_types) if not success: return http_status.unauthorized() body = json.loads(event["body"]) user_email = body.get('email') user_credits = body.get('credits') if not user_email or not credits or not isinstance(user_credits, int): return http_status.bad_request() success = edit_auth(user, user_email) if not success: return http_status.unauthorized() admin_update_credits(user_email, user_credits) return http_status.success()
def handler(event, context): # check authorization authorized_user_types = [UserType.ADMIN] 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()) if not industry_tag: session.close() return http_status.not_found() session.delete(industry_tag) session.commit() session.close() return http_status.success()
def handler(event, context): # check authorization authorized_user_types = [UserType.ADMIN] 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 "" type_filter = event["queryStringParameters"].get( "type", "") if event["queryStringParameters"] else "" senior_executive_filter = event["queryStringParameters"].get( "senior_executive", "") if event["queryStringParameters"] else "" session = Session() filtered_query = session.query(Chat) if status_filter and status_filter in ChatStatus.__members__: filtered_query = filtered_query.filter( Chat.chat_status == ChatStatus[status_filter]) if type_filter and type_filter in ChatType.__members__: filtered_query = filtered_query.filter( Chat.chat_type == ChatType[type_filter]) if senior_executive_filter: filtered_query = filtered_query.filter( Chat.senior_executive == senior_executive_filter) chats = filtered_query.all() for chat in chats: admin_update_declared_chats_frequency(chat.senior_executive, -1) if chat.chat_status == ChatStatus.PENDING: admin_update_remaining_chats_frequency(chat.senior_executive, -1) session.delete(chat) session.commit() session.close() return http_status.success()
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)))
def handler(event, context): authorized_user_types = [ UserType.MENTOR, UserType.PAID, UserType.FREE ] success, user = check_auth(event['headers']['Authorization'], authorized_user_types) if not success: return http_status.unauthorized() userId = event["pathParameters"].get("userId") if event["pathParameters"] else None if not userId: return http_status.bad_request() user_edit, _ = get_users(filter_=('email', userId)) if not user_edit: return http_status.not_found() user_attributes = user_edit['attributes'] success = edit_auth(user, user_attributes.pop('email')) if not success: return http_status.unauthorized() body = json.loads(event["body"]) user_type = user['custom:user_type'] if user_type == 'MENTOR': body['custom:resume'] = 'https://aspire-user-profile.s3.amazonaws.com/blank_resume.pdf' new_attrs = {} for key in body: if key not in standard_attributes: key = 'custom:' + key new_attrs[key] = body[key] admin_update_user_attributes(user['email'], new_attrs) return http_status.success(json.dumps(user))
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() body = json.loads(event["body"]) try: requestor = body['requestor'] requestee = body['requestee'] except: return http_status.bad_request("missing body attribute(s): 'requestor' or 'requestee'") try: requestor_email = requestor['email'] requestor_type = requestor['user_type'] requestor_name = requestor['name'] requestee_email = requestee['email'] requestee_type = requestee['user_type'] requestee_name = requestee['name'] except: return http_status.bad_request("missing body attribute(s): 'user_type', 'email' or 'name'") session = Session() connections = session.query(Connection).all() create_conn = True for connection in connections: if (connection.requestor == requestor_email and connection.requestee == requestee_email) \ or (connection.requestor == requestee_email and connection.requestee == requestor_email): if connection.connection_status == ConnectionStatus.PENDING: if connection.requestor == requestee_email and connection.requestee == requestor_email: connection.connection_status = ConnectionStatus.ACCEPTED template_data = { "requestee_name": str(requestee_name), "requestor_name": str(requestor_name) } template_data = json.dumps(template_data) recipients = [requestor_email,requestee_email] send_templated_email(recipients, "Connection-Confirmation-SEtoSE", template_data) create_conn = False break session.close() return http_status.bad_request("connections request already sent") elif connection.connection_status == ConnectionStatus.ACCEPTED: session.close() return http_status.bad_request("connections request already established") if create_conn: if requestee_type == "MENTOR" and requestor_type == "MENTOR": new_connection = Connection(requestor=requestor_email, requestee=requestee_email, connection_status=ConnectionStatus.PENDING) session.add(new_connection) template_data = { "requestee_name": str(requestee_name), "requestor_name": str(requestor_name) } template_data = json.dumps(template_data) recipients = [requestee_email] send_templated_email(recipients, "Connection-Initiation-SEtoSE", template_data) elif requestee_type == "MENTEE" and requestor_type == "MENTOR": new_connection = Connection(requestor=requestor_email, requestee=requestee_email, connection_status=ConnectionStatus.ACCEPTED) session.add(new_connection) # The send_templated_email function requires JSON Formatted Data with " strings " template_data = { "requestee_name": str(requestee_name), "requestor_name": str(requestor_name) } template_data = json.dumps(template_data) recipients = [requestor_email, requestee_email] send_templated_email(recipients, "Connection-Initiation-SEtoAP", template_data) else: return http_status.bad_request("A connection can only be initiated by a mentor") session.commit() session.close() return http_status.success()
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))