~azzar1/unity/add-show-desktop-key

1099.1.108 by William Grant
Port the tos app to the new framework, and fix ivle.webapp.help's reference
1
# IVLE - Informatics Virtual Learning Environment
2
# Copyright (C) 2007-2009 The University of Melbourne
458 by mattgiuca
Added "tos" as an app. This app simply displays the Terms of Service
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
1099.1.108 by William Grant
Port the tos app to the new framework, and fix ivle.webapp.help's reference
18
# Author: Matt Giuca, Will Grant
19
20
"""View to display the Terms of Service.
21
22
This is mainly for the benefit of the link in ivle.webapp.help."""
23
24
import ivle.util
1099.1.127 by William Grant
Implement ToS acceptance in the new login machinery. Now implemented through
25
import ivle.dispatch.login
1099.1.108 by William Grant
Port the tos app to the new framework, and fix ivle.webapp.help's reference
26
from ivle.webapp.base.xhtml import XHTMLView
27
from ivle.webapp.base.plugins import ViewPlugin
28
29
class TermsOfServiceView(XHTMLView):
1099.1.127 by William Grant
Implement ToS acceptance in the new login machinery. Now implemented through
30
    """View of the Terms of Service, allowing acceptance.
31
32
    Users with state 'no_agreement' see buttons to accept or decline.
33
    If a user has already accepted it, they just see a static page.
34
    """
35
1099.1.129 by William Grant
Allow XHTML views to specify that they cannot have overlays.
36
    allow_overlays = False
37
1099.1.127 by William Grant
Implement ToS acceptance in the new login machinery. Now implemented through
38
    def __init__(self, req):
39
        # We need to be able to handle the case where a user has status
40
        # 'no_agreement'. In that case, req.user will be None, so we have
41
        # to get it ourselves.
42
        if req.user is None:
43
            self.user = ivle.dispatch.login.get_user_details(req)
44
            self.mode = 'accept'
45
            self.template = 'accept.html'
46
        else:
47
            self.user = req.user
48
            self.mode = 'view'
49
            self.template = 'view.html'
50
1099.1.110 by William Grant
Implement an authorization system in the new framework. This breaks the REST
51
    def authorize(self, req):
1099.1.127 by William Grant
Implement ToS acceptance in the new login machinery. Now implemented through
52
        # This can be used by any authenticated user, even if they haven't
53
        # accepted the ToS yet.
54
        return ivle.dispatch.login.get_user_details(req) is not None
1099.1.110 by William Grant
Implement an authorization system in the new framework. This breaks the REST
55
1099.1.108 by William Grant
Port the tos app to the new framework, and fix ivle.webapp.help's reference
56
    def populate(self, req, ctx):
57
        ctx['text'] = ivle.util.get_terms_of_service()
58
1099.1.127 by William Grant
Implement ToS acceptance in the new login machinery. Now implemented through
59
        if self.mode == 'accept':
60
            ctx['user'] = self.user
61
1099.1.108 by William Grant
Port the tos app to the new framework, and fix ivle.webapp.help's reference
62
class Plugin(ViewPlugin):
63
    """Registration for the Terms of Service plugin."""
64
    urls = [
65
        ('+tos', TermsOfServiceView),
66
    ]