def post(self, send_email=True): args = self.req_parser.parse_args() event_id = args['event_id'] email = args['email'] role = args['role'] user = user_repository.get_by_email(email, g.organisation.id) if not user: return USER_NOT_FOUND event = event_repository.get_by_id(event_id) if not event: return EVENT_NOT_FOUND existingInvitedGuest = db.session.query(InvitedGuest).filter( InvitedGuest.event_id == event_id).filter( InvitedGuest.user_id == user.id).first() if existingInvitedGuest: return INVITED_GUEST_FOR_EVENT_EXISTS invitedGuest = InvitedGuest(event_id=event_id, user_id=user.id, role=role) db.session.add(invitedGuest) try: db.session.commit() except IntegrityError: LOGGER.error("Failed to add invited guest: {}".format(email)) return ADD_INVITED_GUEST_FAILED if send_email: try: send_mail(recipient=user.email, subject='Your invitation to {}'.format(event.name), body_text=GUEST_EMAIL_TEMPLATE.format( user_title=user.user_title, firstname=user.firstname, lastname=user.lastname, role=role, event_name=event.name, event_key=event.key, system_name=g.organisation.system_name, host=misc.get_baobab_host())) except Exception as e: LOGGER.error( 'Failed to send email to invited guest with user Id {}, due to {}' .format(user.id, e)) return INVITED_GUEST_EMAIL_FAILED return invitedGuest_info(invitedGuest, user), 201
def post(self, send_email=True): args = self.req_parser.parse_args() event_id = args['event_id'] email = args['email'] role = args['role'] user = user_repository.get_by_email(email, g.organisation.id) if not user: return USER_NOT_FOUND event = event_repository.get_by_id(event_id) if not event: return EVENT_NOT_FOUND existingInvitedGuest = db.session.query(InvitedGuest).filter( InvitedGuest.event_id == event_id).filter(InvitedGuest.user_id == user.id).first() if existingInvitedGuest: return INVITED_GUEST_FOR_EVENT_EXISTS invitedGuest = InvitedGuest( event_id=event_id, user_id=user.id, role=role ) db.session.add(invitedGuest) try: db.session.commit() except IntegrityError: LOGGER.error( "Failed to add invited guest: {}".format(email)) return ADD_INVITED_GUEST_FAILED if send_email: try: email_user( 'guest-invitation-with-registration' if event.is_registration_open else 'guest-invitation', template_parameters=dict( role=role, system_name=g.organisation.system_name, host=misc.get_baobab_host(), event_key=event.key ), event=event, user=user) except Exception as e: LOGGER.error('Failed to send email to invited guest with user Id {}, due to {}'.format(user.id, e)) return INVITED_GUEST_EMAIL_FAILED return invitedGuest_info(invitedGuest, user), 201
def post(self): args = self.post_req_parser.parse_args() user_id = g.current_user['id'] event_id = args['event_id'] reviewer_user_email = args['reviewer_user_email'] num_reviews = args['num_reviews'] event = db.session.query(Event).filter(Event.id == event_id).first() if not event: return EVENT_NOT_FOUND current_user = user_repository.get_by_id(user_id) if not current_user.is_event_admin(event_id): return FORBIDDEN reviewer_user = user_repository.get_by_email(reviewer_user_email, g.organisation.id) if reviewer_user is None: return USER_NOT_FOUND if not reviewer_user.is_reviewer(event_id): self.add_reviewer_role(reviewer_user.id, event_id) config = review_configuration_repository.get_configuration_for_event( event_id) response_ids = self.get_eligible_response_ids( event_id, reviewer_user.id, num_reviews, config.num_reviews_required) response_reviewers = [ ResponseReviewer(response_id, reviewer_user.id) for response_id in response_ids ] db.session.add_all(response_reviewers) db.session.commit() if len(response_ids) > 0: send_mail(recipient=reviewer_user.email, subject='You have been assigned reviews in Baobab', body_text=ASSIGNED_BODY.format( title=reviewer_user.user_title, firstname=reviewer_user.firstname, lastname=reviewer_user.lastname, num_reviews=len(response_ids), baobab_host=misc.get_baobab_host(), system_name=g.organisation.system_name, event_key=event.key, event=event.name)) return {}, 201
def post(self, event_id): parser = reqparse.RequestParser() parser.add_argument('response_ids', type=int, required=True, action='append') parser.add_argument('reviewer_email', type=str, required=True) args = parser.parse_args() response_ids = args['response_ids'] reviewer_email = args['reviewer_email'] filtered_response_ids = response_repository.filter_ids_to_event( response_ids, event_id) print('response_ids:', response_ids) print('filtered_response_ids:', filtered_response_ids) if set(filtered_response_ids) != set(response_ids): return FORBIDDEN event = event_repository.get_by_id(event_id) reviewer_user = user_repository.get_by_email(reviewer_email, g.organisation.id) if reviewer_user is None: return USER_NOT_FOUND if not reviewer_user.is_reviewer(event_id): _add_reviewer_role(reviewer_user.id, event_id) response_reviewers = [ ResponseReviewer(response_id, reviewer_user.id) for response_id in response_ids ] db.session.add_all(response_reviewers) db.session.commit() if len(response_ids) > 0: email_user('reviews-assigned', template_parameters=dict( num_reviews=len(response_ids), baobab_host=misc.get_baobab_host(), system_name=g.organisation.system_name, event_key=event.key), event=event, user=reviewer_user) return {}, 201
def get(self): email = request.args.get('email') LOGGER.debug("Resending verification email to: {}".format(email)) user = user_repository.get_by_email(email, g.organisation.id) if not user: LOGGER.debug( "User not found for email: {} in organisation: {}".format( email, g.organisation.name)) return USER_NOT_FOUND if user.verify_token is None: user.verify_token = make_code() try: db.session.commit() except IntegrityError: LOGGER.error("Adding verify token for {} failed. ".format(email)) return ADD_VERIFY_TOKEN_FAILED send_mail(recipient=user.email, sender_name=g.organisation.name, sender_email=g.organisation.email_from, subject='{} Email Verification'.format( g.organisation.system_name), body_text=VERIFY_EMAIL_BODY.format( title=user.user_title, firstname=user.firstname, lastname=user.lastname, system=g.organisation.system_name, organisation=g.organisation.name, host=misc.get_baobab_host(), token=user.verify_token)) LOGGER.debug("Resent email verification to: {}".format(email)) return {}, 201
def post(self): req_parser = reqparse.RequestParser() req_parser.add_argument('email', type=str, required=True) args = req_parser.parse_args() LOGGER.debug( "Requesting password reset for email {} and organisation {}". format(args['email'], g.organisation.name)) user = user_repository.get_by_email(args['email'], g.organisation.id) if not user: LOGGER.debug( "No user found for email {} and organisation {}".format( args['email'], g.organisation.name)) return USER_NOT_FOUND password_reset = PasswordReset(user=user) db.session.add(password_reset) db.session.commit() send_mail(recipient=args['email'], sender_name=g.organisation.name, sender_email=g.organisation.email_from, subject='Password Reset for {}'.format( g.organisation.system_name), body_text=RESET_EMAIL_BODY.format( title=user.user_title, firstname=user.firstname, lastname=user.lastname, system=g.organisation.system_name, organisation=g.organisation.name, host=misc.get_baobab_host(), token=password_reset.code)) return {}, 201