Skip to content

Commit 43d00de

Browse files
MaffoochMaffooch
andauthored
Fix Authorized User bugs (#3146)
Co-authored-by: Maffooch <[email protected]>
1 parent 6978806 commit 43d00de

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

dojo/product_type/views.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ def add_product_type(request):
8787
@user_passes_test(lambda u: u.is_staff)
8888
def edit_product_type(request, ptid):
8989
pt = get_object_or_404(Product_Type, pk=ptid)
90-
pt_form = Product_TypeForm(instance=pt)
90+
authed_users = pt.authorized_users.all()
91+
pt_form = Product_TypeForm(instance=pt, initial={'authorized_users': authed_users})
9192
delete_pt_form = Delete_Product_TypeForm(instance=pt)
9293
if request.method == "POST" and request.POST.get('edit_product_type'):
9394
pt_form = Product_TypeForm(request.POST, instance=pt)
9495
if pt_form.is_valid():
9596
pt = pt_form.save()
97+
pt.authorized_users.set(pt_form.cleaned_data['authorized_users'])
9698
messages.add_message(
9799
request,
98100
messages.SUCCESS,

dojo/user/views.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,12 @@ def edit_user(request, uid):
310310

311311
if form.is_valid() and contact_form.is_valid():
312312
form.save()
313+
for init_auth_prods in authed_products:
314+
init_auth_prods.authorized_users.remove(user)
315+
init_auth_prods.save()
316+
for init_auth_prod_types in authed_product_types:
317+
init_auth_prod_types.authorized_users.remove(user)
318+
init_auth_prod_types.save()
313319
if 'authorized_products' in form.cleaned_data and len(form.cleaned_data['authorized_products']) > 0:
314320
for p in form.cleaned_data['authorized_products']:
315321
p.authorized_users.add(user)

0 commit comments

Comments
 (0)