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)
def synchronize_external_groups(userid, groups, login_method): """Synchronize external groups adding new groups that aren't already added, adding subscription for userid to groups, for groups that the user isn't already subsribed to, removing subscription to groups the user is no more subsribed to. @param userid, the intger representing the user inside the db @param groups, a dictionary of group_name : group_description @param login_method, a string unique to the type of authentication the groups are associated to, to be used inside the db """ groups_already_known = db.get_login_method_groups(userid, login_method) group_dict = {} for name, groupid in groups_already_known: group_dict[name] = groupid groups_already_known_name = set([g[0] for g in groups_already_known]) groups_name = set(groups.keys()) nomore_groups = groups_already_known_name - groups_name for group in nomore_groups: # delete the user from no more affiliated group db.delete_member(group_dict[group], userid) potential_new_groups = groups_name - groups_already_known_name for group in potential_new_groups: groupid = db.get_group_id(group, login_method) if groupid: # Adding the user to an already existent group db.insert_new_member(userid, groupid[0][0], CFG_WEBSESSION_USERGROUP_STATUS['MEMBER']) else: # Adding a new group try: groupid = db.insert_new_group(userid, group, groups[group], \ CFG_WEBSESSION_GROUP_JOIN_POLICY['VISIBLEEXTERNAL'], \ login_method) db.add_pending_member( groupid, userid, CFG_WEBSESSION_USERGROUP_STATUS['MEMBER']) except IntegrityError: ## The group already exists? Maybe because of concurrency? groupid = db.get_group_id(group, login_method) if groupid: # Adding the user to an already existent group db.insert_new_member( userid, groupid[0][0], CFG_WEBSESSION_USERGROUP_STATUS['MEMBER'])
def synchronize_external_groups(userid, groups, login_method): """Synchronize external groups adding new groups that aren't already added, adding subscription for userid to groups, for groups that the user isn't already subsribed to, removing subscription to groups the user is no more subsribed to. @param userid, the intger representing the user inside the db @param groups, a dictionary of group_name : group_description @param login_method, a string unique to the type of authentication the groups are associated to, to be used inside the db """ groups_already_known = db.get_login_method_groups(userid, login_method) group_dict = {} for name, groupid in groups_already_known: group_dict[name] = groupid groups_already_known_name = set([g[0] for g in groups_already_known]) groups_name = set(groups.keys()) nomore_groups = groups_already_known_name - groups_name for group in nomore_groups: # delete the user from no more affiliated group db.delete_member(group_dict[group], userid) potential_new_groups = groups_name - groups_already_known_name for group in potential_new_groups: groupid = db.get_group_id(group, login_method) if groupid: # Adding the user to an already existent group db.insert_new_member(userid, groupid[0][0], CFG_WEBSESSION_USERGROUP_STATUS['MEMBER']) else: # Adding a new group try: groupid = db.insert_new_group(userid, group, groups[group], \ CFG_WEBSESSION_GROUP_JOIN_POLICY['VISIBLEEXTERNAL'], \ login_method) db.add_pending_member(groupid, userid, CFG_WEBSESSION_USERGROUP_STATUS['MEMBER']) except IntegrityError: ## The group already exists? Maybe because of concurrency? groupid = db.get_group_id(group, login_method) if groupid: # Adding the user to an already existent group db.insert_new_member(userid, groupid[0][0], CFG_WEBSESSION_USERGROUP_STATUS['MEMBER'])
# 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, 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,
except InvenioWebSessionWarning, 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, 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_reject_member(uid, grpID, user_id, ln=CFG_SITE_LANG): """Reject waiting member and delete it from the list. @param uid: user ID