Code

. Lots of cleanup in the classic html (stylesheet, search page, index page, ...)
[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.24 2002-09-01 04:32:30 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     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")
58     
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 <instance home>/db/files/]
70     #   (it also gets the Class properties creation, activity and creator)
71     msg = FileClass(db, "msg", 
72                     author=Link("user"), recipients=Multilink("user"), 
73                     date=Date(),         summary=String(), 
74                     files=Multilink("file"),
75                     messageid=String(),  inreplyto=String())
77     file = FileClass(db, "file", 
78                     name=String(),       type=String())
80     # IssueClass automatically gets these properties:
81     #   title = String()
82     #   messages = Multilink("msg")
83     #   files = Multilink("file")
84     #   nosy = Multilink("user")
85     #   superseder = Multilink("issue")
86     #   (it also gets the Class properties creation, activity and creator)
87     issue = IssueClass(db, "issue", 
88                     assignedto=Link("user"), topic=Multilink("keyword"),
89                     priority=Link("priority"), status=Link("status"))
91     #
92     # SECURITY SETTINGS
93     #
94     # new permissions for this schema
95     for cl in 'issue', 'file', 'msg', 'user':
96         db.security.addPermission(name="Edit", klass=cl,
97             description="User is allowed to edit "+cl)
98         db.security.addPermission(name="View", klass=cl,
99             description="User is allowed to access "+cl)
101     # Assign the access and edit permissions for issue, file and message
102     # to regular users now
103     for cl in 'issue', 'file', 'msg':
104         p = db.security.getPermission('View', cl)
105         db.security.addPermissionToRole('User', p)
106         p = db.security.getPermission('Edit', cl)
107         db.security.addPermissionToRole('User', p)
108     # and give the regular users access to the web and email interface
109     p = db.security.getPermission('Web Access')
110     db.security.addPermissionToRole('User', p)
111     p = db.security.getPermission('Email Access')
112     db.security.addPermissionToRole('User', p)
114     # May users view other user information? Comment these lines out
115     # if you don't want them to
116     p = db.security.getPermission('View', 'user')
117     db.security.addPermissionToRole('User', p)
119     # Assign the appropriate permissions to the anonymous user's Anonymous
120     # Role. Choices here are:
121     # - Allow anonymous users to register through the web
122     p = db.security.getPermission('Web Registration')
123     db.security.addPermissionToRole('Anonymous', p)
124     # - Allow anonymous (new) users to register through the email gateway
125     p = db.security.getPermission('Email Registration')
126     db.security.addPermissionToRole('Anonymous', p)
127     # - Allow anonymous users access to the "issue" class of data
128     #   Note: this also grants access to related information like files,
129     #         messages, statuses etc that are linked to issues
130     #p = db.security.getPermission('View', 'issue')
131     #db.security.addPermissionToRole('Anonymous', p)
132     # - Allow anonymous users access to edit the "issue" class of data
133     #   Note: this also grants access to create related information like
134     #         files and messages etc that are linked to issues
135     #p = db.security.getPermission('Edit', 'issue')
136     #db.security.addPermissionToRole('Anonymous', p)
138     # oh, g'wan, let anonymous access the web interface too
139     p = db.security.getPermission('Web Access')
140     db.security.addPermissionToRole('Anonymous', p)
142     import detectors
143     detectors.init(db)
145     # schema is set up - run any post-initialisation
146     db.post_init()
147     return db
148  
149 def init(adminpw): 
150     ''' as from the roundupdb method initDB 
151  
152     Open the new database, and add new nodes - used for initialisation. You
153     can edit this before running the "roundup-admin initialise" command to
154     change the initial database entries.
155     ''' 
156     dbdir = os.path.join(instance_config.DATABASE, 'files')
157     if not os.path.isdir(dbdir):
158         os.makedirs(dbdir)
160     db = open("admin")
161     db.clear()
163     #
164     # INITIAL PRIORITY AND STATUS VALUES
165     #
166     pri = db.getclass('priority')
167     pri.create(name="critical", order="1")
168     pri.create(name="urgent", order="2")
169     pri.create(name="bug", order="3")
170     pri.create(name="feature", order="4")
171     pri.create(name="wish", order="5")
173     stat = db.getclass('status')
174     stat.create(name="unread", order="1")
175     stat.create(name="deferred", order="2")
176     stat.create(name="chatting", order="3")
177     stat.create(name="need-eg", order="4")
178     stat.create(name="in-progress", order="5")
179     stat.create(name="testing", order="6")
180     stat.create(name="done-cbb", order="7")
181     stat.create(name="resolved", order="8")
183     # create the two default users
184     user = db.getclass('user')
185     user.create(username="admin", password=adminpw,
186         address=instance_config.ADMIN_EMAIL, roles='Admin')
187     user.create(username="anonymous", roles='Anonymous')
189     db.commit()
192 # $Log: not supported by cvs2svn $
193 # Revision 1.23  2002/08/30 08:30:45  richard
194 # allow perms on user class
196 # Revision 1.22  2002/08/01 00:56:22  richard
197 # Added the web access and email access permissions, so people can restrict
198 # access to users who register through the email interface (for example).
199 # Also added "security" command to the roundup-admin interface to display the
200 # Role/Permission config for an instance.
202 # Revision 1.21  2002/07/26 08:26:59  richard
203 # Very close now. The cgi and mailgw now use the new security API. The two
204 # templates have been migrated to that setup. Lots of unit tests. Still some
205 # issue in the web form for editing Roles assigned to users.
207 # Revision 1.20  2002/07/17 12:39:10  gmcm
208 # Saving, running & editing queries.
210 # Revision 1.19  2002/07/14 02:05:54  richard
211 # . all storage-specific code (ie. backend) is now implemented by the backends
213 # Revision 1.18  2002/07/09 03:02:53  richard
214 # More indexer work:
215 # - all String properties may now be indexed too. Currently there's a bit of
216 #   "issue" specific code in the actual searching which needs to be
217 #   addressed. In a nutshell:
218 #   + pass 'indexme="yes"' as a String() property initialisation arg, eg:
219 #         file = FileClass(db, "file", name=String(), type=String(),
220 #             comment=String(indexme="yes"))
221 #   + the comment will then be indexed and be searchable, with the results
222 #     related back to the issue that the file is linked to
223 # - as a result of this work, the FileClass has a default MIME type that may
224 #   be overridden in a subclass, or by the use of a "type" property as is
225 #   done in the default templates.
226 # - the regeneration of the indexes (if necessary) is done once the schema is
227 #   set up in the dbinit.
229 # Revision 1.17  2002/05/24 04:03:23  richard
230 # Added commentage to the dbinit files to help people with their
231 # customisation.
233 # Revision 1.16  2002/02/16 08:06:14  richard
234 # Removed the key property restriction on title of the classic issue class.
236 # Revision 1.15  2002/02/15 07:08:44  richard
237 #  . Alternate email addresses are now available for users. See the MIGRATION
238 #    file for info on how to activate the feature.
240 # Revision 1.14  2002/01/14 02:20:15  richard
241 #  . changed all config accesses so they access either the instance or the
242 #    config attriubute on the db. This means that all config is obtained from
243 #    instance_config instead of the mish-mash of classes. This will make
244 #    switching to a ConfigParser setup easier too, I hope.
246 # At a minimum, this makes migration a _little_ easier (a lot easier in the
247 # 0.5.0 switch, I hope!)
249 # Revision 1.13  2002/01/02 02:31:38  richard
250 # Sorry for the huge checkin message - I was only intending to implement #496356
251 # but I found a number of places where things had been broken by transactions:
252 #  . modified ROUNDUPDBSENDMAILDEBUG to be SENDMAILDEBUG and hold a filename
253 #    for _all_ roundup-generated smtp messages to be sent to.
254 #  . the transaction cache had broken the roundupdb.Class set() reactors
255 #  . newly-created author users in the mailgw weren't being committed to the db
257 # Stuff that made it into CHANGES.txt (ie. the stuff I was actually working
258 # on when I found that stuff :):
259 #  . #496356 ] Use threading in messages
260 #  . detectors were being registered multiple times
261 #  . added tests for mailgw
262 #  . much better attaching of erroneous messages in the mail gateway
264 # Revision 1.12  2001/12/02 05:06:16  richard
265 # . We now use weakrefs in the Classes to keep the database reference, so
266 #   the close() method on the database is no longer needed.
267 #   I bumped the minimum python requirement up to 2.1 accordingly.
268 # . #487480 ] roundup-server
269 # . #487476 ] INSTALL.txt
271 # I also cleaned up the change message / post-edit stuff in the cgi client.
272 # There's now a clearly marked "TODO: append the change note" where I believe
273 # the change note should be added there. The "changes" list will obviously
274 # have to be modified to be a dict of the changes, or somesuch.
276 # More testing needed.
278 # Revision 1.11  2001/12/01 07:17:50  richard
279 # . We now have basic transaction support! Information is only written to
280 #   the database when the commit() method is called. Only the anydbm
281 #   backend is modified in this way - neither of the bsddb backends have been.
282 #   The mail, admin and cgi interfaces all use commit (except the admin tool
283 #   doesn't have a commit command, so interactive users can't commit...)
284 # . Fixed login/registration forwarding the user to the right page (or not,
285 #   on a failure)
287 # Revision 1.10  2001/11/26 22:55:56  richard
288 # Feature:
289 #  . Added INSTANCE_NAME to configuration - used in web and email to identify
290 #    the instance.
291 #  . Added EMAIL_SIGNATURE_POSITION to indicate where to place the roundup
292 #    signature info in e-mails.
293 #  . Some more flexibility in the mail gateway and more error handling.
294 #  . Login now takes you to the page you back to the were denied access to.
296 # Fixed:
297 #  . Lots of bugs, thanks Roché and others on the devel mailing list!
299 # Revision 1.9  2001/10/30 00:54:45  richard
300 # Features:
301 #  . #467129 ] Lossage when username=e-mail-address
302 #  . #473123 ] Change message generation for author
303 #  . MailGW now moves 'resolved' to 'chatting' on receiving e-mail for an issue.
305 # Revision 1.8  2001/10/09 07:25:59  richard
306 # Added the Password property type. See "pydoc roundup.password" for
307 # implementation details. Have updated some of the documentation too.
309 # Revision 1.7  2001/08/07 00:24:43  richard
310 # stupid typo
312 # Revision 1.6  2001/08/07 00:15:51  richard
313 # Added the copyright/license notice to (nearly) all files at request of
314 # Bizar Software.
316 # Revision 1.5  2001/08/02 06:38:17  richard
317 # Roundupdb now appends "mailing list" information to its messages which
318 # include the e-mail address and web interface address. Templates may
319 # override this in their db classes to include specific information (support
320 # instructions, etc).
322 # Revision 1.4  2001/07/29 07:01:39  richard
323 # Added vim command to all source so that we don't get no steenkin' tabs :)
325 # Revision 1.3  2001/07/24 10:46:22  anthonybaxter
326 # Added templatebuilder module. two functions - one to pack up the html base,
327 # one to unpack it. Packed up the two standard templates into htmlbases.
328 # Modified __init__ to install them.
330 # __init__.py magic was needed for the rather high levels of wierd import magic.
331 # Reducing level of import magic == (good, future)
333 # Revision 1.2  2001/07/24 01:06:43  richard
334 # Oops - accidentally duped the keywords class
336 # Revision 1.1  2001/07/23 23:28:43  richard
337 # Adding the classic template
339 # Revision 1.4  2001/07/23 08:45:28  richard
340 # ok, so now "./roundup-admin init" will ask questions in an attempt to get a
341 # workable instance_home set up :)
342 # _and_ anydbm has had its first test :)
344 # Revision 1.3  2001/07/23 07:14:41  richard
345 # Moved the database backends off into backends.
347 # Revision 1.2  2001/07/23 06:25:50  richard
348 # relfected the move to roundup/backends
350 # Revision 1.1  2001/07/23 04:33:21  anthonybaxter
351 # split __init__.py into 2. dbinit and instance_config.
353 # Revision 1.1  2001/07/23 03:50:46  anthonybaxter
354 # moved templates to proper location
356 # Revision 1.2  2001/07/22 12:09:32  richard
357 # Final commit of Grande Splite
360 # vim: set filetype=python ts=4 sw=4 et si