Commit a2f8e3c4 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

pithos backend: Extend list domain objects method

This method optionally accepts a user paramter and used to return
the objects shared to the user and having a specific domain.
This commit extends this functionality and returns also the objects
owned by the user and having the specific domain

Refs: #3510
parent 751bf999
......@@ -31,12 +31,13 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from sqlalchemy.sql import select, literal
from sqlalchemy.sql import select, literal, or_
from sqlalchemy.sql.expression import join, union
from xfeatures import XFeatures
from groups import Groups
from public import Public
from node import Node
from dbworker import ESCAPE_CHAR
......@@ -45,12 +46,13 @@ READ = 0
WRITE = 1
class Permissions(XFeatures, Groups, Public):
class Permissions(XFeatures, Groups, Public, Node):
def __init__(self, **params):
XFeatures.__init__(self, **params)
Groups.__init__(self, **params)
Public.__init__(self, **params)
Node.__init__(self, **params)
def access_grant(self, path, access, members=()):
"""Grant members with access to path.
......@@ -156,8 +158,17 @@ class Permissions(XFeatures, Groups, Public):
valid.append(subp + '/')
return [x for x in valid if self.xfeature_get(x)]
def access_list_paths(self, member, prefix=None):
"""Return the list of paths granted to member."""
def access_list_paths(self, member, prefix=None, include_owned=False,
include_containers=True):
"""Return the list of paths granted to member.
Keyword arguments:
prefix -- return only paths starting with prefix (default None)
include_owned -- return also paths owned by member (default False)
include_containers -- return also container paths owned by member
(default True)
"""
xfeatures_xfeaturevals = self.xfeatures.join(self.xfeaturevals)
......@@ -179,6 +190,19 @@ class Permissions(XFeatures, Groups, Public):
r = self.conn.execute(s)
l = [row[0] for row in r.fetchall()]
r.close()
if include_owned:
container_nodes = select(
[self.nodes.c.node],
self.nodes.c.parent == self.node_lookup(member))
condition = self.nodes.c.parent.in_(container_nodes)
if include_containers:
condition = or_(condition,
self.nodes.c.node.in_(container_nodes))
s = select([self.nodes.c.path], condition)
r = self.conn.execute(s)
l += [row[0] for row in r.fetchall() if row[0] not in l]
r.close()
return l
def access_list_shared(self, prefix=''):
......
......@@ -34,18 +34,20 @@
from xfeatures import XFeatures
from groups import Groups
from public import Public
from node import Node
READ = 0
WRITE = 1
class Permissions(XFeatures, Groups, Public):
class Permissions(XFeatures, Groups, Public, Node):
def __init__(self, **params):
XFeatures.__init__(self, **params)
Groups.__init__(self, **params)
Public.__init__(self, **params)
Node.__init__(self, **params)
def access_grant(self, path, access, members=()):
"""Grant members with access to path.
......@@ -151,8 +153,17 @@ class Permissions(XFeatures, Groups, Public):
valid.append(subp + '/')
return [x for x in valid if self.xfeature_get(x)]
def access_list_paths(self, member, prefix=None):
"""Return the list of paths granted to member."""
def access_list_paths(self, member, prefix=None, include_owned=False,
include_containers=True):
"""Return the list of paths granted to member.
Keyword arguments:
prefix -- return only paths starting with prefix (default None)
include_owned -- return also paths owned by member (default False)
include_containers -- return also container paths owned by member
(default True)
"""
q = ("select distinct path from xfeatures inner join "
" (select distinct feature_id, key from xfeaturevals inner join "
......@@ -165,7 +176,20 @@ class Permissions(XFeatures, Groups, Public):
q += " where path like ? escape '\\'"
p += (self.escape_like(prefix) + '%',)
self.execute(q, p)
return [r[0] for r in self.fetchall()]
l = [r[0] for r in self.fetchall()]
if include_owned:
node = self.node_lookup(member)
select_containers = "select node from nodes where parent = ? "
q = ("select path from nodes where parent in (%s) " %
select_containers)
args = [node]
if include_containers:
q += ("or node in (%s)" % select_containers)
args += [node]
self.execute(q, args)
l += [r[0] for r in self.fetchall() if r[0] not in l]
return l
def access_list_shared(self, prefix=''):
"""Return the list of shared paths."""
......
......@@ -1596,7 +1596,8 @@ class ModularBackend(BaseBackend):
@backend_method
def get_domain_objects(self, domain, user=None):
allowed_paths = self.permissions.access_list_paths(user)
allowed_paths = self.permissions.access_list_paths(
user, include_owned=user is not None, include_containers=False)
if not allowed_paths:
return []
obj_list = self.node.domain_object_list(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment