~ubuntu-branches/ubuntu/natty/tryton-server/natty-security

« back to all changes in this revision

Viewing changes to trytond/web_service/wizard.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann, Daniel Baumann, Mathias Behrle
  • Date: 2009-04-21 19:27:00 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090421192700-hmiosex03jt5qf01
Tags: 1.2.0-1
[ Daniel Baumann ]
* Merging upstream version 1.2.0.
* Tidy rules files.
* Updating version information in manpage.
* Updating copyright file for new upstream release.
* Including TODO file in docs.

[ Mathias Behrle ]
* Updating application description.

[ Daniel Baumann ]
* Correcting wrapping of control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#This file is part of Tryton.  The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms.
2
 
from trytond.netsvc import Service, LocalService
3
 
from trytond import security
4
 
from threading import Lock
5
 
from random import randint
6
 
from sys import maxint
7
 
from trytond.tools import Cache
8
 
 
9
 
 
10
 
class Wizard(Service):
11
 
 
12
 
    def __init__(self, name='wizard'):
13
 
        Service.__init__(self, name)
14
 
        Service.join_group(self, 'web-service')
15
 
        Service.export_method(self, self.execute)
16
 
        Service.export_method(self, self.create)
17
 
        Service.export_method(self, self.delete)
18
 
        self.wiz_datas = {}
19
 
        self.wiz_name = {}
20
 
        self.wiz_uid = {}
21
 
        self.lock = Lock()
22
 
 
23
 
    def _execute(self, database, user, wiz_id, datas, action, context):
24
 
        self.wiz_datas[wiz_id].update(datas)
25
 
        wiz = LocalService('wizard_proxy')
26
 
        return wiz.execute(database, user, self.wiz_name[wiz_id],
27
 
                self.wiz_datas[wiz_id], action, context)
28
 
 
29
 
    def create(self, database, user, passwd, wiz_name, datas=None):
30
 
        security.check(database, user, passwd)
31
 
        Cache.clean(database)
32
 
        self.lock.acquire()
33
 
        wiz_id = 0
34
 
        while True:
35
 
            wiz_id = randint(0, maxint)
36
 
            if wiz_id not in self.wiz_name:
37
 
                break
38
 
        self.wiz_datas[wiz_id] = {}
39
 
        self.wiz_name[wiz_id] = wiz_name
40
 
        self.wiz_uid[wiz_id] = user
41
 
        self.lock.release()
42
 
        Cache.resets(database)
43
 
        return wiz_id
44
 
 
45
 
    def execute(self, database, user, passwd, wiz_id, datas, *args):
46
 
        security.check(database, user, passwd)
47
 
        Cache.clean(database)
48
 
        if wiz_id in self.wiz_uid:
49
 
            if self.wiz_uid[wiz_id] == user:
50
 
                res = self._execute(database, user, wiz_id, datas, *args)
51
 
                Cache.resets(database)
52
 
                return res
53
 
            else:
54
 
                raise Exception, 'AccessDenied'
55
 
        else:
56
 
            raise Exception, 'WizardNotFound'
57
 
 
58
 
    def delete(self, database, user, passwd, wiz_id):
59
 
        security.check(database, user, passwd)
60
 
        Cache.clean(database)
61
 
        if wiz_id in self.wiz_uid:
62
 
            if self.wiz_uid[wiz_id] == user:
63
 
                self.lock.acquire()
64
 
                del self.wiz_datas[wiz_id]
65
 
                del self.wiz_name[wiz_id]
66
 
                del self.wiz_uid[wiz_id]
67
 
                self.lock.release()
68
 
                Cache.resets(database)
69
 
                return wiz_id
70
 
            else:
71
 
                raise Exception, 'AccessDenied'
72
 
        else:
73
 
            raise Exception, 'WizardNotFound'