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 ] 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 ] 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): 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] 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): # 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() 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, 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): 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): 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, 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): # 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, 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): authorized_user_types = [UserType.FREE, UserType.PAID] success, user = check_auth(event['headers']['Authorization'], authorized_user_types) if not success: return http_status.unauthorized( "Thank-you so kindly for being a MAX Aspire member. To support our operational costs, this specific feature is available if you sign up for a paid plan or purchase credits" ) 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)) # ACTIVE Chats are available for booking # User must not have booked this Chat and must have sufficient funds if chat.chat_status != ChatStatus.ACTIVE: session.close() return http_status.forbidden("Chat is not available for booking") if chat.aspiring_professionals and user[ 'email'] in chat.aspiring_professionals: session.close() return http_status.forbidden( "user '{}' already reserved chat with id '{}'".format( user['email'], chatId)) user_credits = int(get_users(filter_=("email", user['email']), \ attributes_filter=["custom:credits"])[0]['attributes'].get('custom:credits')) if user_credits < credit_mapping[chat.chat_type]: session.close() return http_status.forbidden( "Thank-you so kindly for being a MAX Aspire member. To support our operational costs, this specific feature is available if you sign up for a paid plan or purchase credits" ) chat.aspiring_professionals = [user['email']] chat.chat_status = ChatStatus.RESERVED try: prepare_and_send_emails(chat) except ClientError as e: session.rollback() session.close() logging.info(e) if int(e.response['ResponseMetadata']['HTTPStatusCode']) >= 500: return http_status.server_error() else: return http_status.bad_request() else: admin_update_credits(user['email'], (-credit_mapping[chat.chat_type])) 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() # CANCELED state can be achieved from PENDING, ACTIVE, RESERVED_PARTIAL, RESERVED or RESERVED_CONFIRMED # # if chat to be canceled is dated (i.e. cannot be rescheduled): # - if PENDING => N/A # - else => set to CANCELED, refund APs # # if chat to be canceled is undated (i.e. can be rescheduled): # - set to CANCELED # - refund APs # - create a new PENDING chat to be rescheduled # - if not PENDING # - increment remaining chat frequency in Cognito # TODO: send email notification to SEs and APs if chat.chat_status == ChatStatus.DONE or chat.chat_status == ChatStatus.CANCELED or chat.chat_status == ChatStatus.EXPIRED: session.close() return http_status.forbidden( "cannot cancel DONE, CANCELED or EXPIRED chat with id '{}'".format( chatId)) for ap in chat.aspiring_professionals: admin_update_credits(ap, credit_mapping[chat.chat_type]) if not chat.fixed_date: chat_new = Chat(chat_type=chat.chat_type, description=chat.description, chat_status=ChatStatus.PENDING, tags=chat.tags, senior_executive=chat.senior_executive) session.add(chat_new) if chat.chat_status != ChatStatus.PENDING: admin_update_remaining_chats_frequency(chat.senior_executive, 1) chat.chat_status = ChatStatus.CANCELED session.commit() session.close() return http_status.success()