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 as exc: register_exception(stream='warning') 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 as 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 @param ln: language @return: body with warnings """ body = '' _ = gettext_set_language(ln) 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 as 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 as exc: register_exception() body = websession_templates.tmpl_error(exc.message, ln) return body group_infos = db.get_group_infos(grpID) if not len(group_infos): try: raise InvenioWebSessionError(_('Sorry, there was an error with the database.')) except InvenioWebSessionError as exc: register_exception() body = websession_templates.tmpl_error(exc.message, ln) return body 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
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: body with warnings """ body = "" _ = gettext_set_language(ln) 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 as 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 as 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 as 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) return body
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: body with warnings """ body = '' warnings = [] infos = [] _ = gettext_set_language(ln) 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 as exc: register_exception() body = websession_templates.tmpl_error(exc.message, ln) return body if user_id == -1: try: raise InvenioWebSessionWarning(_('Please choose a user from the list if you want him to be removed from waiting list.')) except InvenioWebSessionWarning as exc: register_exception(stream='warning') warnings.append(exc.message) body = 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: try: raise InvenioWebSessionWarning(_('The user request for joining group has already been rejected.')) except InvenioWebSessionWarning as exc: register_exception(stream='warning') warnings.append(exc.message) body = 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, 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 = perform_request_manage_member(uid, grpID, infos=infos, warnings=warnings, ln=ln) return body
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: body with warnings """ body = '' warnings = [] infos = [] _ = gettext_set_language(ln) 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 as exc: register_exception() body = websession_templates.tmpl_error(exc.message, ln) return body if user_id == -1: try: raise InvenioWebSessionWarning(_('Please choose a user from the list if you want him to be added to the group.')) except InvenioWebSessionWarning as exc: register_exception(stream='warning') warnings.append(exc.message) body = 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': try: raise InvenioWebSessionWarning(_('The user is already member of the group.')) except InvenioWebSessionWarning as exc: register_exception(stream='warning') warnings.append(exc.message) body = 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, dummy, dummy) = perform_request_send( uid, msg_to_user=user, msg_to_group="", msg_subject=msg_subjet, msg_body=msg_body, ln=ln) body = perform_request_manage_member(uid, grpID, infos=infos, warnings=warnings, ln=ln) return body
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 as 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) else: try: raise InvenioWebSessionWarning(_('Please select only one group.')) except InvenioWebSessionWarning as exc: register_exception(stream='warning') warnings.append(exc.message) body = perform_request_input_join_group(uid, group_name, search, warnings, ln) return body