Total Complexity | 4 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import typing |
||
|
|||
2 | from pyramid.security import ALL_PERMISSIONS |
||
3 | from pyramid.security import Allow |
||
4 | from pyramid.security import Authenticated |
||
5 | from tracim.lib.core.user import UserApi |
||
6 | from tracim.models.auth import Group |
||
7 | from tracim.lib.core.workspace import WorkspaceApi |
||
8 | |||
9 | # INFO - G.M - 06-04-2018 - Auth for pyramid |
||
10 | # based on this tutorial : https://docs.pylonsproject.org/projects/pyramid-cookbook/en/latest/auth/basic.html # nopep8 |
||
11 | |||
12 | |||
13 | def check_credentials(username, password, request) -> typing.Optional[dict]: |
||
14 | permissions = None |
||
15 | app_config = request.registry.settings['CFG'] |
||
16 | uapi = UserApi(None, session=request.dbsession, config=app_config) |
||
17 | try: |
||
18 | user = uapi.get_one_by_email(username) |
||
19 | if user.validate_password(password): |
||
20 | permissions = [] |
||
21 | for group in user.groups: |
||
22 | permissions.append(group.group_name) |
||
23 | # TODO - G.M - 06-04-2018 - Add workspace specific permission ? |
||
24 | # TODO - G.M - 06-04-2018 - Better catch for exception of bad password, bad |
||
25 | # user |
||
26 | except: |
||
27 | pass |
||
28 | return permissions |
||
29 | |||
30 | |||
31 | class Root: |
||
32 | # root |
||
33 | __acl__ = ( |
||
34 | (Allow, Group.TIM_ADMIN_GROUPNAME, ALL_PERMISSIONS), |
||
35 | (Allow, Group.TIM_MANAGER_GROUPNAME, 'manager'), |
||
36 | (Allow, Group.TIM_USER_GROUPNAME, 'user'), |
||
37 | ) |
||
38 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.