When making batch from products, build query *before* starting thread
Otherwise permission checks will fail, if any are needed to build query
This commit is contained in:
parent
f68c3dd724
commit
4b586c6249
|
@ -405,10 +405,10 @@ class ProductsView(MasterView):
|
||||||
if batch_key and batch_key in supported:
|
if batch_key and batch_key in supported:
|
||||||
handler = get_batch_handler(self.rattail_config, batch_key,
|
handler = get_batch_handler(self.rattail_config, batch_key,
|
||||||
default=supported[batch_key])
|
default=supported[batch_key])
|
||||||
|
products = self.get_effective_data()
|
||||||
progress = SessionProgress(self.request, 'products.batch')
|
progress = SessionProgress(self.request, 'products.batch')
|
||||||
thread = Thread(target=self.make_batch_thread,
|
thread = Thread(target=self.make_batch_thread,
|
||||||
args=(handler, self.request.user.uuid, progress))
|
args=(handler, self.request.user.uuid, products, progress))
|
||||||
thread.start()
|
thread.start()
|
||||||
return self.render_progress({
|
return self.render_progress({
|
||||||
'key': 'products.batch',
|
'key': 'products.batch',
|
||||||
|
@ -423,16 +423,15 @@ class ProductsView(MasterView):
|
||||||
|
|
||||||
return {'supported_batches': batch_types}
|
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.
|
Threat target for making a batch from current products query.
|
||||||
"""
|
"""
|
||||||
session = RattailSession()
|
session = RattailSession()
|
||||||
user = session.query(model.User).get(user_uuid)
|
user = session.query(model.User).get(user_uuid)
|
||||||
assert user
|
assert user
|
||||||
products = self.get_effective_query(session)
|
|
||||||
batch = handler.make_batch(session, created_by=user)
|
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)
|
handler.make_initial_rows(batch, progress=progress)
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
Loading…
Reference in a new issue