简体   繁体   中英

Authorization to select option in drop-down

I have a web tool in python-pyramid. On a page we have a drop down with 20 options. This page is visible to everyone who logs on the web tool. I had put authorization/restriction on options available to a user on this page.

My current design is a 2D matrix which tells for which user what options are available. I m querying the matrix and displaying the options to user. Now I am thinking is it possible to use pyramid.authorization here?

My understanding is that we use pyramid.authorization when we have different pages, associated views (edit,view,create) for user (admin, normal user etc). Since I have only one page, pyramid.authorization can't be used.

Am I correct ? or if I can use pyramid.authorization in my design then how to use it?

It's not quite clear what "2D matrix of options" is, but I'll assume you're talking about links to other pages (or forms submitting to other views), and you want to show/hide options depending on whether the user has permission to view the target page or to invoke the target form submit handler.

In this case, pyramid.security.has_permission should solve your problem. Just protect your target views with appropriate permissions and use this function in your "home page" view to determine if the current user should be shown each particular menu item.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM