def test_getting_nb_new_msg(self):
     """webmessage - count the nb of new message"""
     delete_all_messages(5)
     # juliet writes the message to romeo
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi romeo",
                                     msg_body="hello romeo how are you?",
                                    ln=CFG_SITE_LANG)
     self.assertEqual(get_nb_new_messages_for_user(5), 1)
 def test_delete_message_from_user_inbox(self):
     """webmessage - delete message from user inbox"""
     delete_all_messages(5)
     # juliet writes a message to romeo
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi romeo",
                                     msg_body="hello romeo how are you?",
                                    ln=CFG_SITE_LANG)
     msg_id = get_all_messages_for_user(5)[0][0]
     delete_message_from_user_inbox(5, msg_id)
     self.assertEqual(count_nb_messages(5), 0)
Ejemplo n.º 3
0
 def test_check_quota(self):
     """webmessage - you give a quota, it returns users over-quota"""
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi jekyll",
                                     msg_body="hello how are you?",
                                    ln=CFG_SITE_LANG)
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi jekyll",
                                     msg_body="hello how are you?",
                                    ln=CFG_SITE_LANG)
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi jekyll",
                                     msg_body="hello how are you?",
                                    ln=CFG_SITE_LANG)
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi jekyll",
                                     msg_body="hello how are you?",
                                    ln=CFG_SITE_LANG)
     d = check_quota(3)
     self.assertEqual(d.keys()[0], 2)
     delete_all_messages(2)
 def test_check_quota(self):
     """webmessage - you give a quota, it returns users over-quota"""
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi jekyll",
                                     msg_body="hello how are you?",
                                    ln=CFG_SITE_LANG)
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi jekyll",
                                     msg_body="hello how are you?",
                                    ln=CFG_SITE_LANG)
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi jekyll",
                                     msg_body="hello how are you?",
                                    ln=CFG_SITE_LANG)
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi jekyll",
                                     msg_body="hello how are you?",
                                    ln=CFG_SITE_LANG)
     d = check_quota(3)
     self.assertEqual(d.keys()[0], 2)
     delete_all_messages(2)
 def test_sending_message(self):
     """webmessage - send and receive a message"""
     # juliet writes the message to romeo
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi romeo",
                                     msg_body="hello romeo how are you?",
                                     ln=CFG_SITE_LANG)
     # it is verified that romeo received the message
     result = get_all_messages_for_user(5)
     self.assertEqual("Hi romeo", result[0][3])
     self.assertEqual("juliet", result[0][2])
     webmessage.perform_request_delete_msg(5, result[0][0], ln=CFG_SITE_LANG)
Ejemplo n.º 6
0
 def test_sending_message(self):
     """webmessage - send and receive a message"""
     # juliet writes the message to romeo
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi romeo",
                                     msg_body="hello romeo how are you?",
                                     ln=CFG_SITE_LANG)
     # it is verified that romeo received the message
     result = get_all_messages_for_user(5)
     self.assertEqual("Hi romeo", result[0][3])
     self.assertEqual("juliet", result[0][2])
     webmessage.perform_request_delete_msg(5, result[0][0], ln=CFG_SITE_LANG)
 def test_getting_nb_readable_messages(self):
     """webmessage - get the nb of readable messages"""
     delete_all_messages(5)
     # juliet writes the message to romeo
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi romeo",
                                     msg_body="hello romeo how are you?",
                                    ln=CFG_SITE_LANG)
     msgid =  get_all_messages_for_user(5)[0][0]
     # status is changed
     set_message_status(5, msgid, 'R')
     self.assertEqual(get_nb_readable_messages_for_user(5), 1)
     webmessage.perform_request_delete_msg(5, msgid, ln=CFG_SITE_LANG)
Ejemplo n.º 8
0
 def test_getting_nb_readable_messages(self):
     """webmessage - get the nb of readable messages"""
     delete_all_messages(5)
     # juliet writes the message to romeo
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi romeo",
                                     msg_body="hello romeo how are you?",
                                    ln=CFG_SITE_LANG)
     msgid =  get_all_messages_for_user(5)[0][0]
     # status is changed
     set_message_status(5, msgid, 'R')
     self.assertEqual(get_nb_readable_messages_for_user(5), 1)
     webmessage.perform_request_delete_msg(5, msgid, ln=CFG_SITE_LANG)
 def test_setting_message_status(self):
     """webmessage - status from "new" to "read" """
     # juliet writes the message to romeo
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi romeo",
                                     msg_body="hello romeo how are you?",
                                    ln=CFG_SITE_LANG)
     msgid =  get_all_messages_for_user(5)[0][0]
     # status is changed
     set_message_status(5, msgid, 'R')
     msgstatus = get_all_messages_for_user(5)[0][5]
     self.assertEqual(msgstatus, 'R')
     webmessage.perform_request_delete_msg(5, msgid, ln=CFG_SITE_LANG)
Ejemplo n.º 10
0
 def test_setting_message_status(self):
     """webmessage - status from "new" to "read" """
     # juliet writes the message to romeo
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi romeo",
                                     msg_body="hello romeo how are you?",
                                    ln=CFG_SITE_LANG)
     msgid =  get_all_messages_for_user(5)[0][0]
     # status is changed
     set_message_status(5, msgid, 'R')
     msgstatus = get_all_messages_for_user(5)[0][5]
     self.assertEqual(msgstatus, 'R')
     webmessage.perform_request_delete_msg(5, msgid, ln=CFG_SITE_LANG)
Ejemplo n.º 11
0
def perform_request_add_member(uid, grpID, user_id, ln=CFG_SITE_LANG):
    """Add waiting member to a group.
    @param uid: user ID
    @param grpID: ID of the group
    @param user_id: selected member ID
    @param ln: language
    @return: a (body, errors[], warnings[]) formed tuple
    """
    body = ''
    errors = []
    warnings = []
    infos = []
    _ = gettext_set_language(ln)
    user_status = db.get_user_status(uid, grpID)
    if not len(user_status):
        errors.append('ERR_WEBSESSION_DB_ERROR')
        return (body, errors, warnings)
    if user_id == -1:
        warnings.append('WRN_WEBSESSION_NO_USER_SELECTED_ADD')
        (body, errors, warnings) = perform_request_manage_member(uid,
            grpID,
            warnings=warnings,
            ln=ln)
    else :
        # test if user is already member or pending
        status = db.get_user_status(user_id, grpID)
        if status and status[0][0] == 'M':
            warnings.append('WRN_WEBSESSION_ALREADY_MEMBER_ADD')
            (body, errors, warnings) = perform_request_manage_member(uid,
                grpID,
                infos=infos,
                warnings=warnings,
                ln=ln)


        else:
            db.add_pending_member(grpID,
                user_id,
                CFG_WEBSESSION_USERGROUP_STATUS["MEMBER"])

            infos.append(CFG_WEBSESSION_INFO_MESSAGES["MEMBER_ADDED"])
            group_infos = db.get_group_infos(grpID)
            group_name = group_infos[0][1]
            user = get_user_info(user_id, ln)[2]
            msg_subjet, msg_body = websession_templates.tmpl_member_msg(
                group_name=group_name, accepted=1, ln=ln)
            (body, errors, warnings, dummy, dummy) = perform_request_send(
                uid, msg_to_user=user, msg_to_group="", msg_subject=msg_subjet,
                msg_body=msg_body, ln=ln)
            (body, errors, warnings) = perform_request_manage_member(uid,
                grpID,
                infos=infos,
                warnings=warnings,
                ln=ln)


    return (body, errors, warnings)
Ejemplo n.º 12
0
def perform_request_join_group(uid, grpID, group_name, search, ln=CFG_SITE_LANG):
    """Join group.
    @param grpID: list of the groups the user wants to join,
    only one value must be selected among the two group lists
    (default group list, group list resulting from the search)
    @param group_name: name of the group entered if search on name performed
    @param search=1 if search performed else 0
    @param ln: language
    @return: a (body, errors[], warnings[]) formed tuple
    warnings != [] if 0 or more than one group is selected
    """
    _ = gettext_set_language(ln)
    body = ""
    warnings = []
    errors = []
    infos = []

    if "-1" in grpID:
        grpID = filter(lambda x: x != "-1", grpID)
    if len(grpID) == 1:
        grpID = int(grpID[0])
        # test if user is already member or pending
        status = db.get_user_status(uid, grpID)
        if status:
            warnings.append("WRN_WEBSESSION_ALREADY_MEMBER")

            (body, errors, warnings) = perform_request_groups_display(
                uid, infos=infos, errors=errors, warnings=warnings, ln=ln
            )
            # insert new user of group
        else:
            group_infos = db.get_group_infos(grpID)
            group_type = group_infos[0][3]
            if group_type == CFG_WEBSESSION_GROUP_JOIN_POLICY["VISIBLEMAIL"]:
                db.insert_new_member(uid, grpID, CFG_WEBSESSION_USERGROUP_STATUS["PENDING"])
                admin = db.get_users_by_status(grpID, CFG_WEBSESSION_USERGROUP_STATUS["ADMIN"])[0][1]
                group_name = group_infos[0][1]
                msg_subjet, msg_body = websession_templates.tmpl_admin_msg(group_name=group_name, grpID=grpID, ln=ln)
                (body, errors, warnings, dummy, dummy) = perform_request_send(
                    uid, msg_to_user=admin, msg_to_group="", msg_subject=msg_subjet, msg_body=msg_body, ln=ln
                )
                infos.append(CFG_WEBSESSION_INFO_MESSAGES["JOIN_REQUEST"])

            elif group_type == CFG_WEBSESSION_GROUP_JOIN_POLICY["VISIBLEOPEN"]:
                db.insert_new_member(uid, grpID, CFG_WEBSESSION_USERGROUP_STATUS["MEMBER"])

                infos.append(CFG_WEBSESSION_INFO_MESSAGES["JOIN_GROUP"])
            (body, errors, warnings) = perform_request_groups_display(
                uid, infos=infos, errors=errors, warnings=warnings, ln=ln
            )
    else:
        warnings.append("WRN_WEBSESSION_MULTIPLE_GROUPS")
        (body, errors, warnings) = perform_request_input_join_group(uid, group_name, search, warnings, ln)
    return (body, errors, warnings)
Ejemplo n.º 13
0
 def test_count_nb_message(self):
     """webmessage - count the number of messages"""
     delete_all_messages(5)
     # juliet writes 3 messages to romeo
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi romeo",
                                     msg_body="hello romeo how are you?",
                                    ln=CFG_SITE_LANG)
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi romeo",
                                     msg_body="hello romeo how are you?",
                                    ln=CFG_SITE_LANG)
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi romeo",
                                     msg_body="hello romeo how are you?",
                                    ln=CFG_SITE_LANG)
     self.assertEqual(count_nb_messages(5), 3)
     delete_all_messages(5)
     self.assertEqual(count_nb_messages(5), 0)
 def test_count_nb_message(self):
     """webmessage - count the number of messages"""
     delete_all_messages(5)
     # juliet writes 3 messages to romeo
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi romeo",
                                     msg_body="hello romeo how are you?",
                                    ln=CFG_SITE_LANG)
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi romeo",
                                     msg_body="hello romeo how are you?",
                                    ln=CFG_SITE_LANG)
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi romeo",
                                     msg_body="hello romeo how are you?",
                                    ln=CFG_SITE_LANG)
     self.assertEqual(count_nb_messages(5), 3)
     delete_all_messages(5)
     self.assertEqual(count_nb_messages(5), 0)
 def test_getting_all_messages_for_user(self):
     """webmessage - get all message for user"""
     delete_all_messages(5)
     # juliet writes 3 messages to romeo
     webmessage.perform_request_send(
         6,
         msg_to_user="******",
         msg_to_group="",
         msg_subject="Hi romeo",
         msg_body="hello romeo how are you?",
         ln=CFG_SITE_LANG,
     )
     webmessage.perform_request_send(
         6,
         msg_to_user="******",
         msg_to_group="",
         msg_subject="Hi romeo",
         msg_body="hello romeo how are you?",
         ln=CFG_SITE_LANG,
     )
     webmessage.perform_request_send(
         6,
         msg_to_user="******",
         msg_to_group="",
         msg_subject="Hi romeo",
         msg_body="hello romeo how are you?",
         ln=CFG_SITE_LANG,
     )
     self.assertEqual(len(get_all_messages_for_user(5)), 3)
     delete_all_messages(5)
Ejemplo n.º 16
0
def  perform_request_delete_group(uid, grpID, confirmed=0, ln=CFG_SITE_LANG):
    """First display confirm message(confirmed=0).
    then(confirmed=1) delete group and all its members
    @param uid: user ID
    @param grpID: ID of the group
    @param confirmed: =1 if confirmed message has been previously displayed
    @param ln: language
    @return: a (body, errors[], warnings[]) formed tuple
    """
    body = ""
    warnings = []
    errors = []
    infos = []
    _ = gettext_set_language(ln)
    group_infos = db.get_group_infos(grpID)
    user_status = db.get_user_status(uid, grpID)
    if not group_infos:
        warnings.append('WRN_WEBSESSION_GROUP_ALREADY_DELETED')
        (body, errors, warnings) = perform_request_groups_display(uid,
            infos=infos,
            errors=errors,
            warnings=warnings,
            ln=CFG_SITE_LANG)
    else:
        if not len(user_status):
            errors.append('ERR_WEBSESSION_DB_ERROR')
        elif confirmed:
            group_infos = db.get_group_infos(grpID)
            group_name = group_infos[0][1]
            msg_subjet, msg_body = websession_templates.tmpl_delete_msg(
                group_name=group_name, ln=ln)
            (body, errors, warnings, dummy, dummy) = perform_request_send(
                uid,
                msg_to_user="",
                msg_to_group=group_name,
                msg_subject=msg_subjet,
                msg_body=msg_body,
                ln=ln)
            db.delete_group_and_members(grpID)
            infos.append(CFG_WEBSESSION_INFO_MESSAGES["GROUP_DELETED"])
            (body, errors, warnings) = perform_request_groups_display(uid,
                infos=infos,
                errors=errors,
                warnings=warnings,
                ln=CFG_SITE_LANG)
        else:
            body = websession_templates.tmpl_confirm_delete(grpID, ln)

    return (body, errors, warnings)
Ejemplo n.º 17
0
def perform_request_reject_member(uid, grpID, user_id, ln=CFG_SITE_LANG):
    """Reject waiting member and delete it from the list.
    @param uid: user ID
    @param grpID: ID of the group
    @param member_id: selected member ID
    @param ln: language
    @return: a (body, errors[], warnings[]) formed tuple
    """
    body = ""
    errors = []
    warnings = []
    infos = []
    _ = gettext_set_language(ln)
    user_status = db.get_user_status(uid, grpID)
    if not len(user_status):
        errors.append("ERR_WEBSESSION_DB_ERROR")
        return (body, errors, warnings)
    if user_id == -1:
        warnings.append("WRN_WEBSESSION_NO_USER_SELECTED_DEL")
        (body, errors, warnings) = perform_request_manage_member(uid, grpID, warnings=warnings, ln=ln)
    else:
        # test if user is already member or pending
        status = db.get_user_status(user_id, grpID)
        if not status:
            warnings.append("WRN_WEBSESSION_ALREADY_MEMBER_REJECT")
            (body, errors, warnings) = perform_request_manage_member(uid, grpID, infos=infos, warnings=warnings, ln=ln)
        else:
            db.delete_member(grpID, user_id)
            group_infos = db.get_group_infos(grpID)
            group_name = group_infos[0][1]
            user = get_user_info(user_id, ln)[2]
            msg_subjet, msg_body = websession_templates.tmpl_member_msg(group_name=group_name, accepted=0, ln=ln)
            (body, errors, warnings, dummy, dummy) = perform_request_send(
                uid, msg_to_user=user, msg_to_group="", msg_subject=msg_subjet, msg_body=msg_body, ln=ln
            )
            infos.append(CFG_WEBSESSION_INFO_MESSAGES["MEMBER_REJECTED"])
            (body, errors, warnings) = perform_request_manage_member(uid, grpID, infos=infos, warnings=warnings, ln=ln)

    return (body, errors, warnings)
Ejemplo n.º 18
0
 def test_getting_all_messages_for_user(self):
     """webmessage - get all message for user"""
     delete_all_messages(5)
     # juliet writes 3 messages to romeo
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi romeo",
                                     msg_body="hello romeo how are you?",
                                    ln=CFG_SITE_LANG)
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi romeo",
                                     msg_body="hello romeo how are you?",
                                    ln=CFG_SITE_LANG)
     webmessage.perform_request_send(6,
                                     msg_to_user="******",
                                     msg_to_group="",
                                     msg_subject="Hi romeo",
                                     msg_body="hello romeo how are you?",
                                    ln=CFG_SITE_LANG)
     self.assertEqual(len(get_all_messages_for_user(5)), 3)
     delete_all_messages(5)
    def send(self, req, form):
        """
        Sends the message.

        Possible form keys:
        @param msg_to_user: comma separated usernames.
        @type msg_to_user: 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 msg_send_year: year to send this message on.
        @type msg_send_year: int
        @param_msg_send_month: month to send this message on
        @type msg_send_month: year
        @param_msg_send_day: day to send this message on
        @type msg_send_day: int
        @param results_field: value determining which results field to display.
                              See CFG_WEBMESSAGE_RESULTS_FIELD in
                              webmessage_config.py.
        @param names_to_add: list of usernames to add to
                             msg_to_user / group.
        @type names_to_add: list of strings
        @param search_pattern: will search for users/groups with this pattern.
        @type search_pattern: string
        @param add_values: if 1 users_to_add will be added to msg_to_user
                           field.
        @type add_values: int
        @param *button: which button was pressed.
        @param ln: language.
        @type ln: string
        @return: a (body, errors, warnings) formed tuple.
        @rtype: tuple
        """
        argd = wash_urlargd(
            form, {
                'msg_to_user': (str, ""),
                'msg_to_group': (str, ""),
                'msg_subject': (str, ""),
                'msg_body': (str, ""),
                'msg_send_year': (int, 0),
                'msg_send_month': (int, 0),
                'msg_send_day': (int, 0),
                'results_field': (str, CFG_WEBMESSAGE_RESULTS_FIELD['NONE']),
                'names_selected': (list, []),
                'search_pattern': (str, ""),
                'send_button': (str, ""),
                'search_user': (str, ""),
                'search_group': (str, ""),
                'add_user': (str, ""),
                'add_group': (str, ""),
            })
        # Check if user is logged
        uid = getUid(req)
        _ = gettext_set_language(argd['ln'])
        if CFG_ACCESS_CONTROL_LEVEL_SITE >= 1:
            return page_not_authorized(req, "%s/yourmessages/send" % \
                                             (CFG_SITE_URL,),
                                       navmenuid="yourmessages")
        elif uid == -1 or isGuestUser(uid):
            return redirect_to_url(
                req, "%s/youraccount/login%s" %
                (CFG_SITE_SECURE_URL,
                 make_canonical_urlargd(
                     {
                         'referer':
                         "%s/yourmessages/send%s" %
                         (CFG_SITE_URL, make_canonical_urlargd(argd, {})),
                         "ln":
                         argd['ln']
                     }, {})))

        user_info = collect_user_info(req)
        if not user_info['precached_usemessages']:
            return page_not_authorized(req, "../", \
                                       text = _("You are not authorized to use messages."))

        if argd['send_button']:
            (body, errors, warnings, title, navtrail) = perform_request_send(
                uid=uid,
                msg_to_user=argd['msg_to_user'],
                msg_to_group=argd['msg_to_group'],
                msg_subject=escape_html(argd['msg_subject']),
                msg_body=escape_email_quoted_text(argd['msg_body']),
                msg_send_year=argd['msg_send_year'],
                msg_send_month=argd['msg_send_month'],
                msg_send_day=argd['msg_send_day'],
                ln=argd['ln'])
        else:
            title = _('Write a message')
            navtrail = get_navtrail(argd['ln'], title)
            if argd['search_user']:
                argd['results_field'] = CFG_WEBMESSAGE_RESULTS_FIELD['USER']
            elif argd['search_group']:
                argd['results_field'] = CFG_WEBMESSAGE_RESULTS_FIELD['GROUP']
            add_values = 0
            if argd['add_group'] or argd['add_user']:
                add_values = 1
            (body, errors, warnings) = perform_request_write_with_search(
                uid=uid,
                msg_to_user=argd['msg_to_user'],
                msg_to_group=argd['msg_to_group'],
                msg_subject=escape_html(argd['msg_subject']),
                msg_body=escape_email_quoted_text(argd['msg_body']),
                msg_send_year=argd['msg_send_year'],
                msg_send_month=argd['msg_send_month'],
                msg_send_day=argd['msg_send_day'],
                names_selected=argd['names_selected'],
                search_pattern=argd['search_pattern'],
                results_field=argd['results_field'],
                add_values=add_values,
                ln=argd['ln'])
        return page(title=title,
                    body=body,
                    navtrail=navtrail,
                    uid=uid,
                    lastupdated=__lastupdated__,
                    req=req,
                    language=argd['ln'],
                    errors=errors,
                    warnings=warnings,
                    navmenuid="yourmessages",
                    secure_page_p=1)
    def send(self, req, form):
        """
        Sends the message.

        Possible form keys:
        @param msg_to_user: comma separated usernames.
        @type msg_to_user: 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 msg_send_year: year to send this message on.
        @type msg_send_year: int
        @param_msg_send_month: month to send this message on
        @type msg_send_month: year
        @param_msg_send_day: day to send this message on
        @type msg_send_day: int
        @param results_field: value determining which results field to display.
                              See CFG_WEBMESSAGE_RESULTS_FIELD in
                              webmessage_config.py.
        @param names_to_add: list of usernames to add to
                             msg_to_user / group.
        @type names_to_add: list of strings
        @param search_pattern: will search for users/groups with this pattern.
        @type search_pattern: string
        @param add_values: if 1 users_to_add will be added to msg_to_user
                           field.
        @type add_values: int
        @param *button: which button was pressed.
        @param ln: language.
        @type ln: string
        @return: body.
        """
        argd = wash_urlargd(form, {'msg_to_user': (str, ""),
                                   'msg_to_group': (str, ""),
                                   'msg_subject': (str, ""),
                                   'msg_body': (str, ""),
                                   'msg_send_year': (int, 0),
                                   'msg_send_month': (int, 0),
                                   'msg_send_day': (int, 0),
                                   'results_field': (str,
                                        CFG_WEBMESSAGE_RESULTS_FIELD['NONE']),
                                   'names_selected': (list, []),
                                   'search_pattern': (str, ""),
                                   'send_button': (str, ""),
                                   'search_user': (str, ""),
                                   'search_group': (str, ""),
                                   'add_user': (str, ""),
                                   'add_group': (str, ""),
                                   })
        # Check if user is logged
        uid = getUid(req)
        _ = gettext_set_language(argd['ln'])
        if CFG_ACCESS_CONTROL_LEVEL_SITE >= 1:
            return page_not_authorized(req, "%s/yourmessages/send" % \
                                             (CFG_SITE_URL,),
                                       navmenuid="yourmessages")
        elif uid == -1 or isGuestUser(uid):
            return redirect_to_url(req, "%s/youraccount/login%s" % (
                CFG_SITE_SECURE_URL,
                make_canonical_urlargd({
                    'referer' : "%s/yourmessages/send%s" % (
                        CFG_SITE_URL,
                        make_canonical_urlargd(argd, {})),
                    "ln" : argd['ln']}, {})))

        user_info = collect_user_info(req)
        if not user_info['precached_usemessages']:
            return page_not_authorized(req, "../", \
                                       text = _("You are not authorized to use messages."))

        if argd['send_button']:
            (body, title, navtrail) = perform_request_send(
                            uid=uid,
                            msg_to_user=argd['msg_to_user'],
                            msg_to_group=argd['msg_to_group'],
                            msg_subject=escape_html(argd['msg_subject']),
                            msg_body=escape_email_quoted_text(argd['msg_body']),
                            msg_send_year=argd['msg_send_year'],
                            msg_send_month=argd['msg_send_month'],
                            msg_send_day=argd['msg_send_day'],
                            ln=argd['ln'])
        else:
            title = _('Write a message')
            navtrail = get_navtrail(argd['ln'], title)
            if argd['search_user']:
                argd['results_field'] = CFG_WEBMESSAGE_RESULTS_FIELD['USER']
            elif argd['search_group']:
                argd['results_field'] = CFG_WEBMESSAGE_RESULTS_FIELD['GROUP']
            add_values = 0
            if argd['add_group'] or argd['add_user']:
                add_values = 1
            body = perform_request_write_with_search(
                            uid=uid,
                            msg_to_user=argd['msg_to_user'],
                            msg_to_group=argd['msg_to_group'],
                            msg_subject=escape_html(argd['msg_subject']),
                            msg_body=escape_email_quoted_text(argd['msg_body']),
                            msg_send_year=argd['msg_send_year'],
                            msg_send_month=argd['msg_send_month'],
                            msg_send_day=argd['msg_send_day'],
                            names_selected=argd['names_selected'],
                            search_pattern=argd['search_pattern'],
                            results_field=argd['results_field'],
                            add_values=add_values,
                            ln=argd['ln'])
        return page(title       = title,
                    body        = body,
                    navtrail    = navtrail,
                    uid         = uid,
                    lastupdated = __lastupdated__,
                    req         = req,
                    language    = argd['ln'],
                    navmenuid   = "yourmessages",
                    secure_page_p=1)
Ejemplo n.º 21
0
def perform_request_join_group(uid,
                               grpID,
                               group_name,
                               search,
                               ln=CFG_SITE_LANG):
    """Join group.
    @param grpID: list of the groups the user wants to join,
    only one value must be selected among the two group lists
    (default group list, group list resulting from the search)
    @param group_name: name of the group entered if search on name performed
    @param search=1 if search performed else 0
    @param ln: language
    @return: body with warnings
    warnings != [] if 0 or more than one group is selected
    """
    _ = gettext_set_language(ln)
    body = ""
    warnings = []
    infos = []

    if "-1" in grpID:
        grpID = filter(lambda x: x != '-1', grpID)
    if len(grpID)==1 :
        grpID = int(grpID[0])
        # test if user is already member or pending
        status = db.get_user_status(uid, grpID)
        if status:
            try:
                raise InvenioWebSessionWarning(_('You are already member of the group.'))
            except InvenioWebSessionWarning, exc:
                register_exception(stream='warning')
                warnings.append(exc.message)
            body = perform_request_groups_display(uid,
                                                  infos=infos,
                                                  warnings=warnings,
                                                  ln=ln)
            # insert new user of group
        else:
            group_infos = db.get_group_infos(grpID)
            group_type = group_infos[0][3]
            if group_type == CFG_WEBSESSION_GROUP_JOIN_POLICY["VISIBLEMAIL"]:
                db.insert_new_member(uid,
                    grpID,
                    CFG_WEBSESSION_USERGROUP_STATUS["PENDING"])
                admin = db.get_users_by_status(grpID,
                    CFG_WEBSESSION_USERGROUP_STATUS["ADMIN"])[0][1]
                group_name = group_infos[0][1]
                msg_subjet, msg_body = websession_templates.tmpl_admin_msg(
                    group_name=group_name,
                    grpID=grpID,
                    ln=ln)
                (body, dummy, dummy) = \
                    perform_request_send(uid,
                                         msg_to_user=admin,
                                         msg_to_group="",
                                         msg_subject=msg_subjet,
                                         msg_body=msg_body,
                                         ln=ln)
                infos.append(CFG_WEBSESSION_INFO_MESSAGES["JOIN_REQUEST"])
            elif group_type == CFG_WEBSESSION_GROUP_JOIN_POLICY["VISIBLEOPEN"]:
                db.insert_new_member(uid,
                    grpID,
                    CFG_WEBSESSION_USERGROUP_STATUS["MEMBER"])
                infos.append(CFG_WEBSESSION_INFO_MESSAGES["JOIN_GROUP"])
            body = perform_request_groups_display(uid,
                infos=infos,
                warnings=warnings,
                ln=ln)
Ejemplo n.º 22
0
            warnings.append(exc.message)
        body = perform_request_groups_display(uid, infos=infos, warnings=warnings, ln=CFG_SITE_LANG)
    else:
        if not len(user_status):
            try:
                raise InvenioWebSessionError(_("Sorry, there was an error with the database."))
            except InvenioWebSessionError, exc:
                register_exception()
                body = websession_templates.tmpl_error(exc.message, ln)
                return body
        elif confirmed:
            group_infos = db.get_group_infos(grpID)
            group_name = group_infos[0][1]
            msg_subjet, msg_body = websession_templates.tmpl_delete_msg(group_name=group_name, ln=ln)
            (body, dummy, dummy) = perform_request_send(
                uid, msg_to_user="", msg_to_group=group_name, msg_subject=msg_subjet, msg_body=msg_body, ln=ln
            )
            db.delete_group_and_members(grpID)
            infos.append(CFG_WEBSESSION_INFO_MESSAGES["GROUP_DELETED"])
            body = perform_request_groups_display(uid, infos=infos, warnings=warnings, ln=CFG_SITE_LANG)
        else:
            body = websession_templates.tmpl_confirm_delete(grpID, ln)
    return body


def perform_request_manage_member(uid, grpID, infos=[], warnings=[], ln=CFG_SITE_LANG):
    """Return html for managing group's members.
    @param uid: user ID
    @param grpID: ID of the group
    @param info: info about last user action
    @param warnings: warnings
    def send(self, req, form):
        """
        Sends the message.

        Possible form keys:
        @param msg_to_user: comma separated usernames.
        @type msg_to_user: 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 msg_send_year: year to send this message on.
        @type msg_send_year: int
        @param_msg_send_month: month to send this message on
        @type msg_send_month: year
        @param_msg_send_day: day to send this message on
        @type msg_send_day: int
        @param results_field: value determining which results field to display.
                              See CFG_WEBMESSAGE_RESULTS_FIELD in
                              webmessage_config.py.
        @param names_to_add: list of usernames to add to
                             msg_to_user / group.
        @type names_to_add: list of strings
        @param search_pattern: will search for users/groups with this pattern.
        @type search_pattern: string
        @param add_values: if 1 users_to_add will be added to msg_to_user
                           field.
        @type add_values: int
        @param *button: which button was pressed.
        @param ln: language.
        @type ln: string
        @return: a (body, errors, warnings) formed tuple.
        @rtype: tuple
        """
        argd = wash_urlargd(
            form,
            {
                "msg_to_user": (str, ""),
                "msg_to_group": (str, ""),
                "msg_subject": (str, ""),
                "msg_body": (str, ""),
                "msg_send_year": (int, 0),
                "msg_send_month": (int, 0),
                "msg_send_day": (int, 0),
                "results_field": (str, CFG_WEBMESSAGE_RESULTS_FIELD["NONE"]),
                "names_selected": (list, []),
                "search_pattern": (str, ""),
                "send_button": (str, ""),
                "search_user": (str, ""),
                "search_group": (str, ""),
                "add_user": (str, ""),
                "add_group": (str, ""),
            },
        )
        # Check if user is logged
        uid = getUid(req)
        _ = gettext_set_language(argd["ln"])
        if CFG_ACCESS_CONTROL_LEVEL_SITE >= 1:
            return page_not_authorized(req, "%s/yourmessages/send" % (CFG_SITE_URL,), navmenuid="yourmessages")
        elif uid == -1 or isGuestUser(uid):
            return redirect_to_url(
                req,
                "%s/youraccount/login%s"
                % (
                    CFG_SITE_SECURE_URL,
                    make_canonical_urlargd(
                        {
                            "referer": "%s/yourmessages/send%s" % (CFG_SITE_URL, make_canonical_urlargd(argd, {})),
                            "ln": argd["ln"],
                        },
                        {},
                    ),
                ),
            )

        user_info = collect_user_info(req)
        if not user_info["precached_usemessages"]:
            return page_not_authorized(req, "../", text=_("You are not authorized to use messages."))

        if argd["send_button"]:
            (body, errors, warnings, title, navtrail) = perform_request_send(
                uid=uid,
                msg_to_user=argd["msg_to_user"],
                msg_to_group=argd["msg_to_group"],
                msg_subject=escape_html(argd["msg_subject"]),
                msg_body=escape_email_quoted_text(argd["msg_body"]),
                msg_send_year=argd["msg_send_year"],
                msg_send_month=argd["msg_send_month"],
                msg_send_day=argd["msg_send_day"],
                ln=argd["ln"],
            )
        else:
            title = _("Write a message")
            navtrail = get_navtrail(argd["ln"], title)
            if argd["search_user"]:
                argd["results_field"] = CFG_WEBMESSAGE_RESULTS_FIELD["USER"]
            elif argd["search_group"]:
                argd["results_field"] = CFG_WEBMESSAGE_RESULTS_FIELD["GROUP"]
            add_values = 0
            if argd["add_group"] or argd["add_user"]:
                add_values = 1
            (body, errors, warnings) = perform_request_write_with_search(
                uid=uid,
                msg_to_user=argd["msg_to_user"],
                msg_to_group=argd["msg_to_group"],
                msg_subject=escape_html(argd["msg_subject"]),
                msg_body=escape_email_quoted_text(argd["msg_body"]),
                msg_send_year=argd["msg_send_year"],
                msg_send_month=argd["msg_send_month"],
                msg_send_day=argd["msg_send_day"],
                names_selected=argd["names_selected"],
                search_pattern=argd["search_pattern"],
                results_field=argd["results_field"],
                add_values=add_values,
                ln=argd["ln"],
            )
        return page(
            title=title,
            body=body,
            navtrail=navtrail,
            uid=uid,
            lastupdated=__lastupdated__,
            req=req,
            language=argd["ln"],
            errors=errors,
            warnings=warnings,
            navmenuid="yourmessages",
        )
Ejemplo n.º 24
0
def perform_request_join_group(uid,
                               grpID,
                               group_name,
                               search,
                               ln=CFG_SITE_LANG):
    """Join group.
    @param grpID: list of the groups the user wants to join,
    only one value must be selected among the two group lists
    (default group list, group list resulting from the search)
    @param group_name: name of the group entered if search on name performed
    @param search=1 if search performed else 0
    @param ln: language
    @return: body with warnings
    warnings != [] if 0 or more than one group is selected
    """
    _ = gettext_set_language(ln)
    body = ""
    warnings = []
    infos = []

    if "-1" in grpID:
        grpID = filter(lambda x: x != '-1', grpID)
    if len(grpID) == 1:
        grpID = int(grpID[0])
        # test if user is already member or pending
        status = db.get_user_status(uid, grpID)
        if status:
            try:
                raise InvenioWebSessionWarning(
                    _('You are already member of the group.'))
            except InvenioWebSessionWarning, exc:
                register_exception(stream='warning')
                warnings.append(exc.message)
            body = perform_request_groups_display(uid,
                                                  infos=infos,
                                                  warnings=warnings,
                                                  ln=ln)
            # insert new user of group
        else:
            group_infos = db.get_group_infos(grpID)
            group_type = group_infos[0][3]
            if group_type == CFG_WEBSESSION_GROUP_JOIN_POLICY["VISIBLEMAIL"]:
                db.insert_new_member(
                    uid, grpID, CFG_WEBSESSION_USERGROUP_STATUS["PENDING"])
                admin = db.get_users_by_status(
                    grpID, CFG_WEBSESSION_USERGROUP_STATUS["ADMIN"])[0][1]
                group_name = group_infos[0][1]
                msg_subjet, msg_body = websession_templates.tmpl_admin_msg(
                    group_name=group_name, grpID=grpID, ln=ln)
                (body, dummy, dummy) = \
                    perform_request_send(uid,
                                         msg_to_user=admin,
                                         msg_to_group="",
                                         msg_subject=msg_subjet,
                                         msg_body=msg_body,
                                         ln=ln)
                infos.append(CFG_WEBSESSION_INFO_MESSAGES["JOIN_REQUEST"])
            elif group_type == CFG_WEBSESSION_GROUP_JOIN_POLICY["VISIBLEOPEN"]:
                db.insert_new_member(uid, grpID,
                                     CFG_WEBSESSION_USERGROUP_STATUS["MEMBER"])
                infos.append(CFG_WEBSESSION_INFO_MESSAGES["JOIN_GROUP"])
            body = perform_request_groups_display(uid,
                                                  infos=infos,
                                                  warnings=warnings,
                                                  ln=ln)
Ejemplo n.º 25
0
            try:
                raise InvenioWebSessionError(
                    _('Sorry, there was an error with the database.'))
            except InvenioWebSessionError, exc:
                register_exception()
                body = websession_templates.tmpl_error(exc.message, ln)
                return body
        elif confirmed:
            group_infos = db.get_group_infos(grpID)
            group_name = group_infos[0][1]
            msg_subjet, msg_body = websession_templates.tmpl_delete_msg(
                group_name=group_name, ln=ln)
            (body, dummy,
             dummy) = perform_request_send(uid,
                                           msg_to_user="",
                                           msg_to_group=group_name,
                                           msg_subject=msg_subjet,
                                           msg_body=msg_body,
                                           ln=ln)
            db.delete_group_and_members(grpID)
            infos.append(CFG_WEBSESSION_INFO_MESSAGES["GROUP_DELETED"])
            body = perform_request_groups_display(uid,
                                                  infos=infos,
                                                  warnings=warnings,
                                                  ln=CFG_SITE_LANG)
        else:
            body = websession_templates.tmpl_confirm_delete(grpID, ln)
    return body


def perform_request_manage_member(uid,
                                  grpID,