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

DefaultController.test_user_page()   A

Complexity

Conditions 2

Size

Total Lines 8
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
nop 2
1
# coding=utf-8
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 tracim.views.controllers import Controller
3
from pyramid.config import Configurator
4
from pyramid.response import Response
5
from pyramid.exceptions import NotFound
6
from pyramid.httpexceptions import HTTPUnauthorized
7
from pyramid.httpexceptions import HTTPForbidden
8
from pyramid.security import forget
9
10
11
class DefaultController(Controller):
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...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
12
13
    @classmethod
14
    def notfound_view(cls, request):
0 ignored issues
show
Coding Style introduced by
This method 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...
15
        request.response.status = 404
16
        return {}
17
18
    @classmethod
19
    def forbidden_view(cls, request):
0 ignored issues
show
Coding Style introduced by
This method 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...
20
        if request.authenticated_userid is None:
21
            response = HTTPUnauthorized()
22
            response.headers.update(forget(request))
23
24
        # user is logged in but doesn't have permissions, reject wholesale
25
        else:
26
            response = HTTPForbidden()
27
        return response
28
29
    @classmethod
30
    def test_config(cls, request):
0 ignored issues
show
Coding Style introduced by
This method 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...
31
        try:
32
            app_config = request.registry.settings['CFG']
33
            project = app_config.WEBSITE_TITLE
34
        except Exception as e:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
Coding Style Naming introduced by
The name e does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
35
            return Response(e, content_type='text/plain', status=500)
36
        return {'project': project}
37
38
    @classmethod
39
    def test_admin_page(cls, request):
0 ignored issues
show
Coding Style introduced by
This method 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...
40
        try:
41
            app_config = request.registry.settings['CFG']
0 ignored issues
show
Unused Code introduced by
The variable app_config seems to be unused.
Loading history...
42
            project = 'admin'
43
        except Exception as e:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
Coding Style Naming introduced by
The name e does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
44
            return Response(e, content_type='text/plain', status=500)
45
        return {'project': project}
46
47
    @classmethod
48
    def test_manager_page(cls, request):
0 ignored issues
show
Coding Style introduced by
This method 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...
49
        try:
50
            app_config = request.registry.settings['CFG']
0 ignored issues
show
Unused Code introduced by
The variable app_config seems to be unused.
Loading history...
51
            project = 'manager'
52
        except Exception as e:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
Coding Style Naming introduced by
The name e does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
53
            return Response(e, content_type='text/plain', status=500)
54
        return {'project': project}
55
56
    @classmethod
57
    def test_user_page(cls, request):
0 ignored issues
show
Coding Style introduced by
This method 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...
58
        try:
59
            app_config = request.registry.settings['CFG']
0 ignored issues
show
Unused Code introduced by
The variable app_config seems to be unused.
Loading history...
60
            project = 'user'
61
        except Exception as e:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
Coding Style Naming introduced by
The name e does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
62
            return Response(e, content_type='text/plain', status=500)
63
        return {'project': project}
64
65
66
    def bind(self, configurator: Configurator):
67
        configurator.add_static_view('static', 'static', cache_max_age=3600)
68
        configurator.add_view(
69
            self.notfound_view,
70
            renderer='tracim:templates/404.jinja2',
71
            context=NotFound,
72
        )
73
74
        configurator.add_route('test_config', '/')
75
        configurator.add_view(
76
            self.test_config,
77
            route_name='test_config',
78
            renderer='tracim:templates/mytemplate.jinja2',
79
        )
80
81
        configurator.add_route('test_admin', '/test_admin')
82
        configurator.add_view(
83
            self.test_admin_page,
84
            route_name='test_admin',
85
            renderer='tracim:templates/mytemplate.jinja2',
86
            permission='admin',
87
        )
88
        configurator.add_route('test_manager', '/test_manager')
89
        configurator.add_view(
90
            self.test_user_page,
91
            route_name='test_manager',
92
            renderer='tracim:templates/mytemplate.jinja2',
93
            permission='manager',
94
        )
95
        configurator.add_route('test_user', '/test_user')
96
        configurator.add_view(
97
            self.test_user_page,
98
            route_name='test_user',
99
            renderer='tracim:templates/mytemplate.jinja2',
100
            permission='user',
101
        )
102
        configurator.add_forbidden_view(self.forbidden_view)
103