Esempio n. 1
0
def perform_request_display_msg(uid, msgid, ln=CFG_SITE_LANG):
    """
    Displays a specific message
    @param uid:   user id
    @param msgid: message id

    @return: a (body, errors[], warnings[]) formed tuple
    """
    errors = []
    warnings = []
    body = ""

    if (db.check_user_owns_message(uid, msgid) == 0):
        # The user doesn't own this message
        errors.append(('ERR_WEBMESSAGE_NOTOWNER', ))
    else:
        (msg_id, msg_from_id, msg_from_nickname, msg_sent_to,
         msg_sent_to_group, msg_subject, msg_body, msg_sent_date,
         msg_received_date, msg_status) = db.get_message(uid, msgid)

        if (msg_id == ""):
            # The message exists in table user_msgMESSAGE
            # but not in table msgMESSAGE => table inconsistency
            errors.append(('ERR_WEBMESSAGE_NOMESSAGE', ))
        else:
            if (msg_status == CFG_WEBMESSAGE_STATUS_CODE['NEW']):
                db.set_message_status(uid, msgid,
                                      CFG_WEBMESSAGE_STATUS_CODE['READ'])
            body = webmessage_templates.tmpl_display_msg(
                msg_id, msg_from_id, msg_from_nickname, msg_sent_to,
                msg_sent_to_group, msg_subject, msg_body, msg_sent_date,
                msg_received_date, ln)
    return (body, errors, warnings)
Esempio n. 2
0
def perform_request_write(uid,
                          msg_reply_id="",
                          msg_to="",
                          msg_to_group="",
                          msg_subject="",
                          msg_body="",
                          ln=CFG_SITE_LANG):
    """
    Display a write a message page.

    @param uid: user id.
    @type uid: int
    @param msg_reply_id: if this message is a reply to another, other's ID.
    @type msg_reply_id: int
    @param msg_to: comma separated usernames.
    @type msg_to: string
    @param msg_to_group: comma separated groupnames.
    @type msg_to_group: string
    @param msg_subject: message subject.
    @type msg_subject: string
    @param msg_body: message body.
    @type msg_body: string
    @param ln: language.
    @type ln: string
    @return: (body, errors, warnings).
    @rtype: tuple
    """
    errors = []
    warnings = []
    body = ""

    msg_from_nickname = ""
    msg_id = 0
    if (msg_reply_id):
        if (db.check_user_owns_message(uid, msg_reply_id) == 0):
            # The user doesn't own this message
            errors.append(('ERR_WEBMESSAGE_NOTOWNER',))
        else:
            # dummy == variable name to make pylint and pychecker happy!
            (msg_id,
             msg_from_id, msg_from_nickname,
             dummy, dummy,
             msg_subject, msg_body,
             dummy, dummy, dummy) = db.get_message(uid, msg_reply_id)
            if (msg_id == ""):
                # The message exists in table user_msgMESSAGE
                # but not in table msgMESSAGE => table inconsistency
                errors.append(('ERR_WEBMESSAGE_NOMESSAGE',))
            else:
                msg_to = msg_from_nickname or str(msg_from_id)

    body = webmessage_templates.tmpl_write(msg_to=msg_to,
                                           msg_to_group=msg_to_group,
                                           msg_id=msg_id,
                                           msg_subject=msg_subject,
                                           msg_body=msg_body,
                                           warnings=[],
                                           ln=ln)
    return (body, errors, warnings)
Esempio n. 3
0
def perform_request_write(uid,
                          msg_reply_id="",
                          msg_to="",
                          msg_to_group="",
                          msg_subject="",
                          msg_body="",
                          ln=CFG_SITE_LANG):
    """
    Display a write a message page.

    @param uid: user id.
    @type uid: int
    @param msg_reply_id: if this message is a reply to another, other's ID.
    @type msg_reply_id: int
    @param msg_to: comma separated usernames.
    @type msg_to: string
    @param msg_to_group: comma separated groupnames.
    @type msg_to_group: string
    @param msg_subject: message subject.
    @type msg_subject: string
    @param msg_body: message body.
    @type msg_body: string
    @param ln: language.
    @type ln: string
    @return: body with warnings.
    """
    warnings = []
    body = ""
    _ = gettext_set_language(ln)
    msg_from_nickname = ""
    msg_id = 0
    if (msg_reply_id):
        if (db.check_user_owns_message(uid, msg_reply_id) == 0):
            # The user doesn't own this message
            try:
                raise InvenioWebMessageError(_('Sorry, this message is not in your mailbox.'))
            except InvenioWebMessageError, exc:
                register_exception()
                body = webmessage_templates.tmpl_error(exc.message, ln)
                return body
        else:
            # dummy == variable name to make pylint and pychecker happy!
            (msg_id,
             msg_from_id, msg_from_nickname,
             dummy, dummy,
             msg_subject, msg_body,
             dummy, dummy, dummy) = db.get_message(uid, msg_reply_id)
            if (msg_id == ""):
                # The message exists in table user_msgMESSAGE
                # but not in table msgMESSAGE => table inconsistency
                try:
                    raise InvenioWebMessageError(_('This message does not exist.'))
                except InvenioWebMessageError, exc:
                    register_exception()
                    body = webmessage_templates.tmpl_error(exc.message, ln)
                    return body
            else:
Esempio n. 4
0
def perform_request_write(uid,
                          msg_reply_id="",
                          msg_to="",
                          msg_to_group="",
                          msg_subject="",
                          msg_body="",
                          ln=CFG_SITE_LANG):
    """
    Display a write a message page.

    @param uid: user id.
    @type uid: int
    @param msg_reply_id: if this message is a reply to another, other's ID.
    @type msg_reply_id: int
    @param msg_to: comma separated usernames.
    @type msg_to: string
    @param msg_to_group: comma separated groupnames.
    @type msg_to_group: string
    @param msg_subject: message subject.
    @type msg_subject: string
    @param msg_body: message body.
    @type msg_body: string
    @param ln: language.
    @type ln: string
    @return: body with warnings.
    """
    warnings = []
    body = ""
    _ = gettext_set_language(ln)
    msg_from_nickname = ""
    msg_id = 0
    if (msg_reply_id):
        if (db.check_user_owns_message(uid, msg_reply_id) == 0):
            # The user doesn't own this message
            try:
                raise InvenioWebMessageError(
                    _('Sorry, this message in not in your mailbox.'))
            except InvenioWebMessageError, exc:
                register_exception()
                body = webmessage_templates.tmpl_error(exc.message, ln)
                return body
        else:
            # dummy == variable name to make pylint and pychecker happy!
            (msg_id, msg_from_id, msg_from_nickname, dummy, dummy, msg_subject,
             msg_body, dummy, dummy,
             dummy) = db.get_message(uid, msg_reply_id)
            if (msg_id == ""):
                # The message exists in table user_msgMESSAGE
                # but not in table msgMESSAGE => table inconsistency
                try:
                    raise InvenioWebMessageError(
                        _('This message does not exist.'))
                except InvenioWebMessageError, exc:
                    register_exception()
                    body = webmessage_templates.tmpl_error(exc.message, ln)
                    return body
            else:
Esempio n. 5
0
def perform_request_write(uid,
                          msg_reply_id="",
                          msg_to="",
                          msg_to_group="",
                          msg_subject="",
                          msg_body="",
                          ln=CFG_SITE_LANG):
    """
    Display a write a message page.

    @param uid: user id.
    @type uid: int
    @param msg_reply_id: if this message is a reply to another, other's ID.
    @type msg_reply_id: int
    @param msg_to: comma separated usernames.
    @type msg_to: string
    @param msg_to_group: comma separated groupnames.
    @type msg_to_group: string
    @param msg_subject: message subject.
    @type msg_subject: string
    @param msg_body: message body.
    @type msg_body: string
    @param ln: language.
    @type ln: string
    @return: (body, errors, warnings).
    @rtype: tuple
    """
    errors = []
    warnings = []
    body = ""

    msg_from_nickname = ""
    msg_id = 0
    if (msg_reply_id):
        if (db.check_user_owns_message(uid, msg_reply_id) == 0):
            # The user doesn't own this message
            errors.append(('ERR_WEBMESSAGE_NOTOWNER', ))
        else:
            # dummy == variable name to make pylint and pychecker happy!
            (msg_id, msg_from_id, msg_from_nickname, dummy, dummy, msg_subject,
             msg_body, dummy, dummy,
             dummy) = db.get_message(uid, msg_reply_id)
            if (msg_id == ""):
                # The message exists in table user_msgMESSAGE
                # but not in table msgMESSAGE => table inconsistency
                errors.append(('ERR_WEBMESSAGE_NOMESSAGE', ))
            else:
                msg_to = msg_from_nickname or str(msg_from_id)

    body = webmessage_templates.tmpl_write(msg_to=msg_to,
                                           msg_to_group=msg_to_group,
                                           msg_id=msg_id,
                                           msg_subject=msg_subject,
                                           msg_body=msg_body,
                                           warnings=[],
                                           ln=ln)
    return (body, errors, warnings)
Esempio n. 6
0
def perform_request_display_msg(uid, msgid, ln=CFG_SITE_LANG):
    """
    Displays a specific message
    @param uid:   user id
    @param msgid: message id

    @return: a (body, errors[], warnings[]) formed tuple
    """
    errors = []
    warnings = []
    body = ""

    if (db.check_user_owns_message(uid, msgid) == 0):
        # The user doesn't own this message
        errors.append(('ERR_WEBMESSAGE_NOTOWNER',))
    else:
        (msg_id,
         msg_from_id, msg_from_nickname,
         msg_sent_to, msg_sent_to_group,
         msg_subject, msg_body,
         msg_sent_date, msg_received_date,
         msg_status) = db.get_message(uid, msgid)

        if (msg_id == ""):
            # The message exists in table user_msgMESSAGE
            # but not in table msgMESSAGE => table inconsistency
            errors.append(('ERR_WEBMESSAGE_NOMESSAGE',))
        else:
            if (msg_status == CFG_WEBMESSAGE_STATUS_CODE['NEW']):
                db.set_message_status(uid, msgid,
                                      CFG_WEBMESSAGE_STATUS_CODE['READ'])
            body = webmessage_templates.tmpl_display_msg(
                                                msg_id,
                                                msg_from_id,
                                                msg_from_nickname,
                                                msg_sent_to,
                                                msg_sent_to_group,
                                                msg_subject,
                                                msg_body,
                                                msg_sent_date,
                                                msg_received_date,
                                                ln)
    return (body, errors, warnings)
Esempio n. 7
0
def perform_request_display_msg(uid, msgid, ln=CFG_SITE_LANG):
    """
    Displays a specific message
    @param uid:   user id
    @param msgid: message id

    @return: body
    """
    _ = gettext_set_language(ln)

    body = ""

    if (db.check_user_owns_message(uid, msgid) == 0):
        # The user doesn't own this message
        try:
            raise InvenioWebMessageError(_('Sorry, this message is not in your mailbox.'))
        except InvenioWebMessageError, exc:
            register_exception()
            body = webmessage_templates.tmpl_error(exc.message, ln)
            return body
Esempio n. 8
0
def perform_request_display_msg(uid, msgid, ln=CFG_SITE_LANG):
    """
    Displays a specific message
    @param uid:   user id
    @param msgid: message id

    @return: body
    """
    _ = gettext_set_language(ln)

    body = ""

    if (db.check_user_owns_message(uid, msgid) == 0):
        # The user doesn't own this message
        try:
            raise InvenioWebMessageError(
                _('Sorry, this message in not in your mailbox.'))
        except InvenioWebMessageError, exc:
            register_exception()
            body = webmessage_templates.tmpl_error(exc.message, ln)
            return body
Esempio n. 9
0
def perform_request_delete_msg(uid, msgid, ln=CFG_SITE_LANG):
    """
    Delete a given message from user inbox
    @param uid: user id (int)
    @param msgid: message id (int)
    @param ln: language
    @return: body with warnings
    """
    _ = gettext_set_language(ln)

    warnings = []
    infos = []
    body = ""

    if (db.check_user_owns_message(uid, msgid) == 0):
        # The user doesn't own this message
        try:
            raise InvenioWebMessageError(_('Sorry, this message is not in your mailbox.'))
        except InvenioWebMessageError, exc:
            register_exception()
            body = webmessage_templates.tmpl_error(exc.message, ln)
            return body
Esempio n. 10
0
def perform_request_delete_msg(uid, msgid, ln=CFG_SITE_LANG):
    """
    Delete a given message from user inbox
    @param uid: user id (int)
    @param msgid: message id (int)
    @param ln: language
    @return: body with warnings
    """
    _ = gettext_set_language(ln)

    warnings = []
    infos = []
    body = ""

    if (db.check_user_owns_message(uid, msgid) == 0):
        # The user doesn't own this message
        try:
            raise InvenioWebMessageError(
                _('Sorry, this message in not in your mailbox.'))
        except InvenioWebMessageError, exc:
            register_exception()
            body = webmessage_templates.tmpl_error(exc.message, ln)
            return body
Esempio n. 11
0
def perform_request_delete_msg(uid, msgid, ln=CFG_SITE_LANG):
    """
    Delete a given message from user inbox
    @param uid: user id (int)
    @param msgid: message id (int)
    @param ln: language
    @return: a (body, errors, warning tuple)
    """
    _ = gettext_set_language(ln)

    errors = []
    warnings = []
    infos = []

    if (db.check_user_owns_message(uid, msgid) == 0):
        # The user doesn't own this message
        errors.append(('ERR_WEBMESSAGE_NOTOWNER', ))
    else:
        if (db.delete_message_from_user_inbox(uid, msgid) == 0):
            warnings.append(_("The message could not be deleted."))
        else:
            infos.append(_("The message was successfully deleted."))
    return perform_request_display(uid, errors, warnings, infos, ln)
Esempio n. 12
0
def perform_request_delete_msg(uid, msgid, ln=CFG_SITE_LANG):
    """
    Delete a given message from user inbox
    @param uid: user id (int)
    @param msgid: message id (int)
    @param ln: language
    @return: a (body, errors, warning tuple)
    """
    _ = gettext_set_language(ln)

    errors = []
    warnings = []
    infos = []

    if (db.check_user_owns_message(uid, msgid) == 0):
        # The user doesn't own this message
        errors.append(('ERR_WEBMESSAGE_NOTOWNER',))
    else:
        if (db.delete_message_from_user_inbox(uid, msgid) == 0):
            warnings.append(_("The message could not be deleted."))
        else:
            infos.append(_("The message was successfully deleted."))
    return perform_request_display(uid, errors, warnings, infos, ln)
Esempio n. 13
0
def add(msg_reply_id):
    uid = current_user.get_id()
    if msg_reply_id:
        if (dbplayer.check_user_owns_message(uid, msg_reply_id) == 0):
            flash(_('Sorry, this message in not in your mailbox.'), "error")
            return redirect(url_for('.index'))
        else:
            try:
                m = dbquery.get_message(uid, msg_reply_id)
                message = MsgMESSAGE()
                message.sent_to_user_nicks = m.message.user_from.nickname \
                    or str(m.message.id_user_from)
                message.subject = _("Re:") + " " + m.message.subject
                message.body = email_quote_txt(m.message.body)
                form = AddMsgMESSAGEForm(request.form, obj=message)
                return render_template('webmessage_add.html', form=form)
            except db.sqlalchemy.orm.exc.NoResultFound:
                # The message exists in table user_msgMESSAGE
                # but not in table msgMESSAGE => table inconsistency
                flash(_('This message does not exist.'), "error")
            except:
                flash(_('Problem with loading message.'), "error")

            return redirect(url_for('.index'))

    form = AddMsgMESSAGEForm(request.values)
    if form.validate_on_submit():
        m = MsgMESSAGE()
        form.populate_obj(m)
        m.id_user_from = uid
        m.sent_date = datetime.now()
        quotas = dbplayer.check_quota(CFG_WEBMESSAGE_MAX_NB_OF_MESSAGES - 1)
        users = filter(lambda x: quotas.has_key(x.id), m.recipients)
        #m.recipients = m.recipients.difference(users))
        for u in users:
            m.recipients.remove(u)
        if len(users) > 0:
            flash(_('Following users reached their quota %d messages: %s') % \
                  (CFG_WEBMESSAGE_MAX_NB_OF_MESSAGES, ', '.join(
                  [u.nickname for u in users]),), "error")
        flash(_('Message has %d valid recipients.') %
              (len(m.recipients),), "info")
        if len(m.recipients) == 0:
            flash(_('Message was not sent'), "info")
        else:
            if m.received_date is not None \
                and m.received_date > datetime.now():

                for um in m.sent_to_users:
                    um.status = CFG_WEBMESSAGE_STATUS_CODE['REMINDER']
            else:
                m.received_date = datetime.now()
            try:
                db.session.add(m)
                db.session.commit()
                flash(_('Message was sent'), "info")
                return redirect(url_for('.index'))
            except:
                db.session.rollback()

    return render_template('webmessage_add.html', form=form)