예제 #1
0
    def send_message_to_all_contributors(project_id: int,
                                         message_dto: MessageDTO):
        """  Sends supplied message to all contributors on specified project.  Message all contributors can take
             over a minute to run, so this method is expected to be called on its own thread """

        app = create_app(
        )  # Because message-all run on background thread it needs it's own app context

        with app.app_context():
            contributors = Message.get_all_contributors(project_id)

            project_link = MessageService.get_project_link(project_id)

            message_dto.message = f'{project_link}<br/><br/>' + message_dto.message  # Append project link to end of message

            msg_count = 0
            for contributor in contributors:
                message = Message.from_dto(contributor[0], message_dto)
                message.save()
                user = UserService.get_user_by_id(contributor[0])
                SMTPService.send_email_alert(user.email_address, user.username)
                msg_count += 1
                if msg_count == 10:
                    time.sleep(
                        0.5
                    )  # Sleep for 0.5 seconds to avoid hitting AWS rate limits every 10 messages
                    msg_count = 0
    def send_message_after_chat(chat_from: int, chat: str, project_id: int):
        """ Send alert to user if they were @'d in a chat message """
        current_app.logger.debug('Sending Message After Chat')
        usernames = MessageService._parse_message_for_username(chat)

        if len(usernames) == 0:
            return  # Nobody @'d so return

        link = MessageService.get_project_link(project_id)

        for username in usernames:
            current_app.logger.debug(f'Searching for {username}')
            try:
                user = UserService.get_user_by_username(username)
            except NotFound:
                current_app.logger.error(f'Username {username} not found')
                continue  # If we can't find the user, keep going no need to fail

            message = Message()
            message.message_type = MessageType.MENTION_NOTIFICATION.value
            message.project_id = project_id
            message.from_user_id = chat_from
            message.to_user_id = user.id
            message.subject = f'You were mentioned in Project Chat on {link}'
            message.message = chat
            message.add_message()
            SMTPService.send_email_alert(user.email_address, user.username)
    def send_message_to_all_contributors(project_id: int, message_dto: MessageDTO):
        """ Sends supplied message to all contributors on specified project """
        contributors = Message.get_all_contributors(project_id)

        for contributor in contributors:
            message = Message.from_dto(contributor[0], message_dto)
            message.save()
            user = UserService.get_user_by_id(contributor[0])
            SMTPService.send_email_alert(user.email_address, user.username)
예제 #4
0
    def send_message_to_all_contributors(project_id: int, message_dto: MessageDTO):
        """ Sends supplied message to all contributors on specified project """
        contributors = Message.get_all_contributors(project_id)

        project_link = MessageService.get_project_link(project_id)

        message_dto.message = f'{project_link}<br/><br/>' + message_dto.message  # Append project link to end of message

        for contributor in contributors:
            message = Message.from_dto(contributor[0], message_dto)
            message.save()
            user = UserService.get_user_by_id(contributor[0])
            SMTPService.send_email_alert(user.email_address, user.username)
예제 #5
0
    def send_message_after_validation(status: int, validated_by: int,
                                      mapped_by: int, task_id: int,
                                      project_id: int):
        """ Sends mapper a notification after their task has been marked valid or invalid """
        if validated_by == mapped_by:
            return  # No need to send a message to yourself

        user = UserService.get_user_by_id(mapped_by)
        if user.validation_message == False:
            return  # No need to send validation message

        text_template = get_template('invalidation_message_en.txt' if status == TaskStatus.INVALIDATED \
                                                                   else 'validation_message_en.txt')
        status_text = 'marked invalid' if status == TaskStatus.INVALIDATED else 'validated'
        task_link = MessageService.get_task_link(project_id, task_id)

        text_template = text_template.replace('[USERNAME]', user.username)
        text_template = text_template.replace('[TASK_LINK]', task_link)

        validation_message = Message()
        validation_message.from_user_id = validated_by
        validation_message.to_user_id = mapped_by
        validation_message.subject = f'Your mapping in Project {project_id} on {task_link} has just been {status_text}'
        validation_message.message = text_template
        validation_message.add_message()

        SMTPService.send_email_alert(user.email_address, user.username)
예제 #6
0
    def send_message_after_comment(comment_from: int, comment: str,
                                   task_id: int, project_id: int):
        """ Will send a canned message to anyone @'d in a comment """
        usernames = MessageService._parse_message_for_username(comment)

        if len(usernames) == 0:
            return  # Nobody @'d so return

        task_link = MessageService.get_task_link(project_id, task_id)
        project_title = ProjectService.get_project_title(project_id)
        for username in usernames:

            try:
                user = UserService.get_user_by_username(username)
            except NotFound:
                current_app.logger.error(f'Username {username} not found')
                continue  # If we can't find the user, keep going no need to fail

            message = Message()
            message.from_user_id = comment_from
            message.to_user_id = user.id
            message.subject = f'You were mentioned in a comment in Project {project_id} on {task_link}'
            message.message = comment
            message.add_message()
            SMTPService.send_email_alert(user.email_address, user.username)
예제 #7
0
    def has_user_new_messages(user_id: int) -> dict:
        """ Determines if the user has any unread messages """
        count = Message.get_unread_message_count(user_id)

        new_messages = False
        if count > 0:
            new_messages = True

        return dict(newMessages=new_messages, unread=count)
    def send_message_to_all_contributors(project_id: int,
                                         message_dto: MessageDTO):
        """ Sends supplied message to all contributors on specified project """
        contributors = Message.get_all_contributors(project_id)

        project_link = MessageService.get_project_link(project_id)

        message_dto.message = f'{project_link}<br/><br/>' + message_dto.message  # Append project link to end of message

        msg_count = 0
        for contributor in contributors:
            message = Message.from_dto(contributor[0], message_dto)
            message.save()
            user = UserService.get_user_by_id(contributor[0])
            SMTPService.send_email_alert(user.email_address, user.username)
            msg_count += 1
            if msg_count == 5:
                time.sleep(
                    0.5
                )  # Sleep for 0.5 seconds to avoid hitting AWS rate limits every 5 messages
                msg_count = 0
예제 #9
0
    def notify_level_upgrade(user_id: int, username: str, level: str):
        text_template = get_template('level_upgrade_message_en.txt')

        if username is not None:
            text_template = text_template.replace('[USERNAME]', username)

        text_template = text_template.replace('[LEVEL]', level)
        level_upgrade_message = Message()
        level_upgrade_message.to_user_id = user_id
        level_upgrade_message.subject = 'Mapper Level Upgrade '
        level_upgrade_message.message = text_template
        level_upgrade_message.save()
    def send_welcome_message(user: User):
        """ Sends welcome message to all new users at Sign up"""
        text_template = get_template('welcome_message_en.txt')

        text_template = text_template.replace('[USERNAME]', user.username)
        text_template = text_template.replace('[PROFILE_LINK]',
                                              get_profile_url(user.username))

        welcome_message = Message()
        welcome_message.message_type = MessageType.SYSTEM.value
        welcome_message.to_user_id = user.id
        welcome_message.subject = 'Welcome to the HOT Tasking Manager'
        welcome_message.message = text_template
        welcome_message.save()

        return welcome_message.id
    def send_message_after_validation(validated_by: int, mapped_by: int, task_id: int, project_id: int):
        """ Sends mapper a thank you, after their task has been marked as valid """
        if validated_by == mapped_by:
            return  # No need to send a thankyou to yourself

        text_template = get_template('validation_message_en.txt')
        task_link = MessageService.get_task_link(project_id, task_id)

        user = UserService.get_user_by_id(mapped_by)
        text_template = text_template.replace('[USERNAME]', user.username)
        text_template = text_template.replace('[TASK_LINK]', task_link)

        validation_message = Message()
        validation_message.from_user_id = validated_by
        validation_message.to_user_id = mapped_by
        validation_message.subject = f'Your mapping on {task_link} has just been validated'
        validation_message.message = text_template
        validation_message.add_message()

        SMTPService.send_email_alert(user.email_address, user.username)
예제 #12
0
 def get_all_messages(user_id: int):
     """ Get all messages for user """
     return Message.get_all_messages(user_id)
 def delete_multiple_messages(message_ids: list, user_id: int):
     """ Deletes the specified messages to the user """
     Message.delete_multiple_messages(message_ids, user_id)