Mercurial > p > roundup > code
comparison roundup/templates/minimal/dbinit.py @ 1356:83f33642d220 maint-0.5
[[Metadata associated with this commit was garbled during conversion from CVS
to Subversion.]]
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 09 Jan 2003 22:59:22 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1242:3d0158c8c32b | 1356:83f33642d220 |
|---|---|
| 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.3 2002-10-10 07:17:39 richard Exp $ | |
| 19 | |
| 20 import os | |
| 21 | |
| 22 import config | |
| 23 from select_db import Database, Class, FileClass, IssueClass | |
| 24 | |
| 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 | |
| 30 | |
| 31 # open the database | |
| 32 db = Database(config, name) | |
| 33 | |
| 34 # | |
| 35 # Now initialise the schema. Must do this each time the database is | |
| 36 # opened. | |
| 37 # | |
| 38 | |
| 39 # The "Minimal" template gets only one class, the required "user" | |
| 40 # class. That's it. And even that has the bare minimum of properties. | |
| 41 | |
| 42 # Note: roles is a comma-separated string of Role names | |
| 43 user = Class(db, "user", username=String(), password=Password(), | |
| 44 address=String(), alternate_addresses=String(), roles=String()) | |
| 45 user.setkey("username") | |
| 46 | |
| 47 # add any additional database schema configuration here | |
| 48 | |
| 49 # | |
| 50 # SECURITY SETTINGS | |
| 51 # | |
| 52 # new permissions for this schema | |
| 53 for cl in ('user', ): | |
| 54 db.security.addPermission(name="Edit", klass=cl, | |
| 55 description="User is allowed to edit "+cl) | |
| 56 db.security.addPermission(name="View", klass=cl, | |
| 57 description="User is allowed to access "+cl) | |
| 58 | |
| 59 # and give the regular users access to the web and email interface | |
| 60 p = db.security.getPermission('Web Access') | |
| 61 db.security.addPermissionToRole('User', p) | |
| 62 p = db.security.getPermission('Email Access') | |
| 63 db.security.addPermissionToRole('User', p) | |
| 64 | |
| 65 # May users view other user information? Comment these lines out | |
| 66 # if you don't want them to | |
| 67 p = db.security.getPermission('View', 'user') | |
| 68 db.security.addPermissionToRole('User', p) | |
| 69 | |
| 70 # Assign the appropriate permissions to the anonymous user's Anonymous | |
| 71 # Role. Choices here are: | |
| 72 # - Allow anonymous users to register through the web | |
| 73 p = db.security.getPermission('Web Registration') | |
| 74 db.security.addPermissionToRole('Anonymous', p) | |
| 75 # - Allow anonymous (new) users to register through the email gateway | |
| 76 p = db.security.getPermission('Email Registration') | |
| 77 db.security.addPermissionToRole('Anonymous', p) | |
| 78 | |
| 79 import detectors | |
| 80 detectors.init(db) | |
| 81 | |
| 82 # schema is set up - run any post-initialisation | |
| 83 db.post_init() | |
| 84 return db | |
| 85 | |
| 86 def init(adminpw): | |
| 87 ''' as from the roundupdb method initDB | |
| 88 | |
| 89 Open the new database, and add new nodes - used for initialisation. You | |
| 90 can edit this before running the "roundup-admin initialise" command to | |
| 91 change the initial database entries. | |
| 92 ''' | |
| 93 dbdir = os.path.join(config.DATABASE, 'files') | |
| 94 if not os.path.isdir(dbdir): | |
| 95 os.makedirs(dbdir) | |
| 96 | |
| 97 db = open("admin") | |
| 98 db.clear() | |
| 99 | |
| 100 # create the two default users | |
| 101 user = db.getclass('user') | |
| 102 user.create(username="admin", password=adminpw, | |
| 103 address=config.ADMIN_EMAIL, roles='Admin') | |
| 104 user.create(username="anonymous", roles='Anonymous') | |
| 105 | |
| 106 # add any additional database create steps here - but only if you | |
| 107 # haven't initialised the database with the admin "initialise" command | |
| 108 | |
| 109 db.commit() | |
| 110 | |
| 111 # vim: set filetype=python ts=4 sw=4 et si | |
| 112 |
