Browse Source

New model for group/nodes relation to implement rights

sferot 11 years ago
parent
commit
eb2baaea55

+ 11 - 0
doc/database/pod-upgrade-0.4.0_to_0.5.0.sql View File

@@ -0,0 +1,11 @@
1
+ALTER TABLE pod_group ADD COLUMN personnal_group BOOLEAN;
2
+
3
+CREATE TABLE pod_group_node (
4
+    group_id INTEGER NOT NULL,
5
+    node_id INTEGER NOT NULL,
6
+    rights INTEGER,
7
+    CONSTRAINT pod_group_node_pkey PRIMARY KEY (group_id, node_id),
8
+    CONSTRAINT pod_group_node_group_id_fkey FOREIGN KEY (group_id)
9
+    REFERENCES pod_group (group_id) MATCH SIMPLE
10
+    ON UPDATE CASCADE ON DELETE CASCADE
11
+);

+ 3 - 1
pboard/pboard/model/auth.py View File

@@ -14,7 +14,7 @@ from hashlib import sha256
14 14
 __all__ = ['User', 'Group', 'Permission']
15 15
 
16 16
 from sqlalchemy import Table, ForeignKey, Column
17
-from sqlalchemy.types import Unicode, Integer, DateTime
17
+from sqlalchemy.types import Unicode, Integer, DateTime, Boolean
18 18
 from sqlalchemy.orm import relation, synonym
19 19
 
20 20
 from pboard.model import DeclarativeBase, metadata, DBSession
@@ -52,7 +52,9 @@ class Group(DeclarativeBase):
52 52
     group_name = Column(Unicode(16), unique=True, nullable=False)
53 53
     display_name = Column(Unicode(255))
54 54
     created = Column(DateTime, default=datetime.now)
55
+    personnal_group = Column(Boolean)
55 56
     users = relation('User', secondary=user_group_table, backref='groups')
57
+    rights = relation('Rights', secondary=group_node_table, backref='groups')
56 58
 
57 59
     def __repr__(self):
58 60
         return '<Group: name=%s>' % repr(self.group_name)

+ 9 - 0
pboard/pboard/model/data.py View File

@@ -207,6 +207,7 @@ class PBNode(DeclarativeBase):
207 207
 
208 208
 
209 209
   _oParent = relationship('PBNode', remote_side=[node_id], backref='_lAllChildren')
210
+  rights = relation('Rights', secondary=group_node_table, backref='nodes')
210 211
 
211 212
   def getChildrenOfType(self, plNodeTypeList, poKeySortingMethod=None, pbDoReverseSorting=False):
212 213
     """return all children nodes of type 'data' or 'node' or 'folder'"""
@@ -413,3 +414,11 @@ mapper(
413 414
                     ) 
414 415
 """
415 416
 
417
+# This is the association table for the many-to-many relationship between groups and nodes
418
+group_node_table = Table('pod_group_node', metadata,
419
+        Column('group_id', Integer, ForeignKey('pod_group.group_id',
420
+            onupdate="CASCADE", ondelete="CASCADE"), primary_key=True),
421
+        Column('node_id', Integer, ForeignKey('pod_nodes.node_id',
422
+            onupdate="CASCADE", ondelete="CASCADE"), primary_key=True),
423
+        Column('rights', Integer)
424
+)