Esempio n. 1
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)
Esempio n. 2
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: body with warnings
    """
    body = ""
    warnings = []
    infos = []
    _ = gettext_set_language(ln)
    group_infos = db.get_group_infos(grpID)
    user_status = db.get_user_status(uid, grpID)
    if not group_infos:
        try:
            raise InvenioWebSessionWarning(
                _('The group has already been deleted.'))
        except InvenioWebSessionWarning, exc:
            register_exception(stream='warning')
            warnings.append(exc.message)
        body = perform_request_groups_display(uid,
                                              infos=infos,
                                              warnings=warnings,
                                              ln=CFG_SITE_LANG)
Esempio n. 3
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: body with warnings
    """
    body = ""
    warnings = []
    infos = []
    _ = gettext_set_language(ln)
    group_infos = db.get_group_infos(grpID)
    user_status = db.get_user_status(uid, grpID)
    if not group_infos:
        try:
            raise InvenioWebSessionWarning(_('The group has already been deleted.'))
        except InvenioWebSessionWarning, exc:
            register_exception(stream='warning')
            warnings.append(exc.message)
        body = perform_request_groups_display(uid,
                                              infos=infos,
                                              warnings=warnings,
                                              ln=CFG_SITE_LANG)
Esempio n. 4
0
def perform_request_edit_group(uid, grpID, warnings=[], ln=CFG_SITE_LANG):
    """Return html for group editing.
    @param uid: user ID
    @param grpID: ID of the group
    @param warnings: warnings
    @param ln: language
    @return: a (body, errors[], warnings[]) formed tuple
    """

    body = ""
    errors = []
    user_status = db.get_user_status(uid, grpID)
    if not len(user_status):
        errors.append("ERR_WEBSESSION_DB_ERROR")
        return (body, errors, warnings)
    elif user_status[0][0] != CFG_WEBSESSION_USERGROUP_STATUS["ADMIN"]:
        errors.append(("ERR_WEBSESSION_GROUP_NO_RIGHTS",))
        return (body, errors, warnings)

    group_infos = db.get_group_infos(grpID)[0]
    if not len(group_infos):
        errors.append("ERR_WEBSESSION_DB_ERROR")
        return (body, errors, warnings)

    body = websession_templates.tmpl_display_input_group_info(
        group_name=group_infos[1],
        group_description=group_infos[2],
        join_policy=group_infos[3],
        act_type="update",
        grpID=grpID,
        warnings=warnings,
        ln=ln,
    )

    return (body, errors, warnings)
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
0
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
    @param ln: language
    @return: a (body, errors[], warnings[]) formed tuple
    """
    body = ''
    errors = []
    _ = 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)
    elif user_status[0][0] != CFG_WEBSESSION_USERGROUP_STATUS['ADMIN']:
        errors.append(('ERR_WEBSESSION_GROUP_NO_RIGHTS',))
        return (body, errors, warnings)
    group_infos = db.get_group_infos(grpID)
    if not len(group_infos):
        errors.append('ERR_WEBSESSION_DB_ERROR')
        return (body, errors, warnings)
    members = db.get_users_by_status(grpID,
        CFG_WEBSESSION_USERGROUP_STATUS["MEMBER"])
    pending_members = db.get_users_by_status(grpID,
        CFG_WEBSESSION_USERGROUP_STATUS["PENDING"])

    body = websession_templates.tmpl_display_manage_member(grpID=grpID,
        group_name=group_infos[0][1],
        members=members,
        pending_members=pending_members,
        warnings=warnings,
        infos=infos,
        ln=ln)
    return (body, errors, warnings)
Esempio n. 8
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)
Esempio n. 9
0
def perform_request_edit_group(uid,
        grpID,
        warnings=[],
        ln=CFG_SITE_LANG):
    """Return html for group editing.
    @param uid: user ID
    @param grpID: ID of the group
    @param warnings: warnings
    @param ln: language
    @return: a (body, errors[], warnings[]) formed tuple
    """

    body = ''
    errors = []
    user_status = db.get_user_status(uid, grpID)
    if not len(user_status):
        errors.append('ERR_WEBSESSION_DB_ERROR')
        return (body, errors, warnings)
    elif user_status[0][0] != CFG_WEBSESSION_USERGROUP_STATUS['ADMIN']:
        errors.append(('ERR_WEBSESSION_GROUP_NO_RIGHTS',))
        return (body, errors, warnings)

    group_infos = db.get_group_infos(grpID)[0]
    if not len(group_infos):
        errors.append('ERR_WEBSESSION_DB_ERROR')
        return (body, errors, warnings)

    body = websession_templates.tmpl_display_input_group_info(
        group_name=group_infos[1],
        group_description=group_infos[2],
        join_policy=group_infos[3],
        act_type="update",
        grpID=grpID,
        warnings=warnings,
        ln=ln)

    return (body, errors, warnings)
Esempio n. 10
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)
Esempio n. 11
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 user_status[0][0] != CFG_WEBSESSION_USERGROUP_STATUS['ADMIN']:
     try:
         raise InvenioWebSessionError(
             _('Sorry, you do not have sufficient rights on this group.'))
     except InvenioWebSessionError, exc:
         register_exception()
         body = websession_templates.tmpl_error(exc.message, ln)
         return body
 group_infos = db.get_group_infos(grpID)[0]
 if not len(group_infos):
     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
 body = websession_templates.tmpl_display_input_group_info(
     group_name=group_infos[1],
     group_description=group_infos[2],
     join_policy=group_infos[3],
     act_type="update",
     grpID=grpID,
     warnings=warnings,
Esempio n. 12
0
 user_status = db.get_user_status(uid, grpID)
 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 user_status[0][0] != CFG_WEBSESSION_USERGROUP_STATUS["ADMIN"]:
     try:
         raise InvenioWebSessionError(_("Sorry, you do not have sufficient rights on this group."))
     except InvenioWebSessionError, exc:
         register_exception()
         body = websession_templates.tmpl_error(exc.message, ln)
         return body
 group_infos = db.get_group_infos(grpID)[0]
 if not len(group_infos):
     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
 body = websession_templates.tmpl_display_input_group_info(
     group_name=group_infos[1],
     group_description=group_infos[2],
     join_policy=group_infos[3],
     act_type="update",
     grpID=grpID,
     warnings=warnings,
     ln=ln,
Esempio n. 13
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)