Jonathan, I have tried using this wrapper you've posted, but it
doesn't work:
Error: can't read "db": no such variable
can't read "db": no such variable
I guess it's because the substitution in db takes place before the
wrapper is called, when the variable is still not defined.
The previous solution, getting and releasing the handle before
ad_administrator_p is called, is fine when I call it directrly from
the script, but doesn't work if I do it inside another procedure.
For example:
proc_doc news_is_admin_p { user_id news_group_id} { Check if the
user is a site-wide administrator or an admin for the newsgroup (can
either be a member of the admin group, or the admin (role) of the
newsgroup if admin_group_id is null). If yes, then 1 is returned.
Otherwise, 0 is returned.} {
# if site-wide admin, returns 1
db_release_unused_handles
set db [ns_db gethandle]
if [ad_administrator_p $db $user_id] {
return 1
}
ns_db releasehandle $db
set admin_list [news_get_admins $news_group_id]
if { [lsearch $admin_list $user_id] != -1 } {
return 1
} else {
return 0
}
}
shoots the following error:
Error: dbinit: db handle limit exceeded: thread already owns 1
handle from pool 'main'
and I've tried with diferent pools.
I thought it could work to define a new ad_administrator_p_mine,
and substitute ad_administrator_p by ad_administrator_p_mine
everywhere in this module:
proc_doc ad_administrator_p_mine {{user_id}} {
db_release_unused_handles
set db [ns_db gethandle]
return [ad_administrator_p $db $user_id]
ns_db releasehandle $db
}
but again...
Error: dbinit: db handle limit exceeded: thread already owns 1
handle from pool 'main'
and I've also tried different pools.
I run out of ideas, so what I'm doing, which is working quite
well, is porting these functions from the ACS code. For the moment,
the functions I need are not very complicated and the database
queries are almost similar for oracle and postgres. For example:
proc_doc ad_administrator_p2 { {user_id ""} } {
Returns 1 if the user is part of the site-wide administration
group. 0 otherwise.
} {
if [empty_string_p $user_id] {
set user_id [ad_verify_and_get_user_id]
}
set ad_group_member_p [db_string user_is_group_member {
select ad_group_member_p(:user_id, group_id) as member_p
from user_groups
where short_name = 'SWA'
}]
return [ad_decode $ad_group_member_p "t" 1 0]
}
But if someone has a better idea, it will be welcome.
Thanks for the help