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): # 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.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, 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()
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()