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