slitaz-forge view bugs/templates/slitaz/schema.py @ rev 195
doc: let have a little bigger orange block
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Tue Mar 20 23:43:43 2012 +0100 (2012-03-20) |
parents | |
children |
line source
2 #
3 # TRACKER SCHEMA
4 #
6 # Class automatically gets these properties:
7 # creation = Date()
8 # activity = Date()
9 # creator = Link('user')
10 # actor = Link('user')
12 # Priorities
13 pri = Class(db, "priority",
14 name=String(),
15 order=Number())
16 pri.setkey("name")
18 # Statuses
19 stat = Class(db, "status",
20 name=String(),
21 order=Number())
22 stat.setkey("name")
24 # Keywords
25 keyword = Class(db, "keyword",
26 name=String())
27 keyword.setkey("name")
29 # User-defined saved searches
30 query = Class(db, "query",
31 klass=String(),
32 name=String(),
33 url=String(),
34 private_for=Link('user'))
36 # add any additional database schema configuration here
38 user = Class(db, "user",
39 username=String(),
40 password=Password(),
41 address=String(),
42 realname=String(),
43 website=String(),
44 alternate_addresses=String(),
45 queries=Multilink('query'),
46 roles=String(), # comma-separated string of Role names
47 timezone=String())
48 user.setkey("username")
49 db.security.addPermission(name='Register', klass='user',
50 description='User is allowed to register new user')
52 # FileClass automatically gets this property in addition to the Class ones:
53 # content = String() [saved to disk in <tracker home>/db/files/]
54 # type = String() [MIME type of the content, default 'text/plain']
55 msg = FileClass(db, "msg",
56 author=Link("user", do_journal='no'),
57 recipients=Multilink("user", do_journal='no'),
58 date=Date(),
59 summary=String(),
60 files=Multilink("file"),
61 messageid=String(),
62 inreplyto=String())
64 file = FileClass(db, "file",
65 name=String())
67 # IssueClass automatically gets these properties in addition to the Class ones:
68 # title = String()
69 # messages = Multilink("msg")
70 # files = Multilink("file")
71 # nosy = Multilink("user")
72 # superseder = Multilink("issue")
73 issue = IssueClass(db, "issue",
74 assignedto=Link("user"),
75 keyword=Multilink("keyword"),
76 priority=Link("priority"),
77 status=Link("status"))
79 #
80 # TRACKER SECURITY SETTINGS
81 #
82 # See the configuration and customisation document for information
83 # about security setup.
85 #
86 # REGULAR USERS
87 #
88 # Give the regular users access to the web and email interface
89 db.security.addPermissionToRole('User', 'Web Access')
90 db.security.addPermissionToRole('User', 'Email Access')
92 # Assign the access and edit Permissions for issue, file and message
93 # to regular users now
94 for cl in 'issue', 'file', 'msg', 'keyword':
95 db.security.addPermissionToRole('User', 'View', cl)
96 db.security.addPermissionToRole('User', 'Edit', cl)
97 db.security.addPermissionToRole('User', 'Create', cl)
98 for cl in 'priority', 'status':
99 db.security.addPermissionToRole('User', 'View', cl)
101 # May users view other user information? Comment these lines out
102 # if you don't want them to
103 db.security.addPermissionToRole('User', 'View', 'user')
105 # Users should be able to edit their own details -- this permission is
106 # limited to only the situation where the Viewed or Edited item is their own.
107 def own_record(db, userid, itemid):
108 '''Determine whether the userid matches the item being accessed.'''
109 return userid == itemid
110 p = db.security.addPermission(name='View', klass='user', check=own_record,
111 description="User is allowed to view their own user details")
112 db.security.addPermissionToRole('User', p)
113 p = db.security.addPermission(name='Edit', klass='user', check=own_record,
114 properties=('username', 'password', 'address', 'realname', 'website',
115 'alternate_addresses', 'queries', 'timezone'),
116 description="User is allowed to edit their own user details")
117 db.security.addPermissionToRole('User', p)
119 # Users should be able to edit and view their own queries. They should also
120 # be able to view any marked as not private. They should not be able to
121 # edit others' queries, even if they're not private
122 def view_query(db, userid, itemid):
123 private_for = db.query.get(itemid, 'private_for')
124 if not private_for: return True
125 return userid == private_for
126 def edit_query(db, userid, itemid):
127 return userid == db.query.get(itemid, 'creator')
128 p = db.security.addPermission(name='View', klass='query', check=view_query,
129 description="User is allowed to view their own and public queries")
130 db.security.addPermissionToRole('User', p)
131 p = db.security.addPermission(name='Edit', klass='query', check=edit_query,
132 description="User is allowed to edit their queries")
133 db.security.addPermissionToRole('User', p)
134 p = db.security.addPermission(name='Retire', klass='query', check=edit_query,
135 description="User is allowed to retire their queries")
136 db.security.addPermissionToRole('User', p)
137 p = db.security.addPermission(name='Create', klass='query',
138 description="User is allowed to create queries")
139 db.security.addPermissionToRole('User', p)
142 #
143 # ANONYMOUS USER PERMISSIONS
144 #
145 # Let anonymous users access the web interface. Note that almost all
146 # trackers will need this Permission. The only situation where it's not
147 # required is in a tracker that uses an HTTP Basic Authenticated front-end.
148 db.security.addPermissionToRole('Anonymous', 'Web Access')
150 # Let anonymous users access the email interface (note that this implies
151 # that they will be registered automatically, hence they will need the
152 # "Create" user Permission below)
153 # This is disabled by default to stop spam from auto-registering users on
154 # public trackers.
155 #db.security.addPermissionToRole('Anonymous', 'Email Access')
157 # Assign the appropriate permissions to the anonymous user's Anonymous
158 # Role. Choices here are:
159 # - Allow anonymous users to register
160 db.security.addPermissionToRole('Anonymous', 'Register', 'user')
162 # Allow anonymous users access to view issues (and the related, linked
163 # information)
164 for cl in 'issue', 'file', 'msg', 'keyword', 'priority', 'status':
165 db.security.addPermissionToRole('Anonymous', 'View', cl)
167 # [OPTIONAL]
168 # Allow anonymous users access to create or edit "issue" items (and the
169 # related file and message items)
170 #for cl in 'issue', 'file', 'msg':
171 # db.security.addPermissionToRole('Anonymous', 'Create', cl)
172 # db.security.addPermissionToRole('Anonymous', 'Edit', cl)
175 # vim: set filetype=python sts=4 sw=4 et si :
176 #SHA: d935a2b51c5922fb4e7a5fefc5ed70ef5fcbcac8