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_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
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_SECURE_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)
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_SECURE_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)