~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
1200 by William Grant
Move ivle.util.get_terms_of_service to ivle.webapp.tos.
24
import os.path
25
1099.1.161 by William Grant
Move ivle.dispatch.login.get_user_details() to ivle.webapp.security.
26
import ivle.webapp.security
1099.1.108 by William Grant
Port the tos app to the new framework, and fix ivle.webapp.help's reference
27
from ivle.webapp.base.xhtml import XHTMLView
1092.1.28 by William Grant
Only load tos.js on /+tos.
28
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
1294.2.63 by William Grant
ToS ported...
29
from ivle.webapp import ApplicationRoot
1099.1.108 by William Grant
Port the tos app to the new framework, and fix ivle.webapp.help's reference
30
1200 by William Grant
Move ivle.util.get_terms_of_service to ivle.webapp.tos.
31
def get_terms_of_service(config):
32
    """
33
    Sends the Terms of Service document to the req object.
34
    This consults conf to find out where the TOS is located on disk, and sends
35
    that. If it isn't found, it sends a generic message explaining to admins
36
    how to create a real one.
37
    """
38
    try:
39
        return open(os.path.join(config['paths']['data'],
40
                    'notices/tos.html')).read()
41
    except IOError:
42
        return """\
43
<p><b>*** SAMPLE ONLY ***</b></p>
44
<p>This is the text of the IVLE Terms of Service.</p>
45
<p>The administrator should create a license file with an appropriate
46
"Terms of Service" license for your organisation.</p>
47
<h2>Instructions for Administrators</h2>
48
<p>You are seeing this message because you have not configured a Terms of
49
Service document.</p>
50
<p>When you configured IVLE, you specified a path to the Terms of Service
51
document (this is found in <b><tt>ivle/conf/conf.py</tt></b> under
52
"<tt>tos_path</tt>").</p>
53
<p>Create a file at this location; an HTML file with the appropriately-worded
54
license.</p>
55
<p>This should be a normal XHTML file, except it should not contain
56
<tt>html</tt>, <tt>head</tt> or <tt>body</tt> elements - it should
57
just be the contents of a body element (IVLE will wrap it accordingly).</p>
58
<p>This will automatically be used as the license text instead of this
59
placeholder text.</p>
60
"""
61
1099.1.108 by William Grant
Port the tos app to the new framework, and fix ivle.webapp.help's reference
62
class TermsOfServiceView(XHTMLView):
1099.1.127 by William Grant
Implement ToS acceptance in the new login machinery. Now implemented through
63
    """View of the Terms of Service, allowing acceptance.
64
65
    Users with state 'no_agreement' see buttons to accept or decline.
66
    If a user has already accepted it, they just see a static page.
67
    """
68
1099.1.129 by William Grant
Allow XHTML views to specify that they cannot have overlays.
69
    allow_overlays = False
70
1294.2.63 by William Grant
ToS ported...
71
    def __init__(self, req, context, subpath=None):
72
        super(TermsOfServiceView, self).__init__(req, context, subpath)
1099.1.127 by William Grant
Implement ToS acceptance in the new login machinery. Now implemented through
73
        # We need to be able to handle the case where a user has status
74
        # 'no_agreement'. In that case, req.user will be None, so we have
75
        # to get it ourselves.
76
        if req.user is None:
1099.1.172 by William Grant
Fix a bad reference to ivle.webapp.security.get_user_details in ToS.
77
            self.user = ivle.webapp.security.get_user_details(req)
1099.1.127 by William Grant
Implement ToS acceptance in the new login machinery. Now implemented through
78
            self.mode = 'accept'
79
            self.template = 'accept.html'
80
        else:
81
            self.user = req.user
82
            self.mode = 'view'
83
            self.template = 'view.html'
84
1099.1.110 by William Grant
Implement an authorization system in the new framework. This breaks the REST
85
    def authorize(self, req):
1099.1.127 by William Grant
Implement ToS acceptance in the new login machinery. Now implemented through
86
        # This can be used by any authenticated user, even if they haven't
87
        # accepted the ToS yet.
1099.1.161 by William Grant
Move ivle.dispatch.login.get_user_details() to ivle.webapp.security.
88
        return ivle.webapp.security.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
89
1099.1.108 by William Grant
Port the tos app to the new framework, and fix ivle.webapp.help's reference
90
    def populate(self, req, ctx):
1200 by William Grant
Move ivle.util.get_terms_of_service to ivle.webapp.tos.
91
        ctx['text'] = get_terms_of_service(req.config)
1099.1.108 by William Grant
Port the tos app to the new framework, and fix ivle.webapp.help's reference
92
1099.1.127 by William Grant
Implement ToS acceptance in the new login machinery. Now implemented through
93
        if self.mode == 'accept':
1092.1.28 by William Grant
Only load tos.js on /+tos.
94
            self.plugin_scripts[Plugin] = ['tos.js']
1099.1.127 by William Grant
Implement ToS acceptance in the new login machinery. Now implemented through
95
            ctx['user'] = self.user
96
1092.1.28 by William Grant
Only load tos.js on /+tos.
97
class Plugin(ViewPlugin, MediaPlugin):
1099.1.108 by William Grant
Port the tos app to the new framework, and fix ivle.webapp.help's reference
98
    """Registration for the Terms of Service plugin."""
1294.2.63 by William Grant
ToS ported...
99
    views = [(ApplicationRoot, '+tos', TermsOfServiceView)]
1092.1.28 by William Grant
Only load tos.js on /+tos.
100
101
    media = 'media'