Test coverage report: permission.backends.permission_backend

# permission.backends.permission_backend: 22 total statements, 75.0% covered

Generated: Thu 2012-03-01 14:22 CST

Source file: /home/alisue/Dropbox/Codes/django-permission/permission/backends/permission_backend.py

Stats: 15 executed, 5 missed, 2 excluded, 65 ignored

1. `# vim: set fileencoding=utf-8 :`
2. `"""`
3. `Authentication backends for checking permissions`
4. ``
5. `Method:`
6. `get_permission_handler`
7. `get permission handler of the model from registry`
8. ``
9. `Class:`
10. `PermissionBackend`
11. `Authentication backend for checking permissions`
12. ``
13. ``
14. `AUTHOR:`
15. `lambdalisue[Ali su ae] (lambdalisue@hashnote.net)`
16. ``
17. `License:`
18. `The MIT License (MIT)`
19. ``
20. `Copyright (c) 2012 Alisue allright reserved.`
21. ``
22. `Permission is hereby granted, free of charge, to any person obtaining a copy`
23. `of this software and associated documentation files (the "Software"), to`
24. `deal in the Software without restriction, including without limitation the`
25. `rights to use, copy, modify, merge, publish, distribute, sublicense, and/or`
26. `sell copies of the Software, and to permit persons to whom the Software is`
27. `furnished to do so, subject to the following conditions:`
28. ``
29. `The above copyright notice and this permission notice shall be included in`
30. `all copies or substantial portions of the Software.`
31. ``
32. `THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR`
33. `IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,`
34. `FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE`
35. `AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER`
36. `LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING`
37. `FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS`
38. `IN THE SOFTWARE.`
39. ``
40. `"""`
41. `from __future__ import with_statement`
42. ``
43. `from permission.handlers import registry`
44. ``
45. `__all__ = ('PermissionBackend',)`
46. ``
47. ``
48. `class PermissionBackend(object):`
49. `"""Authentication backend for cheking permissions`
50. ``
51. `This backend is used to check permissions. The permissions`
52. `are handled with ``PermissionHandler`` which have to be registered in`
53. ```fluidpermission.handlers.registry`` before use.`
54. ``
55. ```has_perm(user_obj, perm, obj=None)`` method of detected model's`
56. ```PermissionHandler`` will be used to cheking process.`
57. ``
58. `If no model was detected or no handler was registered, this backend`
59. `does not touch that permission and return ``None`` to pass the permission`
60. `checking process to downstream backends.`
61. ``
62. `"""`
63. `supports_object_permissions = True`
64. `supports_anonymous_user = True`
65. `supports_inactive_user = True`
66. ``
67. `def authenticate(self, username, password):`
68. `"""This backend is only for checking permission"""`
69. `return None`
70. ``
71. `def has_perm(self, user_obj, perm, obj=None):`
72. `"""check permission"""`
73. `# get permission handlers fot this perm`
74. `handlers = registry.get_handlers(perm)`
75. `for handler in handlers:`
76. `if handler.has_perm(user_obj, perm, obj=obj):`
77. `return True`
78. `# do not touch this permission`
79. `return False`
80. ``
81. `def has_module_perms(self, user_obj, app_label):`
82. `# get permission handlers fot this perm`
83. `handlers = registry.get_module_handlers(app_label)`
84. `for handler in handlers:`
85. `if handler.has_module_perms(user_obj, app_label):`
86. `return True`
87. `return False`