@auth.requires_permission not working
When entering a record in the db.auth_permission table, there is a table field in addition to the name field (note, table doesn't have to refer to a database table -- it can be any name representing any type of object). When a permission is checked, both the name and the table must match.
If you insert a permission record via the appadmin interface or using auth.add_permission(1, 'search'), then the table field will be set to an empty string (i.e., ''). This will work, because when you do @auth.requires_permission('search'), that is equivalent to @auth.requires_permission('search', ''), which matches the empty string in the permission record.
However, if you insert via db.auth_permission.insert(group_id=1, name='search'), then the table field will be set to None, which will not match the empty string when you check the permission.
I have an application where I am using web2py's access control system. I have various users in auth_user table. To be more specific I have admin1@mysite.com user whose id is 4. There is a group admin with group id 1 in auth_group table. In auth_membership table I have user_id 4 related to group_id 1. It means that admin1@mysite.com is a member of admin group. Finally in auth_permission table I have a record which relates group_id 1 with permission named search. It means that admin group has search permission. I have a controller in which I have index method with decorator as @auth.requires_permission('search'). I am logging in with admin1@mysite.com and getting to this controller method. But this condition evaluates to false and control doesn't go inside method. However if I replace this decorator with one @auth.requires_login() it works. But I want only users with search permission to get access to this method. Please help me to achieve this.