SHARE
TWEET

Untitled

a guest May 19th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def includeme(config):
  2.     tables = config.registry['metadata'].tables
  3.  
  4.     # ACCOUNTS
  5.  
  6.     orm.mapper(Account, tables['account'], properties={
  7.         'account_roles': orm.relationship(
  8.             AccountRole, back_populates="account"
  9.         )
  10.     })
  11.  
  12.     # ROLES
  13.  
  14.     orm.mapper(Role, tables['role'], properties={
  15.         'accounts': orm.relationship(
  16.             AccountRole, back_populates="role", cascade='all, delete-orphan'
  17.         ),
  18.  
  19.         'acls': orm.relationship(
  20.             ACL, back_populates="role", cascade='all, delete-orphan'
  21.         )
  22.     })
  23.  
  24.     orm.mapper(AccountRole, tables['account_role'], properties={
  25.         'role': orm.relationship(
  26.             Role, back_populates='accounts'
  27.         ),
  28.  
  29.         'account': orm.relationship(
  30.             Account, back_populates='account_roles'
  31.         ),
  32.     })
  33.  
  34.     # ACL RESOURCES
  35.  
  36.     orm.mapper(ACLResource, tables['resource'], properties={
  37.         'acls': orm.relationship(
  38.             ACL, back_populates='resource'
  39.         )
  40.     })
  41.  
  42.     # PERMISSIONS
  43.  
  44.     orm.mapper(Permission, tables['permission'], properties={
  45.         'acls': orm.relationship(
  46.             ACL, back_populates='permission'
  47.         )
  48.     })
  49.     # ACCESS CONTROL LIST
  50.     # TODO: include_properties/exclude_properties
  51.  
  52.     orm.mapper(
  53.         ACL, tables['acl'],
  54.         polymorphic_on=tables['acl'].c.resource_id,
  55.         properties={
  56.             'role': orm.relationship(
  57.                 Role, back_populates='acls'
  58.             ),
  59.  
  60.             'permission': orm.relationship(
  61.                 Permission, back_populates='acls'
  62.             ),
  63.  
  64.             'resource': orm.relationship(
  65.                 ACLResource, back_populates='acls'
  66.             )
  67.         })
  68.  
  69.     orm.mapper(
  70.         GlobalACL, inherits=ACL, polymorphic_identity=1,
  71.     )
  72.  
  73.     orm.mapper(
  74.         ContentACL, inherits=ACL, polymorphic_identity=2,
  75.         properties={
  76.             'content': orm.relationship(
  77.                 Content, back_populates='acls'
  78.             )
  79.         }
  80.     )
  81.  
  82.  
  83.     @event.listens_for(orm.mapper, 'before_configured', once=True)
  84.     def _content_callback():
  85.         orm.class_mapper(Content).add_property('acls', orm.relationship(
  86.             ContentACL, back_populates='content'
  87.         ))
  88.  
  89.  
  90.     @event.listens_for(Account, 'mapper_configured')
  91.     def _account_callback(mapper, class_):
  92.         class_.roles = association_proxy('account_roles', 'role')
  93.  
  94.  
  95.     @event.listens_for(Role, 'mapper_configured')
  96.     def _role_callback(mapper, class_):
  97.         class_.permissions = association_proxy('acls', 'permission')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top