Hello everyone!
I am using (yeah, still) SqlAlchemy 0.6.8 and I'm using an
AttributeExtension to build permissions of users.
My users get the permissions depending on the UserGroup they're in.
The user has the typical relationship towards "UserGroup".
My classes:
------------------ User.py------------------------
class User(declarative):
_id = Column("id", Integer, primary_key=True, key="id")
_userName = Column("user_name", String(50), unique=True, nullable=False)
_password = Column("password", String(64), nullable=False)
_userGroupId = Column("user_group_id", Integer,
ForeignKey("user_groups.id"),
key="userGroupId")
_userGroup = relationship("UserGroup",
uselist=False,
extension=UserGroupExtension.UserGroupExtension(),
primaryjoin="user_groups.c.id == users.c.userGroupId",
backref=backref("_users",
collection_class=set
))
------------------------------------------------
------------------ UserGroup.py------------------------
class UserGroup(declarative):
_id = Column("id", Integer, primary_key=True, key="id")
_name = Column("name", String(50), nullable=False)
_permissions = Column("permissions",
CharSeparatedStrings.CharSeparatedStrings())
def rebuildPermissions(self, user):
# do stuff to assign the
# permissions of group 'self' to user 'user'
------------------------------------------------
------------------ UserGroupExtension.py------------------------
class UserGroupExtension(AttributeExtension):
def set(self, state, value, oldvalue, initiator):
userToUpdate = # !!! do things here to get the user
value.rebuildPermissions(userToUpdate)
return value
def remove(self, state, value, initiator):
removeAllThePermissionForUsersInGroup(value)
------------------------------------------------
So, in the UserGroupExtension, I need to get the user that fired the
event, to apply the proper permissions to it.
I've tried state.obj(), but that gives me an empty user.
Thank you in advance!
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.