source: main/waeup.kofa/branches/henrik-transcript-workflow/src/waeup/kofa/webservices.py @ 17388

Last change on this file since 17388 was 10477, checked in by uli, 11 years ago

Add a (protected) XMLRPC service that tells about a student in exchange for valid credentials.

  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1## $Id: webservices.py 10477 2013-08-10 01:10:04Z uli $
2##
3## Copyright (C) 2012 Uli Fouquet & Henrik Bettermann
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18
19import grok
20from zope.component import getUtility
21from zope.catalog.interfaces import ICatalog
22from waeup.kofa.payments.interfaces import IPayer
23from waeup.kofa.interfaces import IUniversity, academic_sessions_vocab
24
25class PaymentDataWebservice(grok.View):
26    """A simple webservice to publish payment and payer details on request from
27    accepted IP addresses without authentication.
28
29    """
30    grok.context(IUniversity)
31    grok.name('paymentrequest')
32    grok.require('waeup.Public')
33
34    #ACCEPTED_IP = ('174.36.230.28', )
35    ACCEPTED_IP = ('127.0.0.1', )
36
37    def update(self, P_ID=None):
38        if P_ID == None:
39            self.output = '-1'
40            return
41        real_ip = self.request.get('HTTP_X_FORWARDED_FOR', None)
42        if real_ip:
43            self.context.logger.info('PaymentDataWebservice called: %s' % real_ip)
44        if real_ip and self.ACCEPTED_IP:
45            if real_ip not in  self.ACCEPTED_IP:
46                self.output = '-4'
47                return
48        cat = getUtility(ICatalog, name='payments_catalog')
49        results = list(
50            cat.searchResults(p_id=(P_ID, P_ID), p_state=('paid', 'paid')))
51        if len(results) != 1:
52            self.output = '-1'
53            return
54        try:
55            owner = IPayer(results[0])
56            full_name = owner.display_fullname
57            reg_number = owner.reg_number
58            matric_number = owner.matric_number
59            faculty = owner.faculty
60            department = owner.department
61        except (TypeError, AttributeError):
62            self.output = '-3'
63            return
64        amount = results[0].amount_auth
65        payment_category = results[0].category
66        payment_item = results[0].p_item
67        academic_session = academic_sessions_vocab.getTerm(
68            results[0].p_session).title
69        self.output = (
70            'FULL_NAME=%s&' +
71            'FACULTY=%s&' +
72            'DEPARTMENT=%s&' +
73            'PAYMENT_ITEM=%s&' +
74            'PAYMENT_CATEGORY=%s&' +
75            'ACADEMIC_SESSION=%s&' +
76            'MATRIC_NUMBER=%s&' +
77            'REG_NUMBER=%s&' +
78            'FEE_AMOUNT=%s') % (full_name, faculty,
79            department, payment_item, payment_category,
80            academic_session, matric_number, reg_number, amount)
81        return
82
83    def render(self):
84        return self.output
85
86class XMLRPCPermission(grok.Permission):
87    """Permission for using XMLRPC functions.
88    """
89    grok.name('waeup.xmlrpc')
90
91class XMLRPCUsers1(grok.Role):
92    """Usergroup 1
93    """
94    grok.name('waeup.xmlrpcusers1')
95    grok.title('XMLRPC Users Group 1')
96    grok.permissions('waeup.xmlrpc',)
97
98class UniversityXMLRPC(grok.XMLRPC):
99    """XMLRPC webservices for KOFA portals.
100
101    Please note, that XMLRPC does not support real keyword arguments
102    but positional arguments only.
103    """
104    grok.context(IUniversity)
105
106    @grok.require('waeup.Public')
107    def xmlrpc_api_version(self):
108        """Return the current API version for XMLRPC clients.
109        """
110        return u'0.1'
Note: See TracBrowser for help on using the repository browser.