|
| 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 2002-09-26 04:15:07 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 | + |
| 30 | + # open the database |
| 31 | + db = Database(config, name) |
| 32 | + |
| 33 | + # |
| 34 | + # Now initialise the schema. Must do this each time the database is |
| 35 | + # opened. |
| 36 | + # |
| 37 | + |
| 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. |
| 40 | + |
| 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") |
| 45 | + |
| 46 | + # |
| 47 | + # SECURITY SETTINGS |
| 48 | + # |
| 49 | + # new permissions for this schema |
| 50 | + for cl in ('user', ): |
| 51 | + db.security.addPermission(name="Edit", klass=cl, |
| 52 | + description="User is allowed to edit "+cl) |
| 53 | + db.security.addPermission(name="View", klass=cl, |
| 54 | + description="User is allowed to access "+cl) |
| 55 | + |
| 56 | + # and give the regular users access to the web and email interface |
| 57 | + p = db.security.getPermission('Web Access') |
| 58 | + db.security.addPermissionToRole('User', p) |
| 59 | + p = db.security.getPermission('Email Access') |
| 60 | + db.security.addPermissionToRole('User', p) |
| 61 | + |
| 62 | + # May users view other user information? Comment these lines out |
| 63 | + # if you don't want them to |
| 64 | + p = db.security.getPermission('View', 'user') |
| 65 | + db.security.addPermissionToRole('User', p) |
| 66 | + |
| 67 | + # Assign the appropriate permissions to the anonymous user's Anonymous |
| 68 | + # Role. Choices here are: |
| 69 | + # - Allow anonymous users to register through the web |
| 70 | + p = db.security.getPermission('Web Registration') |
| 71 | + db.security.addPermissionToRole('Anonymous', p) |
| 72 | + # - Allow anonymous (new) users to register through the email gateway |
| 73 | + p = db.security.getPermission('Email Registration') |
| 74 | + db.security.addPermissionToRole('Anonymous', p) |
| 75 | + |
| 76 | + import detectors |
| 77 | + detectors.init(db) |
| 78 | + |
| 79 | + # schema is set up - run any post-initialisation |
| 80 | + db.post_init() |
| 81 | + return db |
| 82 | + |
| 83 | +def init(adminpw): |
| 84 | + ''' as from the roundupdb method initDB |
| 85 | + |
| 86 | + Open the new database, and add new nodes - used for initialisation. You |
| 87 | + can edit this before running the "roundup-admin initialise" command to |
| 88 | + change the initial database entries. |
| 89 | + ''' |
| 90 | + dbdir = os.path.join(config.DATABASE, 'files') |
| 91 | + if not os.path.isdir(dbdir): |
| 92 | + os.makedirs(dbdir) |
| 93 | + |
| 94 | + db = open("admin") |
| 95 | + db.clear() |
| 96 | + |
| 97 | + # create the two default users |
| 98 | + user = db.getclass('user') |
| 99 | + user.create(username="admin", password=adminpw, |
| 100 | + address=config.ADMIN_EMAIL, roles='Admin') |
| 101 | + user.create(username="anonymous", roles='Anonymous') |
| 102 | + |
| 103 | + db.commit() |
| 104 | + |
| 105 | +# vim: set filetype=python ts=4 sw=4 et si |
| 106 | + |
0 commit comments