Forum OpenACS Q&A: How do I know, if someone is Admin?

Collapse
Posted by Tim Adler on
The standard-Links that are normally diplayed on the OpenACS mainpage somehow irritate our users. How can I tell if someone is site-wide admin after login? I found a variable admin_p that is used in some other pages, but that doesn't work on that main page.
Collapse
Posted by Richard Hamilton on
I asked this question a couple of days ago - here is the answer.

Regards
Richard
Collapse
Posted by Tim Adler on
Great, that did it. It is working! But I don't quite understand what the code does, or what part is doing which task? Can you perhaps explain the code a little bit?
ad_page_contract {
} {
} -properties {
   admin_p:onevalue
}

set package_id [ad_conn package_id]
set admin_p [ad_permission_p $package_id admin]
Collapse
Posted by Richard Hamilton on
OK, well I am quite new to this as well so someone else may correct my mistakes, but I'll have a go....

ad_page_contract is a function that is called at the top of every *.tcl page to provide services such as automatic documentation (extracts comments from the code), variable declarations, data input filtering and validation and other bits and bobs that I have yet to familiarise myself with. It seems to be a general purpose gateway for tcl code and provides a standard means of integrating tcl page scripts with the acs api.

The first lines are a call to ad_page_contract (will already be in the page you are editing) and the -properties tag in this example declares the variable admin_p (_p for predicate - naming convention only i.e. boolean true/false) as data type onevalue (multiple value datatypes are available in the templating system). This has the effect of making the variable available to the *.adp page that is called at the end of the *.tcl page.

The

 set package_id[ad_conn package_id]
retrieves the current package instance's id number and stores it in the variable package_id.

The

set admin_p[ad_permission_p $package_id admin]
calls the ad_permission_p service passing the package instance and asking for the admin property - the value is left in admin_p

The value of the admin_p variable is then accessible in the template using the form @admin_p@ and conditional tags can be used i.e. >if @admin@ eq 1>DO SOMETHING>/if>
see the templating help in the docs. (>< wrong way round so that the forum will accept the post!)

Hope this helps.
Regards
Richard

Collapse
Posted by Tim Adler on
First of all, thanks for the great explanation.

Stupid me, just inserted your code at the end of index.tcl and it works. Seems to me as if this is just luck.
Now I tried to insert the code the way (I understood your explanation) it is supposed to be.

I added

admin_p:onevalue
to that properties area that is already there. And set
set package_id [ad_conn package_id]
set admin_p [ad_permission_p $package_id admin]
just there where other "set"s are done. Saving and trying that freaks out heavily. It says something about that something called "w" cannot be found. Sounds like certain crap to me.

Have I added in the right places, or did I get it wrong?

Don't say you are new to this, if there's folks like me out there ;)

Collapse
Posted by Richard Hamilton on
Check that the variable package_id is not already in use on the page you are editing. If already declared you need not call ad_conn to get the value. Also check that you have not left grouping characters unterminated such as quotes and brackets. If still no luck please post the tcl page surrounded by
< pre>page here< / pre> tags
.
Regards
Richard
Collapse
Posted by Tim Adler on
Figures that me doing that again and not deleting stuff I shouldn't delete made it work.

That package_id btw. wasn't set so I left it!
Worktime is over on my side of the globe. I get back to you with more questions tomorrow *g*!