Passed
Push — master ( 5e9dbb...c55bf2 )
by
unknown
02:18
created

tracim.lib.utils.auth.check_credentials()   A

Complexity

Conditions 4

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 16
rs 9.2
c 0
b 0
f 0
cc 4
nop 3
1
import typing
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
from pyramid.security import ALL_PERMISSIONS
3
from pyramid.security import Allow
4
from pyramid.security import Authenticated
0 ignored issues
show
Unused Code introduced by
Unused Authenticated imported from pyramid.security
Loading history...
5
from tracim.lib.core.user import UserApi
6
from tracim.models.auth import Group
7
from tracim.lib.core.workspace import WorkspaceApi
0 ignored issues
show
Unused Code introduced by
Unused WorkspaceApi imported from tracim.lib.core.workspace
Loading history...
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
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (119/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
11
12
13
def check_credentials(username, password, request) -> typing.Optional[dict]:
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
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 ?
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
24
    # TODO - G.M - 06-04-2018 - Better catch for exception of bad password, bad
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
25
    # user
26
    except:
0 ignored issues
show
Coding Style Best Practice introduced by
General except handlers without types should be used sparingly.

Typically, you would use general except handlers when you intend to specifically handle all types of errors, f.e. when logging. Otherwise, such general error handlers can mask errors in your application that you want to know of.

Loading history...
27
        pass
28
    return permissions
29
30
31
class Root:
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
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