comparison sat_pubsub/pgsql_storage.py @ 248:50f6ee966da8

item are gotten according to item's access model in getItems
author Goffi <goffi@goffi.org>
date Sun, 03 Jun 2012 15:57:28 +0200
parents 70fae534b83a
children aaf5e34ff765
comparison
equal deleted inserted replaced
247:70fae534b83a 248:50f6ee966da8
590 deleted.append(itemIdentifier) 590 deleted.append(itemIdentifier)
591 591
592 return deleted 592 return deleted
593 593
594 594
595 def getItems(self, maxItems=None): 595 def getItems(self, authorized_groups, unrestricted, maxItems=None):
596 return self.dbpool.runInteraction(self._getItems, maxItems) 596 return self.dbpool.runInteraction(self._getItems, authorized_groups, unrestricted, maxItems)
597 597
598 598
599 def _getItems(self, cursor, maxItems): 599 def _getItems(self, cursor, authorized_groups, unrestricted, maxItems):
600 self._checkNodeExists(cursor) 600 self._checkNodeExists(cursor)
601 query = """SELECT data FROM nodes 601 if unrestricted:
602 INNER JOIN items USING (node_id) 602 query = ["""SELECT data FROM nodes
603 WHERE node=%s ORDER BY date DESC""" 603 INNER JOIN items USING (node_id)
604 WHERE node=%s ORDER BY date DESC"""]
605 args = [self.nodeIdentifier]
606 else:
607 query = ["""SELECT data FROM nodes
608 INNER JOIN items USING (node_id)
609 LEFT JOIN item_groups_authorized USING (item_id)
610 WHERE node=%s AND
611 (items.access_model='open' or
612 (items.access_model='roster' and groupname in (%s))
613 )
614 ORDER BY date DESC"""]
615 args = [self.nodeIdentifier, authorized_groups]
616
604 if maxItems: 617 if maxItems:
605 cursor.execute(query + " LIMIT %s", 618 query.append("LIMIT %s")
606 (self.nodeIdentifier, 619 args.append(maxItems)
607 maxItems)) 620
608 else: 621 cursor.execute(' '.join(query), args)
609 cursor.execute(query, (self.nodeIdentifier,))
610 622
611 result = cursor.fetchall() 623 result = cursor.fetchall()
612 items = [stripNamespace(parseXml(r[0])) for r in result] 624 items = [stripNamespace(parseXml(r[0])) for r in result]
613 return items 625 return items
614 626
615 627
616 def getItemsById(self, itemIdentifiers): 628 def getItemsById(self, authorized_groups, unrestricted, itemIdentifiers):
617 return self.dbpool.runInteraction(self._getItemsById, itemIdentifiers) 629 return self.dbpool.runInteraction(self._getItemsById, itemIdentifiers)
618 630
619 631
620 def _getItemsById(self, cursor, itemIdentifiers): 632 def _getItemsById(self, cursor, authorized_groups, unrestricted, itemIdentifiers):
621 self._checkNodeExists(cursor) 633 self._checkNodeExists(cursor)
622 items = [] 634 items = []
623 for itemIdentifier in itemIdentifiers: 635 for itemIdentifier in itemIdentifiers:
624 cursor.execute("""SELECT data FROM nodes 636 cursor.execute("""SELECT data FROM nodes
625 INNER JOIN items USING (node_id) 637 INNER JOIN items USING (node_id)