|  | @@ -1,125 +1,19 @@
 | 
	
		
			
			| 1 | 1 |  # coding=utf-8
 | 
	
		
			
			| 2 |  | -from pyramid.request import Request
 | 
	
		
			
			| 3 |  | -
 | 
	
		
			
			| 4 | 2 |  from tracim import TracimRequest
 | 
	
		
			
			| 5 |  | -from tracim.models import Group
 | 
	
		
			
			| 6 |  | -from tracim.models.data import UserRoleInWorkspace
 | 
	
		
			
			| 7 | 3 |  from tracim.views.controllers import Controller
 | 
	
		
			
			| 8 | 4 |  from pyramid.config import Configurator
 | 
	
		
			
			| 9 |  | -from pyramid.response import Response
 | 
	
		
			
			| 10 | 5 |  from pyramid.exceptions import NotFound
 | 
	
		
			
			| 11 |  | -from pyramid.httpexceptions import HTTPUnauthorized
 | 
	
		
			
			| 12 |  | -from pyramid.httpexceptions import HTTPForbidden
 | 
	
		
			
			| 13 |  | -from pyramid.security import forget, authenticated_userid
 | 
	
		
			
			| 14 |  | -
 | 
	
		
			
			| 15 |  | -from tracim.lib.utils.authorization import require_workspace_role, \
 | 
	
		
			
			| 16 |  | -    require_profile
 | 
	
		
			
			| 17 | 6 |  
 | 
	
		
			
			| 18 | 7 |  
 | 
	
		
			
			| 19 | 8 |  class DefaultController(Controller):
 | 
	
		
			
			| 20 | 9 |  
 | 
	
		
			
			| 21 |  | -    def notfound_view(self, request):
 | 
	
		
			
			|  | 10 | +    def notfound_view(self, request:TracimRequest):
 | 
	
		
			
			| 22 | 11 |          request.response.status = 404
 | 
	
		
			
			| 23 | 12 |          return {}
 | 
	
		
			
			| 24 | 13 |  
 | 
	
		
			
			| 25 |  | -    def forbidden_view(self, request):
 | 
	
		
			
			| 26 |  | -        if request.authenticated_userid is None:
 | 
	
		
			
			| 27 |  | -            response = HTTPUnauthorized()
 | 
	
		
			
			| 28 |  | -            response.headers.update(forget(request))
 | 
	
		
			
			| 29 |  | -
 | 
	
		
			
			| 30 |  | -        # user is logged in but doesn't have permissions, reject wholesale
 | 
	
		
			
			| 31 |  | -        else:
 | 
	
		
			
			| 32 |  | -            response = HTTPForbidden()
 | 
	
		
			
			| 33 |  | -        return response
 | 
	
		
			
			| 34 |  | -
 | 
	
		
			
			| 35 |  | -    def home(self, request: TracimRequest):
 | 
	
		
			
			| 36 |  | -        app_config = request.registry.settings['CFG']
 | 
	
		
			
			| 37 |  | -        project = app_config.WEBSITE_TITLE
 | 
	
		
			
			| 38 |  | -        return {'project': project}
 | 
	
		
			
			| 39 |  | -
 | 
	
		
			
			| 40 |  | -    @require_profile(Group.TIM_USER)
 | 
	
		
			
			| 41 |  | -    def user(self, request: TracimRequest):
 | 
	
		
			
			| 42 |  | -        return self.home(request)
 | 
	
		
			
			| 43 |  | -
 | 
	
		
			
			| 44 |  | -    # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
 | 
	
		
			
			| 45 |  | -    @require_workspace_role(UserRoleInWorkspace.READER)
 | 
	
		
			
			| 46 |  | -    def test_reader(self, request: TracimRequest):
 | 
	
		
			
			| 47 |  | -        return self.home(request)
 | 
	
		
			
			| 48 |  | -
 | 
	
		
			
			| 49 |  | -    # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
 | 
	
		
			
			| 50 |  | -    @require_workspace_role(UserRoleInWorkspace.CONTRIBUTOR)
 | 
	
		
			
			| 51 |  | -    def test_contributor(self, request):
 | 
	
		
			
			| 52 |  | -        return self.home(request)
 | 
	
		
			
			| 53 |  | -
 | 
	
		
			
			| 54 |  | -    # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
 | 
	
		
			
			| 55 |  | -    @require_workspace_role(UserRoleInWorkspace.WORKSPACE_MANAGER)
 | 
	
		
			
			| 56 |  | -    def test_workspace_manager(self, request):
 | 
	
		
			
			| 57 |  | -        return self.home(request)
 | 
	
		
			
			| 58 |  | -
 | 
	
		
			
			| 59 |  | -    # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
 | 
	
		
			
			| 60 |  | -    @require_workspace_role(UserRoleInWorkspace.CONTENT_MANAGER)
 | 
	
		
			
			| 61 |  | -    def test_content_manager(self, request):
 | 
	
		
			
			| 62 |  | -        return self.home(request)
 | 
	
		
			
			| 63 |  | -
 | 
	
		
			
			| 64 | 14 |      def bind(self, configurator: Configurator):
 | 
	
		
			
			| 65 |  | -        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop static files
 | 
	
		
			
			| 66 |  | -        configurator.add_static_view('static', 'static', cache_max_age=3600)
 | 
	
		
			
			| 67 |  | -        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Do not rely
 | 
	
		
			
			| 68 |  | -        # on static file for 404 view
 | 
	
		
			
			| 69 | 15 |          configurator.add_view(
 | 
	
		
			
			| 70 | 16 |              self.notfound_view,
 | 
	
		
			
			| 71 |  | -            renderer='tracim:templates/404.jinja2',
 | 
	
		
			
			|  | 17 | +            renderer='json',
 | 
	
		
			
			| 72 | 18 |              context=NotFound,
 | 
	
		
			
			| 73 | 19 |          )
 | 
	
		
			
			| 74 |  | -
 | 
	
		
			
			| 75 |  | -        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
 | 
	
		
			
			| 76 |  | -        configurator.add_route('home', '/')
 | 
	
		
			
			| 77 |  | -        configurator.add_view(
 | 
	
		
			
			| 78 |  | -            self.home,
 | 
	
		
			
			| 79 |  | -            route_name='home',
 | 
	
		
			
			| 80 |  | -            renderer='tracim:templates/mytemplate.jinja2',
 | 
	
		
			
			| 81 |  | -        )
 | 
	
		
			
			| 82 |  | -        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
 | 
	
		
			
			| 83 |  | -        configurator.add_route('user', '/test_user')
 | 
	
		
			
			| 84 |  | -        configurator.add_view(
 | 
	
		
			
			| 85 |  | -            self.user,
 | 
	
		
			
			| 86 |  | -            route_name='user',
 | 
	
		
			
			| 87 |  | -            renderer='tracim:templates/mytemplate.jinja2',
 | 
	
		
			
			| 88 |  | -        )
 | 
	
		
			
			| 89 |  | -
 | 
	
		
			
			| 90 |  | -        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
 | 
	
		
			
			| 91 |  | -        configurator.add_route('test_contributor', '/test_contributor')
 | 
	
		
			
			| 92 |  | -        configurator.add_view(
 | 
	
		
			
			| 93 |  | -            self.test_contributor,
 | 
	
		
			
			| 94 |  | -            route_name='test_contributor',
 | 
	
		
			
			| 95 |  | -            renderer='tracim:templates/mytemplate.jinja2',
 | 
	
		
			
			| 96 |  | -        )
 | 
	
		
			
			| 97 |  | -        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
 | 
	
		
			
			| 98 |  | -        configurator.add_route('test_reader', '/test_reader')
 | 
	
		
			
			| 99 |  | -        configurator.add_view(
 | 
	
		
			
			| 100 |  | -            self.test_contributor,
 | 
	
		
			
			| 101 |  | -            route_name='test_reader',
 | 
	
		
			
			| 102 |  | -            renderer='tracim:templates/mytemplate.jinja2',
 | 
	
		
			
			| 103 |  | -        )
 | 
	
		
			
			| 104 |  | -        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
 | 
	
		
			
			| 105 |  | -        configurator.add_route(
 | 
	
		
			
			| 106 |  | -            'test_workspace_manager',
 | 
	
		
			
			| 107 |  | -            '/test_workspace_manager'
 | 
	
		
			
			| 108 |  | -        )
 | 
	
		
			
			| 109 |  | -        configurator.add_view(
 | 
	
		
			
			| 110 |  | -            self.test_workspace_manager,
 | 
	
		
			
			| 111 |  | -            route_name='test_workspace_manager',
 | 
	
		
			
			| 112 |  | -            renderer='tracim:templates/mytemplate.jinja2',
 | 
	
		
			
			| 113 |  | -        )
 | 
	
		
			
			| 114 |  | -
 | 
	
		
			
			| 115 |  | -        # TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this method
 | 
	
		
			
			| 116 |  | -        configurator.add_route(
 | 
	
		
			
			| 117 |  | -            'test_content_manager',
 | 
	
		
			
			| 118 |  | -            '/test_content_manager'
 | 
	
		
			
			| 119 |  | -        )
 | 
	
		
			
			| 120 |  | -        configurator.add_view(
 | 
	
		
			
			| 121 |  | -            self.test_content_manager,
 | 
	
		
			
			| 122 |  | -            route_name='test_content_manager',
 | 
	
		
			
			| 123 |  | -            renderer='tracim:templates/mytemplate.jinja2',
 | 
	
		
			
			| 124 |  | -        )
 | 
	
		
			
			| 125 |  | -        configurator.add_forbidden_view(self.forbidden_view)
 |