Code

added hook for external password validation, and some more docco
[roundup.git] / roundup / templates / classic / dbinit.py
1 #
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
3 # This module is free software, and you may redistribute it and/or modify
4 # under the same terms as Python, so long as this copyright message and
5 # disclaimer are retained in their original form.
6 #
7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
10 # POSSIBILITY OF SUCH DAMAGE.
11 #
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE.  THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17
18 # $Id: dbinit.py,v 1.30 2002-09-26 23:59:08 richard Exp $
20 import os
22 import config
23 from select_db import Database, Class, FileClass, IssueClass
25 def open(name=None):
26     ''' as from the roundupdb method openDB 
27     ''' 
28     from roundup.hyperdb import String, Password, Date, Link, Multilink
30     # open the database
31     db = Database(config, name)
33     #
34     # Now initialise the schema. Must do this each time the database is
35     # opened.
36     #
38     # Class automatically gets these properties:
39     #   creation = Date()
40     #   activity = Date()
41     #   creator = Link('user')
42     pri = Class(db, "priority", 
43                     name=String(), order=String())
44     pri.setkey("name")
46     stat = Class(db, "status", 
47                     name=String(), order=String())
48     stat.setkey("name")
50     keyword = Class(db, "keyword", 
51                     name=String())
52     keyword.setkey("name")
53     
54     query = Class(db, "query",
55                     klass=String(),     name=String(),
56                     url=String())
57     query.setkey("name")
59     # add any additional database schema configuration here
60     
61     # Note: roles is a comma-separated string of Role names
62     user = Class(db, "user", 
63                     username=String(),   password=Password(),
64                     address=String(),    realname=String(), 
65                     phone=String(),      organisation=String(),
66                     alternate_addresses=String(),
67                     queries=Multilink('query'), roles=String())
68     user.setkey("username")
70     # FileClass automatically gets these properties:
71     #   content = String()    [saved to disk in <tracker home>/db/files/]
72     #   (it also gets the Class properties creation, activity and creator)
73     msg = FileClass(db, "msg", 
74                     author=Link("user", do_journal='no'),
75                     recipients=Multilink("user", do_journal='no'), 
76                     date=Date(),         summary=String(), 
77                     files=Multilink("file"),
78                     messageid=String(),  inreplyto=String())
80     file = FileClass(db, "file", 
81                     name=String(),       type=String())
83     # IssueClass automatically gets these properties:
84     #   title = String()
85     #   messages = Multilink("msg")
86     #   files = Multilink("file")
87     #   nosy = Multilink("user")
88     #   superseder = Multilink("issue")
89     #   (it also gets the Class properties creation, activity and creator)
90     issue = IssueClass(db, "issue", 
91                     assignedto=Link("user"), topic=Multilink("keyword"),
92                     priority=Link("priority"), status=Link("status"))
94     #
95     # SECURITY SETTINGS
96     #
97     # new permissions for this schema
98     for cl in 'issue', 'file', 'msg', 'user', 'query', 'keyword':
99         db.security.addPermission(name="Edit", klass=cl,
100             description="User is allowed to edit "+cl)
101         db.security.addPermission(name="View", klass=cl,
102             description="User is allowed to access "+cl)
104     # Assign the access and edit permissions for issue, file and message
105     # to regular users now
106     for cl in 'issue', 'file', 'msg', 'query', 'keyword':
107         p = db.security.getPermission('View', cl)
108         db.security.addPermissionToRole('User', p)
109         p = db.security.getPermission('Edit', cl)
110         db.security.addPermissionToRole('User', p)
111     # and give the regular users access to the web and email interface
112     p = db.security.getPermission('Web Access')
113     db.security.addPermissionToRole('User', p)
114     p = db.security.getPermission('Email Access')
115     db.security.addPermissionToRole('User', p)
117     # May users view other user information? Comment these lines out
118     # if you don't want them to
119     p = db.security.getPermission('View', 'user')
120     db.security.addPermissionToRole('User', p)
122     # Assign the appropriate permissions to the anonymous user's Anonymous
123     # Role. Choices here are:
124     # - Allow anonymous users to register through the web
125     p = db.security.getPermission('Web Registration')
126     db.security.addPermissionToRole('Anonymous', p)
127     # - Allow anonymous (new) users to register through the email gateway
128     p = db.security.getPermission('Email Registration')
129     db.security.addPermissionToRole('Anonymous', p)
130     # - Allow anonymous users access to the "issue" class of data
131     #   Note: this also grants access to related information like files,
132     #         messages, statuses etc that are linked to issues
133     p = db.security.getPermission('View', 'issue')
134     db.security.addPermissionToRole('Anonymous', p)
135     # - Allow anonymous users access to edit the "issue" class of data
136     #   Note: this also grants access to create related information like
137     #         files and messages etc that are linked to issues
138     #p = db.security.getPermission('Edit', 'issue')
139     #db.security.addPermissionToRole('Anonymous', p)
141     # oh, g'wan, let anonymous access the web interface too
142     p = db.security.getPermission('Web Access')
143     db.security.addPermissionToRole('Anonymous', p)
145     import detectors
146     detectors.init(db)
148     # schema is set up - run any post-initialisation
149     db.post_init()
150     return db
151  
152 def init(adminpw): 
153     ''' as from the roundupdb method initDB 
154  
155     Open the new database, and add new nodes - used for initialisation. You
156     can edit this before running the "roundup-admin initialise" command to
157     change the initial database entries.
158     ''' 
159     dbdir = os.path.join(config.DATABASE, 'files')
160     if not os.path.isdir(dbdir):
161         os.makedirs(dbdir)
163     db = open("admin")
164     db.clear()
166     #
167     # INITIAL PRIORITY AND STATUS VALUES
168     #
169     pri = db.getclass('priority')
170     pri.create(name="critical", order="1")
171     pri.create(name="urgent", order="2")
172     pri.create(name="bug", order="3")
173     pri.create(name="feature", order="4")
174     pri.create(name="wish", order="5")
176     stat = db.getclass('status')
177     stat.create(name="unread", order="1")
178     stat.create(name="deferred", order="2")
179     stat.create(name="chatting", order="3")
180     stat.create(name="need-eg", order="4")
181     stat.create(name="in-progress", order="5")
182     stat.create(name="testing", order="6")
183     stat.create(name="done-cbb", order="7")
184     stat.create(name="resolved", order="8")
186     # create the two default users
187     user = db.getclass('user')
188     user.create(username="admin", password=adminpw,
189         address=config.ADMIN_EMAIL, roles='Admin')
190     user.create(username="anonymous", roles='Anonymous')
192     # add any additional database create steps here - but only if you
193     # haven't initialised the database with the admin "initialise" command
195     db.commit()
197 # vim: set filetype=python ts=4 sw=4 et si