Ticket #1583: special_group.patch
| File special_group.patch, 6.2 kB (added by cdevienne, 1 year ago) |
|---|
-
1.0/turbogears/identity/saprovider.py
old new 21 21 # these will be set when the Provider is initialised. 22 22 user_class = None 23 23 group_class = None 24 special_group_class = None 24 25 permission_class = None 25 26 visit_class = None 26 27 … … 64 65 except AttributeError: 65 66 # Permissions haven't been computed yet 66 67 pass 68 permissions = [] 69 for g in session.query(special_group_class).all(): 70 if g.predicate.eval_with_object(self): 71 permissions.extend([p.permission_name for p in g.permissions]) 67 72 if not self.user: 68 self._permissions = frozenset( )73 self._permissions = frozenset(permissions) 69 74 else: 70 self._permissions = frozenset( [75 self._permissions = frozenset(permissions + [ 71 76 p.permission_name for p in self.user.permissions]) 72 77 return self._permissions 73 78 permissions = property(_get_permissions) … … 85 90 return self._groups 86 91 groups = property(_get_groups) 87 92 93 def _get_special_groups(self): 94 try: 95 return self._special_groups 96 except AttributeError: 97 # Special groups haven't been computed yet 98 pass 99 special_groups = session.query(special_group_class).all() 100 self._special_groups = frozenset([group.group_name for group in special_groups if group.predicate.eval_with_object(self)]) 101 return self._special_groups 102 special_groups = property(_get_special_groups) 103 88 104 def logout(self): 89 105 ''' 90 106 Remove the link between this identity and the visit. … … 113 129 super(SqlAlchemyIdentityProvider, self).__init__() 114 130 get=turbogears.config.get 115 131 116 global user_class, group_class, permission_class, visit_class132 global user_class, group_class, special_group_class, permission_class, visit_class 117 133 118 134 user_class_path = get("identity.saprovider.model.user", 119 135 None) … … 121 137 group_class_path = get("identity.saprovider.model.group", 122 138 None) 123 139 group_class = load_class(group_class_path) 140 special_group_class_path = get("identity.saprovider.model.special_group", 141 None) 142 special_group_class = load_class(special_group_class_path) 124 143 permission_class_path = get("identity.saprovider.model.permission", 125 144 None) 126 145 permission_class = load_class(permission_class_path) … … 139 158 ''' 140 159 class_mapper(user_class).local_table.create(checkfirst=True) 141 160 class_mapper(group_class).local_table.create(checkfirst=True) 161 class_mapper(special_group_class).local_table.create(checkfirst=True) 142 162 class_mapper(permission_class).local_table.create(checkfirst=True) 143 163 class_mapper(visit_class).local_table.create(checkfirst=True) 144 164 -
1.0/turbogears/qstemplates/quickstart/+package+/model.py_tmpl
old new 7 7 #end if 8 8 #if $sqlalchemy == 'True' 9 9 from sqlalchemy import (Table, Column, String, DateTime, Date, Integer, 10 DECIMAL, Unicode, ForeignKey, and_, or_ )10 DECIMAL, Unicode, ForeignKey, and_, or_, PickleType) 11 11 #if $elixir == 'True' 12 12 from elixir import * 13 13 #end if … … 171 171 Column('created', DateTime, default=datetime.now) 172 172 ) 173 173 174 special_groups_table = Table('tg_special_group', metadata, 175 Column('special_group_id', Integer, primary_key=True), 176 Column('group_name', Unicode(16), unique=True), 177 Column('display_name', Unicode(255)), 178 Column('created', DateTime, default=datetime.now), 179 Column('predicate', PickleType) 180 ) 181 174 182 users_table = Table('tg_user', metadata, 175 183 Column('user_id', Integer, primary_key=True), 176 184 Column('user_name', Unicode(16), unique=True), … … 200 208 onupdate="CASCADE", ondelete="CASCADE")) 201 209 ) 202 210 211 special_group_permission_table = Table('special_group_permission', metadata, 212 Column('special_group_id', Integer, ForeignKey('tg_special_group.special_group_id', 213 onupdate="CASCADE", ondelete="CASCADE")), 214 Column('permission_id', Integer, ForeignKey('permission.permission_id', 215 onupdate="CASCADE", ondelete="CASCADE")) 216 ) 217 203 218 # 204 219 # identity model 205 220 # … … 223 238 """ 224 239 pass 225 240 241 class SpecialGroup(object): 242 """ 243 An ultra-simple special group definition. 244 """ 245 pass 246 226 247 class User(object): 227 248 """ 228 249 Reasonably basic User definition. Probably would want additional … … 286 307 properties=dict(users=relation(User, 287 308 secondary=user_group_table, backref='groups'))) 288 309 310 mapper(SpecialGroup, special_groups_table) 311 289 312 mapper(Permission, permissions_table, 290 313 properties=dict(groups=relation(Group, 291 secondary=group_permission_table, backref='permissions'))) 314 secondary=group_permission_table, backref='permissions'), 315 special_groups=relation(SpecialGroup, 316 secondary=special_group_permission_table, backref='permissions'))) 292 317 #end if 293 318 #if $identity == "sqlalchemy" and $elixir == "True" 294 319 # -
1.0/turbogears/qstemplates/quickstart/+package+/config/app.cfg_tmpl
old new 139 139 # name using sqlmeta). 140 140 identity.saprovider.model.user="${package}.model.User" 141 141 identity.saprovider.model.group="${package}.model.Group" 142 identity.saprovider.model.special_group="${package}.model.SpecialGroup" 142 143 identity.saprovider.model.permission="${package}.model.Permission" 143 144 144 145 # The password encryption algorithm used when comparing passwords against what's