Index: openacs-4/packages/forums/forums.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/forums.info,v diff -u -N -r1.47 -r1.48 --- openacs-4/packages/forums/forums.info 27 Sep 2017 11:07:51 -0000 1.47 +++ openacs-4/packages/forums/forums.info 8 Nov 2017 12:05:55 -0000 1.48 @@ -9,7 +9,7 @@ f t - + OpenACS Online discussion forums. 2017-08-06 @@ -19,7 +19,7 @@ 2 #forums.Forums# - + Index: openacs-4/packages/forums/lib/forums/edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/lib/forums/edit.tcl,v diff -u -N -r1.6 -r1.7 --- openacs-4/packages/forums/lib/forums/edit.tcl 27 Sep 2017 11:07:51 -0000 1.6 +++ openacs-4/packages/forums/lib/forums/edit.tcl 8 Nov 2017 12:05:55 -0000 1.7 @@ -20,37 +20,47 @@ forums::form::forum forum if {[form is_valid forum]} { - template::form get_values forum return_url forum_id name charter presentation_type posting_policy new_threads_p + template::form get_values forum return_url forum_id \ + name charter presentation_type posting_policy new_threads_p anonymous_allowed_p - forum::edit -forum_id $forum_id \ - -name $name \ - -charter [template::util::richtext::get_property contents $charter] \ - -presentation_type $presentation_type \ - -posting_policy $posting_policy - # Users can create new threads? - if { $new_threads_p && $posting_policy ne "closed" } { - forum::new_questions_allow -forum_id $forum_id - } else { - forum::new_questions_deny -forum_id $forum_id - } + set new_questions_allowed_p [expr { $new_threads_p && $posting_policy ne "closed" ? t : f}] + db_transaction { + forum::edit -forum_id $forum_id \ + -name $name \ + -charter [template::util::richtext::get_property contents $charter] \ + -presentation_type $presentation_type \ + -posting_policy $posting_policy \ + -new_questions_allowed_p $new_questions_allowed_p \ + -anonymous_allowed_p $anonymous_allowed_p + } + ad_returnredirect $return_url ad_script_abort } if { [form is_request forum] } { - element set_properties forum return_url -value $return_url - element set_properties forum forum_id -value $forum(forum_id) - element set_properties forum name -value $forum(name) - element set_properties forum charter -value [template::util::richtext create $forum(charter) "text/html"] - element set_properties forum presentation_type -value $forum(presentation_type) - element set_properties forum posting_policy -value $forum(posting_policy) - element set_properties forum new_threads_p -value [forum::new_questions_allowed_p -forum_id $forum(forum_id)] + element set_properties forum return_url \ + -value $return_url + element set_properties forum forum_id \ + -value $forum(forum_id) + element set_properties forum name \ + -value $forum(name) + element set_properties forum charter \ + -value [template::util::richtext create $forum(charter) "text/html"] + element set_properties forum presentation_type \ + -value $forum(presentation_type) + element set_properties forum posting_policy \ + -value $forum(posting_policy) + element set_properties forum new_threads_p \ + -value $forum(new_questions_allowed_p) + element set_properties forum anonymous_allowed_p \ + -value $forum(anonymous_allowed_p) } -if {([info exists alt_template] && $alt_template ne "")} { - ad_return_template $alt_template +if {[info exists alt_template] && $alt_template ne ""} { + ad_return_template $alt_template } # Local variables: Index: openacs-4/packages/forums/lib/forums/new.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/lib/forums/new.tcl,v diff -u -N -r1.8 -r1.9 --- openacs-4/packages/forums/lib/forums/new.tcl 27 Sep 2017 11:07:52 -0000 1.8 +++ openacs-4/packages/forums/lib/forums/new.tcl 8 Nov 2017 12:05:55 -0000 1.9 @@ -26,23 +26,22 @@ if {[form is_valid forum]} { template::form get_values forum \ - forum_id name charter presentation_type posting_policy new_threads_p + forum_id name charter presentation_type posting_policy new_threads_p anonymous_allowed_p - set forum_id [forum::new -forum_id $forum_id \ - -name $name \ - -charter [template::util::richtext::get_property contents $charter] \ - -presentation_type $presentation_type \ - -posting_policy $posting_policy \ - -package_id $package_id \ - ] - # Users can create new threads? - if { $new_threads_p && $posting_policy ne "closed" } { - forum::new_questions_allow -forum_id $forum_id - } else { - forum::new_questions_deny -forum_id $forum_id - } + set new_questions_allowed_p [expr {$new_threads_p && $posting_policy ne "closed" ? t : f}] + db_transaction { + set forum_id [forum::new -forum_id $forum_id \ + -name $name \ + -charter [template::util::richtext::get_property contents $charter] \ + -presentation_type $presentation_type \ + -posting_policy $posting_policy \ + -package_id $package_id \ + -new_questions_allowed_p $new_questions_allowed_p \ + -anonymous_allowed_p $anonymous_allowed_p] + } + ad_returnredirect $return_url ad_script_abort } @@ -51,12 +50,13 @@ # Pre-fetch the forum_id set forum_id [db_nextval acs_object_id_seq] element set_properties forum forum_id -value $forum_id - element set_value forum new_threads_p 1 + element set_value forum new_threads_p t + element set_value forum anonymous_allowed_p f element set_value forum name $name } -if {([info exists alt_template] && $alt_template ne "")} { - ad_return_template $alt_template +if {[info exists alt_template] && $alt_template ne ""} { + ad_return_template $alt_template } # Local variables: Index: openacs-4/packages/forums/sql/oracle/forums-forums-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/sql/oracle/forums-forums-create.sql,v diff -u -N -r1.7 -r1.8 --- openacs-4/packages/forums/sql/oracle/forums-forums-create.sql 27 Sep 2017 11:07:52 -0000 1.7 +++ openacs-4/packages/forums/sql/oracle/forums-forums-create.sql 8 Nov 2017 12:05:55 -0000 1.8 @@ -63,7 +63,13 @@ constraint forums_new_questions_allowed_p_nn not null constraint forums_new_questions_allowed_p_ck - check (enabled_p in ('t','f')), + check (new_questions_allowed_p in ('t','f')), + anonymous_allowed_p char(1) + default 'f' + constraint forums_anonymous_allowed_p_nn + not null + constraint forums_anonymous_allowed_p_ck + check (anonymous_allowed_p in ('t','f')), package_id integer constraint forums_package_id_nn not null, Index: openacs-4/packages/forums/sql/oracle/upgrade/upgrade-1.3.1d1-1.3.1d2.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/sql/oracle/upgrade/upgrade-1.3.1d1-1.3.1d2.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/forums/sql/oracle/upgrade/upgrade-1.3.1d1-1.3.1d2.sql 8 Nov 2017 12:05:55 -0000 1.1 @@ -0,0 +1,27 @@ +begin; + +alter table forums_forums + add anonymous_allowed_p char(1) + default 'f' + constraint forums_anonymous_allowed_p_nn + not null + constraint forums_anonymous_allowed_p_ck + check (anonymous_allowed_p in ('t','f')); + +alter table forums_forums + column new_questions_allowed_p char(1) + default 't' + constraint forums_new_questions_allowed_p_nn + not null + constraint forums_new_questions_allowed_p_ck + check (new_questions_allowed_p in ('t','f')); + +drop view forums_forums_enabled; + +create view forums_forums_enabled +as + select * + from forums_forums + where enabled_p = 't'; + +end; Index: openacs-4/packages/forums/sql/postgresql/forums-forums-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/sql/postgresql/forums-forums-create.sql,v diff -u -N -r1.12 -r1.13 --- openacs-4/packages/forums/sql/postgresql/forums-forums-create.sql 27 Sep 2017 11:07:52 -0000 1.12 +++ openacs-4/packages/forums/sql/postgresql/forums-forums-create.sql 8 Nov 2017 12:05:55 -0000 1.13 @@ -59,6 +59,9 @@ new_questions_allowed_p boolean default true not null, + anonymous_allowed_p boolean + default false + not null, package_id integer constraint forums_package_id_nn not null, Index: openacs-4/packages/forums/sql/postgresql/upgrade/upgrade-1.3.1d1-1.3.1d2.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/sql/postgresql/upgrade/upgrade-1.3.1d1-1.3.1d2.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/forums/sql/postgresql/upgrade/upgrade-1.3.1d1-1.3.1d2.sql 8 Nov 2017 12:05:55 -0000 1.1 @@ -0,0 +1,13 @@ +begin; + +alter table forums_forums + add column anonymous_allowed_p boolean default false not null; + +drop view forums_forums_enabled; +create view forums_forums_enabled +as + select * + from forums_forums + where enabled_p = true; + +end; Index: openacs-4/packages/forums/tcl/form-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/tcl/form-procs.tcl,v diff -u -N -r1.12 -r1.13 --- openacs-4/packages/forums/tcl/form-procs.tcl 7 Aug 2017 23:48:11 -0000 1.12 +++ openacs-4/packages/forums/tcl/form-procs.tcl 8 Nov 2017 12:05:55 -0000 1.13 @@ -173,12 +173,18 @@ -help_text [_ forums.help_posting_policy] \ -options [list [list [_ forums.open] open] [list [_ forums.moderated] moderated] [list [_ forums.closed] closed] ] + template::element create $form_name ${prefix}anonymous_allowed_p \ + -label [_ forums.post_anonymously] \ + -datatype text \ + -widget radio \ + -options [list [list [_ forums.Yes] t] [list [_ forums.No] f] ] + template::element create $form_name ${prefix}new_threads_p \ -label [_ forums.lt_Users_Can_Create_New_] \ - -datatype integer \ + -datatype text \ -widget radio \ -help_text [_ forums.help_new_threads] \ - -options [list [list [_ forums.Yes] 1] [list [_ forums.No] 0] ] + -options [list [list [_ forums.Yes] t] [list [_ forums.No] f] ] } # Local variables: Index: openacs-4/packages/forums/tcl/forums-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/tcl/forums-procs.tcl,v diff -u -N -r1.27 -r1.28 --- openacs-4/packages/forums/tcl/forums-procs.tcl 27 Sep 2017 12:28:10 -0000 1.27 +++ openacs-4/packages/forums/tcl/forums-procs.tcl 8 Nov 2017 12:05:55 -0000 1.28 @@ -18,10 +18,12 @@ {-presentation_type flat} {-posting_policy open} {-package_id:required} + {-new_questions_allowed_p t} + {-anonymous_allowed_p f} -no_callback:boolean } { create a new forum -} { +} { set var_list [list \ [list forum_id $forum_id] \ [list name $name] \ @@ -32,6 +34,13 @@ set forum_id [package_instantiate_object -var_list $var_list forums_forum] + db_dml update_extra_cols { + update forums_forums set + new_questions_allowed_p = :new_questions_allowed_p, + anonymous_allowed_p = :anonymous_allowed_p + where forum_id = :forum_id + } + if {!$no_callback_p} { callback forum::forum_new -package_id $package_id -forum_id $forum_id } @@ -41,14 +50,25 @@ ad_proc -public forum::edit { {-forum_id:required} - {-name:required} - {-charter ""} - {-presentation_type flat} - {-posting_policy open} + -name + -charter + -presentation_type + -posting_policy + -new_questions_allowed_p + -anonymous_allowed_p -no_callback:boolean } { - edit a forum + Edit a forum } { + forum::get -forum_id $forum_id -array forum + foreach var { + name charter presentation_type posting_policy + new_questions_allowed_p anonymous_allowed_p} { + if {![info exists $var]} { + set $var $forum($var) + } + } + # This is a straight DB update db_dml update_forum {} db_dml update_forum_object {} Index: openacs-4/packages/forums/tcl/forums-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/tcl/forums-procs.xql,v diff -u -N -r1.7 -r1.8 --- openacs-4/packages/forums/tcl/forums-procs.xql 15 Jun 2005 17:43:42 -0000 1.7 +++ openacs-4/packages/forums/tcl/forums-procs.xql 8 Nov 2017 12:05:55 -0000 1.8 @@ -3,19 +3,23 @@ - update forums_forums - set name= :name, - charter= :charter, - presentation_type= :presentation_type, - posting_policy= :posting_policy - where forum_id = :forum_id + update forums_forums set + name = :name, + charter = :charter, + presentation_type = :presentation_type, + posting_policy = :posting_policy, + new_questions_allowed_p = :new_questions_allowed_p, + anonymous_allowed_p = :anonymous_allowed_p + where forum_id = :forum_id - update acs_objects - set title= :name + update acs_objects set + title = :name, + last_modified = current_timestamp, + modifying_user = [ad_conn user_id] where object_id = :forum_id Index: openacs-4/packages/forums/tcl/forums-security-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/tcl/forums-security-procs.tcl,v diff -u -N -r1.18 -r1.19 --- openacs-4/packages/forums/tcl/forums-security-procs.tcl 11 Oct 2017 16:20:19 -0000 1.18 +++ openacs-4/packages/forums/tcl/forums-security-procs.tcl 8 Nov 2017 12:05:55 -0000 1.19 @@ -41,16 +41,21 @@ {-user_id ""} {-forum_id:required} } { - if {[ad_conn user_id] == 0} { - return false - } elseif {[can_moderate_forum_p \ - -forum_id $forum_id \ - -user_id $user_id]} { + set user_id [expr {$user_id eq "" ? [ad_conn user_id] : $user_id}] + + # Moderators can always post + if {[can_moderate_forum_p \ + -forum_id $forum_id \ + -user_id $user_id]} { return true - } else { - forum::get -forum_id $forum_id -array forum - return [expr {$forum(posting_policy) ne "closed"}] } + + forum::get -forum_id $forum_id -array forum + + # Others can post if forum is not closed. The public can post + # only if anonymous posting is enabled. + return [expr {$forum(posting_policy) ne "closed" && + ($user_id != 0 || $forum(anonymous_allowed_p))}] } ad_proc -public require_post_forum {