Forum OpenACS Q&A: Scope, registration behaviour in calendar/post-new-2.tcl

Hi all,

I find myself with this unexpected behaviour in the calendar module. My calendar is set to be open for posting, but when users click to post a new event, it does not ask the users to register. Instead it tries to insert the event as user_id 0, which fails.

I don't understand how do the scope procs work, but here's the difference between calendar/post-new-2.tcl and news/post-new-2.tcl:


calendar/post-new-2.tcl
-----------------------
ad_scope_error_check

set db [ns_db gethandle]
ad_scope_authorize $db $scope all group_member registered

news/post-new-2.tcl
-------------------
ad_scope_error_check

set db [ns_db gethandle]
set user_id [ad_scope_authorize $db $scope all all all ]

if { $user_id == 0 } {
    ns_returnredirect "/register/index.tcl?[export_url_scope_vars]"
    return
}
I was having a similar problem so I inserted some of the code from the news module into the calendar add pages:

if { $user_id == 0 } { ns_returnredirect "/register/index.tcl?[export_url_scope_vars] &return_url=[ns_urlencode [ns_conn url]]" return }

It may not be correct, but it does prompt the user to either login or register if they aren't currently.

See also https://openacs.org/forums/message-view?message_id=16959 for what I was trying to do.

Also, there is a proc "ad_maybe_redirect_for_registration" within the
acs which I think accomplishes the same thing. Not sure why
all the modules are not using it.
History...some modules predate it, some authors weren't aware of it when the little utility was written.  More of the kind of stuff we hope to see cleaned up in ACS 4.0.
I thought about using the news code snippet but for some reason it does not take the user back to the page. It just takes him to the his workspace.

The calendar module is "scoped" for groups and other things. I am not sure if ad_maybe... deals with scoped stuff as the code does not show explicitly. I'll give it a shot.