From 4b586c6249bcee6d70a5885d89fd57c3f37ead6f Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 6 Jan 2017 17:36:50 -0600 Subject: [PATCH] When making batch from products, build query *before* starting thread Otherwise permission checks will fail, if any are needed to build query --- tailbone/views/products.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tailbone/views/products.py b/tailbone/views/products.py index 56e9679a..99a243ef 100644 --- a/tailbone/views/products.py +++ b/tailbone/views/products.py @@ -405,10 +405,10 @@ class ProductsView(MasterView): if batch_key and batch_key in supported: handler = get_batch_handler(self.rattail_config, batch_key, default=supported[batch_key]) - + products = self.get_effective_data() progress = SessionProgress(self.request, 'products.batch') thread = Thread(target=self.make_batch_thread, - args=(handler, self.request.user.uuid, progress)) + args=(handler, self.request.user.uuid, products, progress)) thread.start() return self.render_progress({ 'key': 'products.batch', @@ -423,16 +423,15 @@ class ProductsView(MasterView): return {'supported_batches': batch_types} - def make_batch_thread(self, handler, user_uuid, progress): + def make_batch_thread(self, handler, user_uuid, products, progress): """ Threat target for making a batch from current products query. """ session = RattailSession() user = session.query(model.User).get(user_uuid) assert user - products = self.get_effective_query(session) batch = handler.make_batch(session, created_by=user) - batch.products = products.all() + batch.products = products.with_session(session).all() handler.make_initial_rows(batch, progress=progress) session.commit()