Index: openacs-4/packages/dotlrn/www/member-add-3.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/www/member-add-3.tcl,v diff -u -r1.11 -r1.12 --- openacs-4/packages/dotlrn/www/member-add-3.tcl 21 Dec 2006 15:57:53 -0000 1.11 +++ openacs-4/packages/dotlrn/www/member-add-3.tcl 14 Nov 2007 17:07:07 -0000 1.12 @@ -29,23 +29,59 @@ set community_id [dotlrn_community::get_community_id] # See if the user is already in the group -set user_ids_to_email [list] + foreach uid $user_id { set member_p [dotlrn_community::member_p $community_id $uid] + set skip_p 0 if {$member_p} { - dotlrn_community::remove_user $community_id $uid + # get the rel_info + db_1row get_rel_info "" + + # if new rel type is same as old then + # no sense in doing anything + if {$rel_type eq $old_rel_type} { + set skip_p 1 + } + + if {!$skip_p} { + # this is just a change rel + # so we do not want to call remove_user + # as that removes subgroup rels as well + relation_remove $rel_id + util_memoize_flush "dotlrn_community::list_users_not_cached -rel_type $rel_type -community_id $community_id" + } + } else { + # if the user is not a member + # then we could not possibly be + # changing the rel_type so set to 0 + set change_rel_p 0 } - # Add the relation - dotlrn_community::add_user -rel_type $rel_type $community_id $uid - lappend user_ids_to_email $uid + if {!$skip_p} { + if {$change_rel_p} { + # if this is just a change rel then + # no need to call add_user as the user + # has already been added before and + # add_user_to_community should have + # taken care of everything + set extra_vars [ns_set create] + ns_set put $extra_vars user_id $uid + ns_set put $extra_vars community_id $community_id + ns_set put $extra_vars class_instance_id $community_id + relation_add \ + -member_state "approved" \ + -extra_vars $extra_vars \ + $rel_type \ + $community_id \ + $uid + util_memoize_flush "dotlrn_community::list_users_not_cached -rel_type $rel_type -community_id $community_id" + } else { + dotlrn_community::add_user -rel_type $rel_type $community_id $uid + } + } } - -if {[llength $user_ids_to_email]} { - set referer [export_vars -base member-email-confirm {{user_id $user_ids_to_email} community_id {return_url $referer}}] -} ad_returnredirect $referer