Index: openacs-4/packages/acs-subsite/www/register/user-join.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-subsite/www/register/user-join.tcl,v diff -u -r1.7 -r1.8 --- openacs-4/packages/acs-subsite/www/register/user-join.tcl 10 Oct 2003 16:35:03 -0000 1.7 +++ openacs-4/packages/acs-subsite/www/register/user-join.tcl 30 Jan 2004 15:16:27 -0000 1.8 @@ -11,127 +11,130 @@ } { {group_id:integer {[application_group::group_id_from_package_id]}} {rel_type:notnull "membership_rel"} - { return_url "[ad_conn package_url]" } + {return_url {}} } -properties { context:onevalue role_pretty_name:onevalue group_name:onevalue export_form_vars:onevalue } -validate { rel_type_valid_p { - if {![relation_type_is_valid_to_group_p -group_id $group_id $rel_type]} { + if { ![relation_type_is_valid_to_group_p -group_id $group_id $rel_type] } { ad_complain "[_ acs-subsite.lt_Cannot_join_this_grou]" } } } +set user_id [auth::require_login] -# Randy O'Meara - 8/6/03 - Changes: -# o added ad_maybe_redirect_for_registration as we must have a valid user_id -# to join to the specified (or defaulted) group. -# o changed ad_complain calls to ad_return_complaint with a 'return' to the -# caller. These ad_complain calls were outside the ad_page_contract 'validate' -# block so they did nothing at all. -# o any failure now generates a slightly more descriptive reason for the -# failure. -# o added a link to each ad_return_complaint error message that allows the user -# to click and return to the calling page. That is, only if return_url was -# passed in the query vars. -# o added code to check for and display an error regarding joining a group in which -# the user is already a member. This code simply checks for for a unique constraint -# violation message contained in the received error message. +group::get -group_id $group_id -array group_info -# Must have a valid user_id. The Unregistered User can't join groups. -ad_maybe_redirect_for_registration +# Need these as local vars for some of the message keys below +set group_name $group_info(group_name) +set join_policy $group_info(join_policy) -db_1row group_info {} -if {![empty_string_p $return_url]} { +if { [exists_and_not_null return_url] } { set ret_link "Return to previous page." } else { set ret_link "" } -if {[string equal $join_policy closed]} { - ad_complain "[_ acs-subsite.lt_Cannot_join_this_grou] $ret_link" +if { [string equal $join_policy closed] } { + ad_return_error [_ acs-subsite.Closed_group] "[_ acs-subsite.This_group_is_closed]
$ret_link" + ad_script_abort } -set export_var_list [list group_id rel_type return_url] - -set party_id [ad_conn user_id] - set context [list "[_ acs-subsite.Join_group_name]"] +#---------------------------------------------------------------------- +# Build up a form asking for relevant attributes +#---------------------------------------------------------------------- + template::form create join relation_required_segments_multirow \ -datasource_name required_segments \ -group_id $group_id \ -rel_type $rel_type +set num_required_segments [multirow size required_segments] -set num_required_segments [template::multirow size required_segments] - -if {[template::form is_request join]} { - - for {set rownum 1} {$rownum <= $num_required_segments } {incr rownum} { - set required_seg [template::multirow get required_segments $rownum] +if { [form is_request join] } { + for { set rownum 1 } { $rownum <= $num_required_segments } { incr rownum } { + set required_seg [multirow get required_segments $rownum] - if { [string equal $required_segments(join_policy) closed] && ![group::member_p -group_id $required_segments(group_id)] } { - ad_return_complaint 1 "Cannot join this group - segment closed to all applicants. $ret_link" - return + if { ![group::member_p -group_id $required_segments(group_id)] } { + if { [string equal $required_segments(join_policy) "closed"] } { + ad_return_error [_ acs-subsite.Closed_group] "[_ acs-subsite.This_group_is_closed]
$ret_link" + ad_script_abort + } + + attribute::add_form_elements \ + -form_id join \ + -variable_prefix seg_$required_segments(segment_id) \ + -start_with relationship \ + -object_type $required_segments(rel_type) } - - set segment_id $required_segments(segment_id) - set cur_group_id $required_segments(group_id) - set cur_rel_type $required_segments(rel_type) - - attribute::add_form_elements -form_id join -variable_prefix seg_$segment_id -start_with relationship -object_type $cur_rel_type - } } -attribute::add_form_elements -form_id join -start_with relationship -object_type $rel_type +attribute::add_form_elements \ + -form_id join \ + -start_with relationship \ + -object_type $rel_type -if { [template::form::size join] == 0 } { - # There's no attributes to ask the user for, so just add the user to - # the group (instead of displaying a 0 element form). - set just_do_it_p 1 -} - -foreach var $export_var_list { - template::element create join $var \ +if { [form size join] > 0 } { + foreach var { group_id rel_type return_url } { + template::element create join $var \ -value [set $var] \ -datatype text \ -widget hidden + } } -if { $just_do_it_p || [template::form is_valid join] } { +# Empty form means nothing to ask for, don't have to submit first +if { [form size join] == 0 || [template::form is_valid join] } { db_transaction { - for {set rownum 1} {$rownum <= $num_required_segments } {incr rownum} { + + #---------------------------------------------------------------------- + # Join all required segments + #---------------------------------------------------------------------- + + for { set rownum 1 } { $rownum <= $num_required_segments } { incr rownum } { set required_seg [template::multirow get required_segments $rownum] if { ![group::member_p -group_id $required_segments(group_id)] } { - if { [string equal $required_segments(join_policy) closed] } { - ad_return_complaint 1 "[_ acs-subsite.lt_Cannot_join_this_grou]" - return + switch $required_segments(join_policy) { + "needs approval" { + set member_state "needs approval" + } + "open" { + set member_state "approved" + set return_url [ad_conn package_url] + } + default { + # Should have been caught above + ad_return_error [_ acs-subsite.Closed_group] "[_ acs-subsite.This_group_is_closed]
$ret_link" + ad_script_abort + } } - - if {[string equal $required_segments(join_policy) "needs approval"]} { - set member_state "needs approval" - } else { - set member_state "approved" - } - set segment_id $required_segments(segment_id) - set cur_group_id $required_segments(group_id) - set cur_rel_type $required_segments(rel_type) - - set rel_id [relation_add -form_id join -variable_prefix seg_$segment_id -member_state $member_state $cur_rel_type $cur_group_id $party_id] + set rel_id [relation_add \ + -form_id join \ + -variable_prefix seg_$required_segments(segment_id) \ + -member_state $member_state \ + $required_segments(rel_type) \ + $required_segments(group_id) \ + $user_id] } } - + + #---------------------------------------------------------------------- + # Join the actual group + #---------------------------------------------------------------------- + if { [permission::permission_p -object_id $group_id -privilege "admin"] } { set member_state "approved" if { [string equal $rel_type "membership_rel"] } { @@ -146,22 +149,25 @@ } } - set rel_id [relation_add -form_id join -member_state $member_state $rel_type $group_id $party_id] + group::add_member \ + -group_id $group_id \ + -user_id $user_id \ + -rel_type $rel_type \ + -member_state $member_state } on_error { - set err {} - regexp {\n\nERROR:\s\s(\S.*?)\n.*?\nSQL:\s\n\n\t.*?(\S.*?)\n.*} $errmsg junk err sql - if {[regexp {duplicate.*?unique} $err]} { - set reason "Your application for membership to this group has been previously accepted. " - append reason "It is possible that your application is still awaiting approval. $ret_link" - } else { - set reason "An error was encountered while attempting to add you to this group. " - append reason "
$errmsg$ret_link" - } - ad_return_complaint 1 $reason + global errorInfo + ns_log Error "user-join: Error when adding user to group: $errmsg\n$errorInfo" + + ad_return_error "Error Joining" "We experienced an error adding you to the group." ad_script_abort } + + switch $member_state { + "approved" { set message "You have joined the group \"$group_name\"." } + "needs approval" { set message "Your request to join group \"$group_name\" has been submitted." } + } - ad_returnredirect $return_url - ad_script_abort + + ad_returnredirect -message $message -abort $return_url } Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-subsite/www/register/user-join.xql'. Fisheye: No comparison available. Pass `N' to diff?