make sure dropped file is owned by user
This commit is contained in:
parent
a3fb9d1545
commit
fbf06a1545
2 changed files with 14 additions and 4 deletions
|
@ -22,6 +22,7 @@ import tornado.concurrent
|
||||||
from oxtornado import json_dumps, json_response
|
from oxtornado import json_dumps, json_response
|
||||||
|
|
||||||
from media import get_id
|
from media import get_id
|
||||||
|
import state
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -183,6 +184,9 @@ class UploadHandler(tornado.web.RequestHandler):
|
||||||
with open(import_name, 'wb') as fd:
|
with open(import_name, 'wb') as fd:
|
||||||
fd.write(upload.body)
|
fd.write(upload.body)
|
||||||
file = add_file(id, import_name, prefix_books)
|
file = add_file(id, import_name, prefix_books)
|
||||||
|
else:
|
||||||
|
user = state.user()
|
||||||
|
file.item.add_user(user)
|
||||||
if listname and ids:
|
if listname and ids:
|
||||||
l = List.get(settings.USER_ID, listname)
|
l = List.get(settings.USER_ID, listname)
|
||||||
if l:
|
if l:
|
||||||
|
|
|
@ -92,8 +92,10 @@ class Item(db.Model):
|
||||||
return item
|
return item
|
||||||
|
|
||||||
def add_user(self, user):
|
def add_user(self, user):
|
||||||
|
if not user in self.users:
|
||||||
self.users.append(user)
|
self.users.append(user)
|
||||||
l = user.library
|
l = user.library
|
||||||
|
if not self in l.items:
|
||||||
l.items.append(self)
|
l.items.append(self)
|
||||||
state.db.session.add(l)
|
state.db.session.add(l)
|
||||||
|
|
||||||
|
@ -382,7 +384,11 @@ class Item(db.Model):
|
||||||
primaryid = self.meta.get('primaryid')
|
primaryid = self.meta.get('primaryid')
|
||||||
logger.debug('scrape %s', primaryid)
|
logger.debug('scrape %s', primaryid)
|
||||||
if primaryid:
|
if primaryid:
|
||||||
|
try:
|
||||||
m = meta.lookup(*primaryid)
|
m = meta.lookup(*primaryid)
|
||||||
|
except:
|
||||||
|
logger.debug('meta.lookup %s failed:', primaryid, exc_info=True)
|
||||||
|
m = None
|
||||||
if m:
|
if m:
|
||||||
m['primaryid'] = primaryid
|
m['primaryid'] = primaryid
|
||||||
self.meta = m
|
self.meta = m
|
||||||
|
|
Loading…
Reference in a new issue