Completed
Push — master ( 186be2...fa3426 )
by
unknown
02:42
created

DefaultController.test_contributor_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
from tracim.lib.utils.auth import MANAGE_CONTENT_PERM
0 ignored issues
show
Unused Code introduced by
Unused MANAGE_CONTENT_PERM imported from tracim.lib.utils.auth
Loading history...
introduced by
Imports from package tracim are not grouped
Loading history...
11
from tracim.lib.utils.auth import MANAGE_WORKSPACE_PERM
0 ignored issues
show
Unused Code introduced by
Unused MANAGE_WORKSPACE_PERM imported from tracim.lib.utils.auth
Loading history...
12
from tracim.lib.utils.auth import MANAGE_GLOBAL_PERM
13
from tracim.lib.utils.auth import READ_PERM
0 ignored issues
show
Unused Code introduced by
Unused READ_PERM imported from tracim.lib.utils.auth
Loading history...
14
from tracim.lib.utils.auth import CONTRIBUTE_PERM
15
from tracim.lib.utils.auth import ADMIN_PERM
16
from tracim.lib.utils.auth import USER_PERM
17
18
19
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...
20
21
    @classmethod
22
    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...
23
        request.response.status = 404
24
        return {}
25
26
    @classmethod
27
    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...
28
        if request.authenticated_userid is None:
29
            response = HTTPUnauthorized()
30
            response.headers.update(forget(request))
31
32
        # user is logged in but doesn't have permissions, reject wholesale
33
        else:
34
            response = HTTPForbidden()
35
        return response
36
37
    # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
38
    @classmethod
39
    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...
40
        try:
41
            app_config = request.registry.settings['CFG']
42
            project = app_config.WEBSITE_TITLE
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
    # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
48
    @classmethod
49
    def test_contributor_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...
50
        try:
51
            app_config = request.registry.settings['CFG']
0 ignored issues
show
Unused Code introduced by
The variable app_config seems to be unused.
Loading history...
52
            project = 'contributor'
53
        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...
54
            return Response(e, content_type='text/plain', status=500)
55
        return {'project': project}
56
57
    # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
58
    @classmethod
59
    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...
60
        try:
61
            app_config = request.registry.settings['CFG']
0 ignored issues
show
Unused Code introduced by
The variable app_config seems to be unused.
Loading history...
62
            project = 'admin'
63
        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...
64
            return Response(e, content_type='text/plain', status=500)
65
        return {'project': project}
66
67
    # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
68
    @classmethod
69
    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...
70
        try:
71
            app_config = request.registry.settings['CFG']
0 ignored issues
show
Unused Code introduced by
The variable app_config seems to be unused.
Loading history...
72
            project = 'manager'
73
        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...
74
            return Response(e, content_type='text/plain', status=500)
75
        return {'project': project}
76
77
    # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
78
    @classmethod
79
    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...
80
        try:
81
            app_config = request.registry.settings['CFG']
0 ignored issues
show
Unused Code introduced by
The variable app_config seems to be unused.
Loading history...
82
            project = 'user'
83
        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...
84
            return Response(e, content_type='text/plain', status=500)
85
        return {'project': project}
86
87
    def bind(self, configurator: Configurator):
88
        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop static files
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
89
        configurator.add_static_view('static', 'static', cache_max_age=3600)
90
        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Do not rely
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
91
        # on static file for 404 view
92
        configurator.add_view(
93
            self.notfound_view,
94
            renderer='tracim:templates/404.jinja2',
95
            context=NotFound,
96
        )
97
98
        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
99
        configurator.add_route('test_config', '/')
100
        configurator.add_view(
101
            self.test_config,
102
            route_name='test_config',
103
            renderer='tracim:templates/mytemplate.jinja2',
104
        )
105
106
        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
107
        configurator.add_route('test_contributor', '/test_contributor')
108
        configurator.add_view(
109
            self.test_contributor_page,
110
            route_name='test_contributor',
111
            renderer='tracim:templates/mytemplate.jinja2',
112
            permission=CONTRIBUTE_PERM,
113
        )
114
115
        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
116
        configurator.add_route('test_admin', '/test_admin')
117
        configurator.add_view(
118
            self.test_admin_page,
119
            route_name='test_admin',
120
            renderer='tracim:templates/mytemplate.jinja2',
121
            permission=ADMIN_PERM,
122
        )
123
124
        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
125
        configurator.add_route('test_manager', '/test_manager')
126
        configurator.add_view(
127
            self.test_user_page,
128
            route_name='test_manager',
129
            renderer='tracim:templates/mytemplate.jinja2',
130
            permission=MANAGE_GLOBAL_PERM,
131
        )
132
133
        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
134
        configurator.add_route('test_user', '/test_user')
135
        configurator.add_view(
136
            self.test_user_page,
137
            route_name='test_user',
138
            renderer='tracim:templates/mytemplate.jinja2',
139
            permission=USER_PERM,
140
        )
141
142
        configurator.add_forbidden_view(self.forbidden_view)
143