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 media import get_id
|
||||
import state
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -183,6 +184,9 @@ class UploadHandler(tornado.web.RequestHandler):
|
|||
with open(import_name, 'wb') as fd:
|
||||
fd.write(upload.body)
|
||||
file = add_file(id, import_name, prefix_books)
|
||||
else:
|
||||
user = state.user()
|
||||
file.item.add_user(user)
|
||||
if listname and ids:
|
||||
l = List.get(settings.USER_ID, listname)
|
||||
if l:
|
||||
|
|
|
@ -92,8 +92,10 @@ class Item(db.Model):
|
|||
return item
|
||||
|
||||
def add_user(self, user):
|
||||
if not user in self.users:
|
||||
self.users.append(user)
|
||||
l = user.library
|
||||
if not self in l.items:
|
||||
l.items.append(self)
|
||||
state.db.session.add(l)
|
||||
|
||||
|
@ -382,7 +384,11 @@ class Item(db.Model):
|
|||
primaryid = self.meta.get('primaryid')
|
||||
logger.debug('scrape %s', primaryid)
|
||||
if primaryid:
|
||||
try:
|
||||
m = meta.lookup(*primaryid)
|
||||
except:
|
||||
logger.debug('meta.lookup %s failed:', primaryid, exc_info=True)
|
||||
m = None
|
||||
if m:
|
||||
m['primaryid'] = primaryid
|
||||
self.meta = m
|
||||
|
|
Loading…
Reference in a new issue