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.1 2003-04-17 03:26:03 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
29 from roundup.hyperdb import Interval, Boolean, Number
31 # open the database
32 db = Database(config, name)
34 #
35 # Now initialise the schema. Must do this each time the database is
36 # opened.
37 #
39 # Class automatically gets these properties:
40 # creation = Date()
41 # activity = Date()
42 # creator = Link('user')
43 pri = Class(db, "priority",
44 name=String(), order=String())
45 pri.setkey("name")
47 stat = Class(db, "status",
48 name=String(), order=String())
49 stat.setkey("name")
51 keyword = Class(db, "keyword",
52 name=String())
53 keyword.setkey("name")
55 query = Class(db, "query",
56 klass=String(), name=String(),
57 url=String())
58 query.setkey("name")
60 # add any additional database schema configuration here
62 # Note: roles is a comma-separated string of Role names
63 user = Class(db, "user",
64 username=String(), password=Password(),
65 address=String(), realname=String(),
66 phone=String(), organisation=String(),
67 alternate_addresses=String(),
68 queries=Multilink('query'), roles=String(),
69 timezone=String())
70 user.setkey("username")
72 # FileClass automatically gets these properties:
73 # content = String() [saved to disk in <tracker home>/db/files/]
74 # (it also gets the Class properties creation, activity and creator)
75 msg = FileClass(db, "msg",
76 author=Link("user", do_journal='no'),
77 recipients=Multilink("user", do_journal='no'),
78 date=Date(), summary=String(),
79 files=Multilink("file"),
80 messageid=String(), inreplyto=String())
82 file = FileClass(db, "file",
83 name=String(), type=String())
85 # IssueClass automatically gets these properties:
86 # title = String()
87 # messages = Multilink("msg")
88 # files = Multilink("file")
89 # nosy = Multilink("user")
90 # superseder = Multilink("issue")
91 # (it also gets the Class properties creation, activity and creator)
92 issue = IssueClass(db, "issue",
93 assignedto=Link("user"), topic=Multilink("keyword"),
94 priority=Link("priority"), status=Link("status"))
96 #
97 # SECURITY SETTINGS
98 #
99 # See the configuration and customisation document for information
100 # about security setup.
101 # Add new Permissions for this schema
102 for cl in 'issue', 'file', 'msg', 'user', 'query', 'keyword':
103 db.security.addPermission(name="Edit", klass=cl,
104 description="User is allowed to edit "+cl)
105 db.security.addPermission(name="View", klass=cl,
106 description="User is allowed to access "+cl)
108 # Assign the access and edit Permissions for issue, file and message
109 # to regular users now
110 for cl in 'issue', 'file', 'msg', 'query', 'keyword':
111 p = db.security.getPermission('View', cl)
112 db.security.addPermissionToRole('User', p)
113 p = db.security.getPermission('Edit', cl)
114 db.security.addPermissionToRole('User', p)
116 # and give the regular users access to the web and email interface
117 p = db.security.getPermission('Web Access')
118 db.security.addPermissionToRole('User', p)
119 p = db.security.getPermission('Email Access')
120 db.security.addPermissionToRole('User', p)
122 # May users view other user information? Comment these lines out
123 # if you don't want them to
124 p = db.security.getPermission('View', 'user')
125 db.security.addPermissionToRole('User', p)
127 # Assign the appropriate permissions to the anonymous user's Anonymous
128 # Role. Choices here are:
129 # - Allow anonymous users to register through the web
130 p = db.security.getPermission('Web Registration')
131 db.security.addPermissionToRole('Anonymous', p)
132 # - Allow anonymous (new) users to register through the email gateway
133 p = db.security.getPermission('Email Registration')
134 db.security.addPermissionToRole('Anonymous', p)
135 # - Allow anonymous users access to the "issue" class of data
136 # Note: this also grants access to related information like files,
137 # messages, statuses etc that are linked to issues
138 p = db.security.getPermission('View', 'issue')
139 db.security.addPermissionToRole('Anonymous', p)
140 # - Allow anonymous users access to edit the "issue" class of data
141 # Note: this also grants access to create related information like
142 # files and messages etc that are linked to issues
143 #p = db.security.getPermission('Edit', 'issue')
144 #db.security.addPermissionToRole('Anonymous', p)
146 # oh, g'wan, let anonymous access the web interface too
147 p = db.security.getPermission('Web Access')
148 db.security.addPermissionToRole('Anonymous', p)
150 import detectors
151 detectors.init(db)
153 # schema is set up - run any post-initialisation
154 db.post_init()
155 return db
157 def init(adminpw):
158 ''' as from the roundupdb method initDB
160 Open the new database, and add new nodes - used for initialisation. You
161 can edit this before running the "roundup-admin initialise" command to
162 change the initial database entries.
163 '''
164 dbdir = os.path.join(config.DATABASE, 'files')
165 if not os.path.isdir(dbdir):
166 os.makedirs(dbdir)
168 db = open("admin")
169 db.clear()
171 #
172 # INITIAL PRIORITY AND STATUS VALUES
173 #
174 pri = db.getclass('priority')
175 pri.create(name="critical", order="1")
176 pri.create(name="urgent", order="2")
177 pri.create(name="bug", order="3")
178 pri.create(name="feature", order="4")
179 pri.create(name="wish", order="5")
181 stat = db.getclass('status')
182 stat.create(name="unread", order="1")
183 stat.create(name="deferred", order="2")
184 stat.create(name="chatting", order="3")
185 stat.create(name="need-eg", order="4")
186 stat.create(name="in-progress", order="5")
187 stat.create(name="testing", order="6")
188 stat.create(name="done-cbb", order="7")
189 stat.create(name="resolved", order="8")
191 # create the two default users
192 user = db.getclass('user')
193 user.create(username="admin", password=adminpw,
194 address=config.ADMIN_EMAIL, roles='Admin')
195 user.create(username="anonymous", roles='Anonymous')
197 # add any additional database create steps here - but only if you
198 # haven't initialised the database with the admin "initialise" command
200 db.commit()
202 # vim: set filetype=python ts=4 sw=4 et si