6149c4dc5d8d9bf26408b4eb568703357dd85134
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.24 2002-07-26 08:27:00 richard Exp $
20 import os
22 import instance_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(instance_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 keywords = Class(db, "keyword",
51 name=String())
52 keywords.setkey("name")
54 user = Class(db, "user",
55 username=String(), password=Password(),
56 address=String(), realname=String(),
57 phone=String(), organisation=String(),
58 alternate_addresses=String(),
59 queries=Multilink('query'), roles=String())
60 user.setkey("username")
62 # FileClass automatically gets these properties:
63 # content = String() [saved to disk in <instance home>/db/files/]
64 # (it also gets the Class properties creation, activity and creator)
65 msg = FileClass(db, "msg",
66 author=Link("user"), recipients=Multilink("user"),
67 date=Date(), summary=String(),
68 files=Multilink("file"),
69 messageid=String(), inreplyto=String())
71 file = FileClass(db, "file",
72 name=String(), type=String())
74 # bugs and support calls etc
75 rate = Class(db, "rate",
76 name=String(), order=String())
77 rate.setkey("name")
79 source = Class(db, "source",
80 name=String(), order=String())
81 source.setkey("name")
83 platform = Class(db, "platform",
84 name=String(), order=String())
85 platform.setkey("name")
87 product = Class(db, "product",
88 name=String(), order=String())
89 product.setkey("name")
91 timelog = Class(db, "timelog",
92 date=Date(), time=String(),
93 performedby=Link("user"), description=String())
95 # IssueClass automatically gets these properties:
96 # title = String()
97 # messages = Multilink("msg")
98 # files = Multilink("file")
99 # nosy = Multilink("user")
100 # superseder = Multilink("issue")
101 # (it also gets the Class properties creation, activity and creator)
102 support = IssueClass(db, "support",
103 assignedto=Link("user"), status=Link("status"),
104 rate=Link("rate"), source=Link("source"),
105 product=Link("product"), platform=Multilink("platform"),
106 version=String(), timelog=Multilink("timelog"),
107 customername=String())
109 issue = IssueClass(db, "issue",
110 assignedto=Link("user"), priority=Link("priority"),
111 status=Link("status"), product=Link("product"),
112 platform=Multilink("platform"), version=String(),
113 targetversion=String(), supportcall=Multilink("support"))
115 #
116 # SECURITY SETTINGS
117 #
118 # new permissions for this schema
119 for cl in 'issue', 'support', 'file', 'msg':
120 db.security.addPermission(name="Edit", klass=cl,
121 description="User is allowed to edit "+cl)
122 db.security.addPermission(name="View", klass=cl,
123 description="User is allowed to access "+cl)
125 # Assign the appropriate permissions to the anonymous user's Anonymous
126 # Role. Choices here are:
127 # - Allow anonymous users to register through the web
128 p = db.security.getPermission('Web Registration')
129 db.security.addPermissionToRole('Anonymous', p)
130 # - Allow anonymous (new) users to register through the email gateway
131 p = db.security.getPermission('Email Registration')
132 db.security.addPermissionToRole('Anonymous', p)
133 # - Allow anonymous users access to the "issue" class of data
134 # Note: this also grants access to related information like files,
135 # messages, statuses etc that are linked to issues
136 #p = db.security.getPermission('View', 'issue')
137 #db.security.addPermissionToRole('Anonymous', p)
138 # - Allow anonymous users access to edit the "issue" class of data
139 # Note: this also grants access to create related information like
140 # files and messages etc that are linked to issues
141 #p = db.security.getPermission('Edit', 'issue')
142 #db.security.addPermissionToRole('Anonymous', p)
144 # Assign the access and edit permissions for issue, file and message
145 # to regular users now
146 for cl in 'issue', 'support', 'file', 'msg':
147 p = db.security.getPermission('View', cl)
148 db.security.addPermissionToRole('User', p)
149 p = db.security.getPermission('Edit', cl)
150 db.security.addPermissionToRole('User', p)
152 import detectors
153 detectors.init(db)
155 # schema is set up - run any post-initialisation
156 db.post_init()
157 return db
159 def init(adminpw):
160 ''' as from the roundupdb method initDB
162 Open the new database, and add new nodes - used for initialisation. You
163 can edit this before running the "roundup-admin initialise" command to
164 change the initial database entries.
165 '''
166 dbdir = os.path.join(instance_config.DATABASE, 'files')
167 if not os.path.isdir(dbdir):
168 os.makedirs(dbdir)
170 db = open("admin")
171 db.clear()
173 pri = db.getclass('priority')
174 pri.create(name="fatal-bug", order="1")
175 pri.create(name="bug", order="2")
176 pri.create(name="usability", order="3")
177 pri.create(name="feature", order="4")
179 stat = db.getclass('status')
180 stat.create(name="unread", order="1")
181 stat.create(name="deferred", order="2")
182 stat.create(name="chatting", order="3")
183 stat.create(name="need-eg", order="4")
184 stat.create(name="in-progress", order="5")
185 stat.create(name="testing", order="6")
186 stat.create(name="done-cbb", order="7")
187 stat.create(name="resolved", order="8")
189 rate = db.getclass("rate")
190 rate.create(name='basic', order="1")
191 rate.create(name='premium', order="2")
192 rate.create(name='internal', order="3")
194 source = db.getclass("source")
195 source.create(name='phone', order="1")
196 source.create(name='e-mail', order="2")
197 source.create(name='internal', order="3")
198 source.create(name='internal-qa', order="4")
200 platform = db.getclass("platform")
201 platform.create(name='linux', order="1")
202 platform.create(name='windows', order="2")
203 platform.create(name='mac', order="3")
205 product = db.getclass("product")
206 product.create(name='Bizar Shop', order="1")
207 product.create(name='Bizar Shop Developer', order="2")
208 product.create(name='Bizar Shop Manual', order="3")
209 product.create(name='Bizar Shop Developer Manual', order="4")
211 user = db.getclass('user')
212 user.create(username="admin", password=adminpw,
213 address=instance_config.ADMIN_EMAIL, roles="Admin")
214 user.create(username="anonymous", roles='Anonymous')
216 db.commit()
218 #
219 # $Log: not supported by cvs2svn $
220 # Revision 1.23 2002/07/14 02:05:54 richard
221 # . all storage-specific code (ie. backend) is now implemented by the backends
222 #
223 # Revision 1.22 2002/07/09 03:02:53 richard
224 # More indexer work:
225 # - all String properties may now be indexed too. Currently there's a bit of
226 # "issue" specific code in the actual searching which needs to be
227 # addressed. In a nutshell:
228 # + pass 'indexme="yes"' as a String() property initialisation arg, eg:
229 # file = FileClass(db, "file", name=String(), type=String(),
230 # comment=String(indexme="yes"))
231 # + the comment will then be indexed and be searchable, with the results
232 # related back to the issue that the file is linked to
233 # - as a result of this work, the FileClass has a default MIME type that may
234 # be overridden in a subclass, or by the use of a "type" property as is
235 # done in the default templates.
236 # - the regeneration of the indexes (if necessary) is done once the schema is
237 # set up in the dbinit.
238 #
239 # Revision 1.21 2002/05/24 04:03:23 richard
240 # Added commentage to the dbinit files to help people with their
241 # customisation.
242 #
243 # Revision 1.20 2002/02/15 07:08:44 richard
244 # . Alternate email addresses are now available for users. See the MIGRATION
245 # file for info on how to activate the feature.
246 #
247 # Revision 1.19 2002/01/14 02:20:15 richard
248 # . changed all config accesses so they access either the instance or the
249 # config attriubute on the db. This means that all config is obtained from
250 # instance_config instead of the mish-mash of classes. This will make
251 # switching to a ConfigParser setup easier too, I hope.
252 #
253 # At a minimum, this makes migration a _little_ easier (a lot easier in the
254 # 0.5.0 switch, I hope!)
255 #
256 # Revision 1.18 2002/01/02 02:31:38 richard
257 # Sorry for the huge checkin message - I was only intending to implement #496356
258 # but I found a number of places where things had been broken by transactions:
259 # . modified ROUNDUPDBSENDMAILDEBUG to be SENDMAILDEBUG and hold a filename
260 # for _all_ roundup-generated smtp messages to be sent to.
261 # . the transaction cache had broken the roundupdb.Class set() reactors
262 # . newly-created author users in the mailgw weren't being committed to the db
263 #
264 # Stuff that made it into CHANGES.txt (ie. the stuff I was actually working
265 # on when I found that stuff :):
266 # . #496356 ] Use threading in messages
267 # . detectors were being registered multiple times
268 # . added tests for mailgw
269 # . much better attaching of erroneous messages in the mail gateway
270 #
271 # Revision 1.17 2001/12/02 05:06:16 richard
272 # . We now use weakrefs in the Classes to keep the database reference, so
273 # the close() method on the database is no longer needed.
274 # I bumped the minimum python requirement up to 2.1 accordingly.
275 # . #487480 ] roundup-server
276 # . #487476 ] INSTALL.txt
277 #
278 # I also cleaned up the change message / post-edit stuff in the cgi client.
279 # There's now a clearly marked "TODO: append the change note" where I believe
280 # the change note should be added there. The "changes" list will obviously
281 # have to be modified to be a dict of the changes, or somesuch.
282 #
283 # More testing needed.
284 #
285 # Revision 1.16 2001/12/01 07:17:50 richard
286 # . We now have basic transaction support! Information is only written to
287 # the database when the commit() method is called. Only the anydbm
288 # backend is modified in this way - neither of the bsddb backends have been.
289 # The mail, admin and cgi interfaces all use commit (except the admin tool
290 # doesn't have a commit command, so interactive users can't commit...)
291 # . Fixed login/registration forwarding the user to the right page (or not,
292 # on a failure)
293 #
294 # Revision 1.15 2001/11/26 22:55:56 richard
295 # Feature:
296 # . Added INSTANCE_NAME to configuration - used in web and email to identify
297 # the instance.
298 # . Added EMAIL_SIGNATURE_POSITION to indicate where to place the roundup
299 # signature info in e-mails.
300 # . Some more flexibility in the mail gateway and more error handling.
301 # . Login now takes you to the page you back to the were denied access to.
302 #
303 # Fixed:
304 # . Lots of bugs, thanks Roché and others on the devel mailing list!
305 #
306 # Revision 1.14 2001/11/21 02:34:18 richard
307 # Added a target version field to the extended issue schema
308 #
309 # Revision 1.13 2001/10/30 00:54:45 richard
310 # Features:
311 # . #467129 ] Lossage when username=e-mail-address
312 # . #473123 ] Change message generation for author
313 # . MailGW now moves 'resolved' to 'chatting' on receiving e-mail for an issue.
314 #
315 # Revision 1.12 2001/10/09 07:25:59 richard
316 # Added the Password property type. See "pydoc roundup.password" for
317 # implementation details. Have updated some of the documentation too.
318 #
319 # Revision 1.11 2001/08/07 00:24:43 richard
320 # stupid typo
321 #
322 # Revision 1.10 2001/08/07 00:15:51 richard
323 # Added the copyright/license notice to (nearly) all files at request of
324 # Bizar Software.
325 #
326 # Revision 1.9 2001/08/02 06:38:17 richard
327 # Roundupdb now appends "mailing list" information to its messages which
328 # include the e-mail address and web interface address. Templates may
329 # override this in their db classes to include specific information (support
330 # instructions, etc).
331 #
332 # Revision 1.8 2001/07/30 01:26:59 richard
333 # Big changes:
334 # . split off the support priority into its own class
335 # . added "new support, new user" to the page head
336 # . fixed the display options for the heading links
337 #
338 # Revision 1.7 2001/07/29 07:01:39 richard
339 # Added vim command to all source so that we don't get no steenkin' tabs :)
340 #
341 # Revision 1.6 2001/07/25 01:23:07 richard
342 # Added the Roundup spec to the new documentation directory.
343 #
344 # Revision 1.5 2001/07/23 23:20:35 richard
345 # forgot to remove the interfaces from the dbinit module ;)
346 #
347 # Revision 1.4 2001/07/23 08:45:28 richard
348 # ok, so now "./roundup-admin init" will ask questions in an attempt to get a
349 # workable instance_home set up :)
350 # _and_ anydbm has had its first test :)
351 #
352 # Revision 1.3 2001/07/23 07:14:41 richard
353 # Moved the database backends off into backends.
354 #
355 # Revision 1.2 2001/07/23 06:25:50 richard
356 # relfected the move to roundup/backends
357 #
358 # Revision 1.1 2001/07/23 04:33:21 anthonybaxter
359 # split __init__.py into 2. dbinit and instance_config.
360 #
361 # Revision 1.1 2001/07/23 03:50:46 anthonybaxter
362 # moved templates to proper location
363 #
364 # Revision 1.2 2001/07/22 12:09:32 richard
365 # Final commit of Grande Splite
366 #
367 #
368 # vim: set filetype=python ts=4 sw=4 et si