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.27 2002-09-11 01:18:24 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")
54 query = Class(db, "query",
55 klass=String(), name=String(),
56 url=String())
57 query.setkey("name")
59 # Note: roles is a comma-separated string of Role names
60 user = Class(db, "user",
61 username=String(), password=Password(),
62 address=String(), realname=String(),
63 phone=String(), organisation=String(),
64 alternate_addresses=String(),
65 queries=Multilink('query'), roles=String())
66 user.setkey("username")
68 # FileClass automatically gets these properties:
69 # content = String() [saved to disk in <tracker home>/db/files/]
70 # (it also gets the Class properties creation, activity and creator)
71 msg = FileClass(db, "msg",
72 author=Link("user", do_journal='no'),
73 recipients=Multilink("user", do_journal='no'),
74 date=Date(), summary=String(),
75 files=Multilink("file"),
76 messageid=String(), inreplyto=String())
78 file = FileClass(db, "file",
79 name=String(), type=String())
81 # IssueClass automatically gets these properties:
82 # title = String()
83 # messages = Multilink("msg")
84 # files = Multilink("file")
85 # nosy = Multilink("user")
86 # superseder = Multilink("issue")
87 # (it also gets the Class properties creation, activity and creator)
88 issue = IssueClass(db, "issue",
89 assignedto=Link("user"), topic=Multilink("keyword"),
90 priority=Link("priority"), status=Link("status"))
92 #
93 # SECURITY SETTINGS
94 #
95 # new permissions for this schema
96 for cl in 'issue', 'file', 'msg', 'user':
97 db.security.addPermission(name="Edit", klass=cl,
98 description="User is allowed to edit "+cl)
99 db.security.addPermission(name="View", klass=cl,
100 description="User is allowed to access "+cl)
102 # Assign the access and edit permissions for issue, file and message
103 # to regular users now
104 for cl in 'issue', 'file', 'msg':
105 p = db.security.getPermission('View', cl)
106 db.security.addPermissionToRole('User', p)
107 p = db.security.getPermission('Edit', cl)
108 db.security.addPermissionToRole('User', p)
109 # and give the regular users access to the web and email interface
110 p = db.security.getPermission('Web Access')
111 db.security.addPermissionToRole('User', p)
112 p = db.security.getPermission('Email Access')
113 db.security.addPermissionToRole('User', p)
115 # May users view other user information? Comment these lines out
116 # if you don't want them to
117 p = db.security.getPermission('View', 'user')
118 db.security.addPermissionToRole('User', p)
120 # Assign the appropriate permissions to the anonymous user's Anonymous
121 # Role. Choices here are:
122 # - Allow anonymous users to register through the web
123 p = db.security.getPermission('Web Registration')
124 db.security.addPermissionToRole('Anonymous', p)
125 # - Allow anonymous (new) users to register through the email gateway
126 p = db.security.getPermission('Email Registration')
127 db.security.addPermissionToRole('Anonymous', p)
128 # - Allow anonymous users access to the "issue" class of data
129 # Note: this also grants access to related information like files,
130 # messages, statuses etc that are linked to issues
131 p = db.security.getPermission('View', 'issue')
132 db.security.addPermissionToRole('Anonymous', p)
133 # - Allow anonymous users access to edit the "issue" class of data
134 # Note: this also grants access to create related information like
135 # files and messages etc that are linked to issues
136 #p = db.security.getPermission('Edit', 'issue')
137 #db.security.addPermissionToRole('Anonymous', p)
139 # oh, g'wan, let anonymous access the web interface too
140 p = db.security.getPermission('Web Access')
141 db.security.addPermissionToRole('Anonymous', p)
143 import detectors
144 detectors.init(db)
146 # schema is set up - run any post-initialisation
147 db.post_init()
148 return db
150 def init(adminpw):
151 ''' as from the roundupdb method initDB
153 Open the new database, and add new nodes - used for initialisation. You
154 can edit this before running the "roundup-admin initialise" command to
155 change the initial database entries.
156 '''
157 dbdir = os.path.join(config.DATABASE, 'files')
158 if not os.path.isdir(dbdir):
159 os.makedirs(dbdir)
161 db = open("admin")
162 db.clear()
164 #
165 # INITIAL PRIORITY AND STATUS VALUES
166 #
167 pri = db.getclass('priority')
168 pri.create(name="critical", order="1")
169 pri.create(name="urgent", order="2")
170 pri.create(name="bug", order="3")
171 pri.create(name="feature", order="4")
172 pri.create(name="wish", order="5")
174 stat = db.getclass('status')
175 stat.create(name="unread", order="1")
176 stat.create(name="deferred", order="2")
177 stat.create(name="chatting", order="3")
178 stat.create(name="need-eg", order="4")
179 stat.create(name="in-progress", order="5")
180 stat.create(name="testing", order="6")
181 stat.create(name="done-cbb", order="7")
182 stat.create(name="resolved", order="8")
184 # create the two default users
185 user = db.getclass('user')
186 user.create(username="admin", password=adminpw,
187 address=config.ADMIN_EMAIL, roles='Admin')
188 user.create(username="anonymous", roles='Anonymous')
190 db.commit()
192 # vim: set filetype=python ts=4 sw=4 et si