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.2 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 # The "Minimal" template gets only one class, the required "user"
39 # class. That's it. And even that has the bare minimum of properties.
41 # Note: roles is a comma-separated string of Role names
42 user = Class(db, "user", username=String(), password=Password(),
43 address=String(), alternate_addresses=String(), roles=String())
44 user.setkey("username")
46 # add any additional database schema configuration here
48 #
49 # SECURITY SETTINGS
50 #
51 # new permissions for this schema
52 for cl in ('user', ):
53 db.security.addPermission(name="Edit", klass=cl,
54 description="User is allowed to edit "+cl)
55 db.security.addPermission(name="View", klass=cl,
56 description="User is allowed to access "+cl)
58 # and give the regular users access to the web and email interface
59 p = db.security.getPermission('Web Access')
60 db.security.addPermissionToRole('User', p)
61 p = db.security.getPermission('Email Access')
62 db.security.addPermissionToRole('User', p)
64 # May users view other user information? Comment these lines out
65 # if you don't want them to
66 p = db.security.getPermission('View', 'user')
67 db.security.addPermissionToRole('User', p)
69 # Assign the appropriate permissions to the anonymous user's Anonymous
70 # Role. Choices here are:
71 # - Allow anonymous users to register through the web
72 p = db.security.getPermission('Web Registration')
73 db.security.addPermissionToRole('Anonymous', p)
74 # - Allow anonymous (new) users to register through the email gateway
75 p = db.security.getPermission('Email Registration')
76 db.security.addPermissionToRole('Anonymous', p)
78 import detectors
79 detectors.init(db)
81 # schema is set up - run any post-initialisation
82 db.post_init()
83 return db
85 def init(adminpw):
86 ''' as from the roundupdb method initDB
88 Open the new database, and add new nodes - used for initialisation. You
89 can edit this before running the "roundup-admin initialise" command to
90 change the initial database entries.
91 '''
92 dbdir = os.path.join(config.DATABASE, 'files')
93 if not os.path.isdir(dbdir):
94 os.makedirs(dbdir)
96 db = open("admin")
97 db.clear()
99 # create the two default users
100 user = db.getclass('user')
101 user.create(username="admin", password=adminpw,
102 address=config.ADMIN_EMAIL, roles='Admin')
103 user.create(username="anonymous", roles='Anonymous')
105 # add any additional database create steps here - but only if you
106 # haven't initialised the database with the admin "initialise" command
108 db.commit()
110 # vim: set filetype=python ts=4 sw=4 et si