Revision 95e92490 pithos/backends/simple.py
b/pithos/backends/simple.py | ||
---|---|---|
40 | 40 |
|
41 | 41 |
from base import NotAllowedError, BaseBackend |
42 | 42 |
from lib.hashfiler import Mapper, Blocker |
43 |
|
|
43 |
from django.utils.encoding import smart_unicode, smart_str |
|
44 | 44 |
|
45 | 45 |
logger = logging.getLogger(__name__) |
46 | 46 |
|
... | ... | |
661 | 661 |
row = c.fetchone() |
662 | 662 |
if not row: |
663 | 663 |
raise IndexError('Version does not exist') |
664 |
return str(row[0]), str(row[1]), int(row[2]), int(row[3])
|
|
664 |
return smart_str(row[0]), smart_str(row[1]), int(row[2]), int(row[3])
|
|
665 | 665 |
|
666 | 666 |
def _put_version(self, path, user, size=0, hide=0): |
667 | 667 |
tstamp = int(time.time()) |
... | ... | |
845 | 845 |
sql = 'select gname, user from groups where account = ?' |
846 | 846 |
c = self.con.execute(sql, (account,)) |
847 | 847 |
groups = {} |
848 |
for row in c.fetchall():
|
|
849 |
if row[0] not in groups:
|
|
850 |
groups[row[0]] = []
|
|
851 |
groups[row[0]].append(row[1])
|
|
848 |
for gname, user in c.fetchall():
|
|
849 |
if gname not in groups:
|
|
850 |
groups[gname] = []
|
|
851 |
groups[gname].append(user)
|
|
852 | 852 |
return groups |
853 | 853 |
|
854 | 854 |
def _put_groups(self, account, groups, replace=False): |
... | ... | |
895 | 895 |
name = path |
896 | 896 |
perms = {} # Return nothing, if nothing is set. |
897 | 897 |
for row in c.fetchall(): |
898 |
#name = smart_str(row[0], strings_only=True) |
|
899 |
#op = smart_str(row[1], strings_only=True) |
|
900 |
#user = smart_str(row[2], strings_only=True) |
|
898 | 901 |
name = row[0] |
899 |
if row[1] not in perms: |
|
900 |
perms[row[1]] = [] |
|
901 |
perms[row[1]].append(row[2]) |
|
902 |
op = row[1] |
|
903 |
user = row[2] |
|
904 |
if op not in perms: |
|
905 |
perms[op] = [] |
|
906 |
perms[op].append(user) |
|
902 | 907 |
return name, perms |
903 | 908 |
|
904 | 909 |
def _put_permissions(self, path, r, w): |
... | ... | |
932 | 937 |
self.con.execute(sql, (path,)) |
933 | 938 |
|
934 | 939 |
def _is_allowed(self, user, account, container, name, op='read'): |
935 |
if user == account:
|
|
940 |
if smart_unicode(user) == smart_unicode(account):
|
|
936 | 941 |
return True |
937 | 942 |
path = '/'.join((account, container, name)) |
938 | 943 |
if op == 'read' and self._get_public(path): |
... | ... | |
946 | 951 |
if ':' in y: |
947 | 952 |
g_account, g_name = y.split(':', 1) |
948 | 953 |
groups = self._get_groups(g_account) |
949 |
if g_name in groups: |
|
954 |
if g_name in groups.keys():
|
|
950 | 955 |
g_perms.update(groups[g_name]) |
951 | 956 |
else: |
952 | 957 |
g_perms.add(y) |
953 | 958 |
perms[x] = g_perms |
954 | 959 |
|
960 |
user = smart_unicode(user, strings_only=True) |
|
955 | 961 |
if op == 'read' and ('*' in perms['read'] or user in perms['read']): |
956 | 962 |
return True |
957 | 963 |
if '*' in perms['write'] or user in perms['write']: |
Also available in: Unified diff