-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs.py
32 lines (21 loc) · 1.06 KB
/
funcs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from models import MyUser, Directory, Share
def check(current_user_key, cwd_id):
owner = MyUser.get(cwd_id.split('/')[0])
if owner:
directory = Directory.get_by_id(cwd_id, owner.key);
if directory:
parent = None
is_shared = directory.is_users_dir(current_user_key)
if not is_shared:
parent = directory
while parent and not is_shared and current_user_key not in parent.lock:
is_shared = parent.is_shared_to_me(current_user_key)
if not is_shared:
parent = parent.get_parent()
if is_shared:
return owner, directory, parent
return None, None, None
def has_write_permission(myuser_key, parent):
query = Share.ancestor_query().filter(Share.user == myuser_key)
share = query.filter(Share.folder == parent.key).get()
return share.permission == 'rw'