0001-manager-rename-site_json-field-24921.patch
src/authentic2/manager/forms.py | ||
---|---|---|
674 | 674 |
class SiteImportForm(forms.Form): |
675 | 675 |
file_field_label = _('Site Export File') |
676 | 676 | |
677 |
site_json = forms.FileField(label=file_field_label)
|
|
677 |
import_file = forms.FileField(label=file_field_label)
|
|
678 | 678 | |
679 |
def clean_site_json(self):
|
|
679 |
def clean_import_file(self):
|
|
680 | 680 |
try: |
681 |
return json.loads(self.cleaned_data['site_json'].read().decode())
|
|
681 |
return json.loads(self.cleaned_data['import_file'].read().decode())
|
|
682 | 682 |
except ValueError: |
683 | 683 |
raise ValidationError(_('File is not in the expected JSON format.')) |
684 | 684 |
src/authentic2/manager/ou_views.py | ||
---|---|---|
137 | 137 |
try: |
138 | 138 |
context = data_transfer.ImportContext(import_roles=False) |
139 | 139 |
with transaction.atomic(): |
140 |
data_transfer.import_site(form.cleaned_data['site_json'], context)
|
|
140 |
data_transfer.import_site(form.cleaned_data['import_file'], context)
|
|
141 | 141 |
except ValidationError as e: |
142 |
form.add_error('site_json', e)
|
|
142 |
form.add_error('import_file', e)
|
|
143 | 143 |
return self.form_invalid(form) |
144 | 144 | |
145 | 145 |
return super().form_valid(form) |
src/authentic2/manager/role_views.py | ||
---|---|---|
572 | 572 |
try: |
573 | 573 |
context = data_transfer.ImportContext(import_ous=False, set_ou=self.ou) |
574 | 574 |
with transaction.atomic(): |
575 |
data_transfer.import_site(form.cleaned_data['site_json'], context)
|
|
575 |
data_transfer.import_site(form.cleaned_data['import_file'], context)
|
|
576 | 576 |
except ValidationError as e: |
577 |
form.add_error('site_json', e)
|
|
577 |
form.add_error('import_file', e)
|
|
578 | 578 |
return self.form_invalid(form) |
579 | 579 | |
580 | 580 |
return super().form_valid(form) |
src/authentic2/manager/views.py | ||
---|---|---|
721 | 721 |
def form_valid(self, form): |
722 | 722 |
try: |
723 | 723 |
with transaction.atomic(): |
724 |
import_site(form.cleaned_data['site_json'], ImportContext())
|
|
724 |
import_site(form.cleaned_data['import_file'], ImportContext())
|
|
725 | 725 |
except ValidationError as e: |
726 |
form.add_error('site_json', e)
|
|
726 |
form.add_error('import_file', e)
|
|
727 | 727 |
return self.form_invalid(form) |
728 | 728 | |
729 | 729 |
return super(SiteImportView, self).form_valid(form) |
tests/test_manager.py | ||
---|---|---|
710 | 710 |
"uuid": "6eb7bbf64bf547119120f925f0e560ac" |
711 | 711 |
}] |
712 | 712 |
} |
713 |
form['site_json'] = Upload(
|
|
713 |
form['import_file'] = Upload(
|
|
714 | 714 |
'site_export.json', force_bytes(json.dumps(site_export).encode('ascii')), 'application/octet-stream') |
715 | 715 |
res = form.submit() |
716 | 716 |
assert res.status_code == 302 |
... | ... | |
735 | 735 |
"uuid": "6eb7bbf64bf547119120f925f0e560ac" |
736 | 736 |
}] |
737 | 737 |
} |
738 |
form['site_json'] = Upload(
|
|
738 |
form['import_file'] = Upload(
|
|
739 | 739 |
'site_export.json', force_bytes(json.dumps(site_export).encode('ascii')), 'application/octet-stream') |
740 | 740 |
res = form.submit() |
741 | 741 |
assert res.status_code == 200 |
... | ... | |
743 | 743 |
with pytest.raises(Role.DoesNotExist): |
744 | 744 |
Role.objects.get(slug='basic') |
745 | 745 | |
746 |
form['site_json'] = Upload(
|
|
746 |
form['import_file'] = Upload(
|
|
747 | 747 |
'site_export.json', force_bytes(json.dumps([])), 'application/octet-stream') |
748 | 748 |
res = form.submit() |
749 | 749 |
assert res.status_code == 200 |
tests/test_ou_manager.py | ||
---|---|---|
59 | 59 | |
60 | 60 |
resp = app.get('/manage/organizational-units/') |
61 | 61 |
resp = resp.click('Import') |
62 |
resp.form['site_json'] = Upload('export.json', json.dumps(export).encode(), 'application/json')
|
|
62 |
resp.form['import_file'] = Upload('export.json', json.dumps(export).encode(), 'application/json')
|
|
63 | 63 |
resp = resp.form.submit().follow() |
64 | 64 | |
65 | 65 |
assert OU.objects.filter(name=ou1.name).exists() |
... | ... | |
78 | 78 |
"name": "should_not_exist", |
79 | 79 |
}] |
80 | 80 |
resp = resp.click('Import') |
81 |
resp.form['site_json'] = Upload('export.json', json.dumps(export).encode(), 'application/json')
|
|
81 |
resp.form['import_file'] = Upload('export.json', json.dumps(export).encode(), 'application/json')
|
|
82 | 82 |
resp = resp.form.submit().follow() |
83 | 83 | |
84 | 84 |
assert not Role.objects.filter(slug="should_not_exist").exists() |
tests/test_role_manager.py | ||
---|---|---|
130 | 130 | |
131 | 131 |
resp = app.get('/manage/roles/') |
132 | 132 |
resp = resp.click('Import') |
133 |
resp.form['site_json'] = Upload('export.json', json.dumps(export).encode(), 'application/json')
|
|
133 |
resp.form['import_file'] = Upload('export.json', json.dumps(export).encode(), 'application/json')
|
|
134 | 134 |
resp = resp.form.submit().follow() |
135 | 135 | |
136 | 136 |
assert Role.objects.filter(name=role_ou1.name, ou=get_default_ou()).exists() |
... | ... | |
147 | 147 | |
148 | 148 |
resp = app.get('/manage/roles/') |
149 | 149 |
resp = resp.click('Import') |
150 |
resp.form['site_json'] = Upload('export.json', json.dumps(export).encode(), 'application/json')
|
|
150 |
resp.form['import_file'] = Upload('export.json', json.dumps(export).encode(), 'application/json')
|
|
151 | 151 |
resp.form['ou'] = ou1.pk |
152 | 152 |
resp = resp.form.submit().follow() |
153 | 153 | |
... | ... | |
163 | 163 |
}] |
164 | 164 |
resp = app.get('/manage/roles/') # unselect ou1 |
165 | 165 |
resp = resp.click('Import') |
166 |
resp.form['site_json'] = Upload('export.json', json.dumps(export).encode(), 'application/json')
|
|
166 |
resp.form['import_file'] = Upload('export.json', json.dumps(export).encode(), 'application/json')
|
|
167 | 167 |
resp = resp.form.submit().follow() |
168 | 168 | |
169 | 169 |
assert not OrganizationalUnit.objects.filter(slug="should_not_exist").exists() |
... | ... | |
184 | 184 |
assert not 'Organizational unit' in resp.text |
185 | 185 |
assert resp.form['ou'].attrs['type'] == 'hidden' |
186 | 186 | |
187 |
resp.form['site_json'] = Upload('export.json', json.dumps(export).encode(), 'application/json')
|
|
187 |
resp.form['import_file'] = Upload('export.json', json.dumps(export).encode(), 'application/json')
|
|
188 | 188 |
resp = resp.form.submit().follow() |
189 | 189 | |
190 | 190 |
imported_role = Role.objects.get(slug=simple_role.slug) |
191 |
- |