0002-settings-add-export-import-for-api_access-objects-48.patch
tests/admin_pages/test_all.py | ||
---|---|---|
18 | 18 | |
19 | 19 |
from quixote.http_request import Upload as QuixoteUpload |
20 | 20 | |
21 | 21 |
from wcs.qommon.form import UploadedFile |
22 | 22 |
from wcs.qommon.ident.password_accounts import PasswordAccount |
23 | 23 |
from wcs.qommon.http_request import HTTPRequest |
24 | 24 |
from wcs.qommon.template import get_current_theme |
25 | 25 |
from wcs.admin.settings import UserFieldsFormDef |
26 |
from wcs.api_access import ApiAccess |
|
26 | 27 |
from wcs.categories import Category, CardDefCategory |
27 | 28 |
from wcs.data_sources import NamedDataSource |
28 | 29 |
from wcs.wscalls import NamedWsCall |
29 | 30 |
from wcs.roles import Role |
30 | 31 |
from wcs.workflows import ( |
31 | 32 |
Workflow, CommentableWorkflowStatusItem, |
32 | 33 |
ChoiceWorkflowStatusItem, JumpOnSubmitWorkflowStatusItem) |
33 | 34 |
from wcs.wf.export_to_model import ExportToModel |
... | ... | |
639 | 640 |
FormDef.wipe() |
640 | 641 |
CardDef.wipe() |
641 | 642 |
Workflow.wipe() |
642 | 643 |
Role.wipe() |
643 | 644 |
Category.wipe() |
644 | 645 |
CardDefCategory.wipe() |
645 | 646 |
NamedDataSource.wipe() |
646 | 647 |
NamedWsCall.wipe() |
648 |
ApiAccess.wipe() |
|
647 | 649 | |
648 | 650 |
wipe() |
649 | 651 |
create_superuser(pub) |
650 | 652 |
app = login(get_app(pub)) |
651 | 653 |
resp = app.get('/backoffice/settings/export') |
652 | 654 |
resp = resp.form.submit('cancel') |
653 | 655 |
resp = app.get('/backoffice/settings/export') |
654 | 656 |
resp = resp.form.submit('submit') |
... | ... | |
687 | 689 |
upload.fp = BytesIO() |
688 | 690 |
upload.fp.write(file_content) |
689 | 691 |
upload.fp.seek(0) |
690 | 692 |
export_to.model_file = UploadedFile('models', 'export_to_model-1.upload', upload) |
691 | 693 |
st1.items.append(export_to) |
692 | 694 |
export_to.parent = st1 |
693 | 695 |
wf.store() |
694 | 696 | |
697 |
api_access = ApiAccess() |
|
698 |
api_access.name = 'Jhon' |
|
699 |
api_access.api_identifier = 'jhon' |
|
700 |
api_access.api_key = '1234' |
|
701 |
api_access.store() |
|
702 | ||
695 | 703 |
resp = app.get('/backoffice/settings/export') |
696 | 704 |
resp = resp.form.submit('submit') |
697 | 705 |
assert resp.location.startswith('http://example.net/backoffice/settings/export?job=') |
698 | 706 |
job_id = urlparse.parse_qs(urlparse.urlparse(resp.location).query)['job'][0] |
699 | 707 |
resp = resp.follow() |
700 | 708 |
resp = resp.click('Download Export') |
701 | 709 |
zip_content = BytesIO(resp.body) |
702 | 710 |
zipf = zipfile.ZipFile(zip_content, 'a') |
... | ... | |
708 | 716 |
assert 'workflows/1' not in filelist |
709 | 717 |
assert 'workflows_xml/1' in filelist |
710 | 718 |
assert 'models/export_to_model-1.upload' not in filelist |
711 | 719 |
assert 'roles/1' in filelist |
712 | 720 |
assert 'categories/1' in filelist |
713 | 721 |
assert 'carddef_categories/1' in filelist |
714 | 722 |
assert 'datasources/1' in filelist |
715 | 723 |
assert 'wscalls/corge' in filelist |
724 |
assert 'apiaccess/1' in filelist |
|
716 | 725 |
for filename in filelist: |
717 | 726 |
assert '.indexes' not in filename |
718 | 727 | |
719 | 728 |
wipe() |
720 | 729 |
assert FormDef.count() == 0 |
721 | 730 | |
722 | 731 |
resp = app.get('/backoffice/settings/import') |
723 | 732 |
resp = resp.form.submit('cancel') |
... | ... | |
732 | 741 |
resp = resp.form.submit('submit') |
733 | 742 |
assert 'Imported successfully' in resp.text |
734 | 743 |
assert '1 forms' in resp.text |
735 | 744 |
assert '1 cards' in resp.text |
736 | 745 |
assert FormDef.count() == 1 |
737 | 746 |
assert FormDef.select()[0].url_name == 'foo' |
738 | 747 |
assert CardDef.count() == 1 |
739 | 748 |
assert CardDef.select()[0].url_name == 'bar' |
749 |
assert ApiAccess.count() == 1 |
|
740 | 750 | |
741 | 751 |
# check roles are found by name |
742 | 752 |
wipe() |
743 | 753 |
role = Role(name='qux') |
744 | 754 |
role.store() |
745 | 755 | |
746 | 756 |
workflow = Workflow(name='Workflow One') |
747 | 757 |
st1 = workflow.add_status(name='st1') |
wcs/admin/settings.py | ||
---|---|---|
874 | 874 |
if not get_cfg('sp', {}).get('idp-manage-roles'): |
875 | 875 |
form.add(CheckboxWidget, 'roles', title = _('Roles'), value = True) |
876 | 876 |
form.add(CheckboxWidget, 'categories', title = _('Categories'), value = True) |
877 | 877 |
form.add(CheckboxWidget, 'carddef_categories', title = _('Card Model Categories'), value = True) |
878 | 878 |
form.add(CheckboxWidget, 'settings', title = _('Settings'), value = False) |
879 | 879 |
form.add(CheckboxWidget, 'datasources', title=_('Data sources'), value=True) |
880 | 880 |
form.add(CheckboxWidget, 'mail-templates', title=_('Mail templates'), value=True) |
881 | 881 |
form.add(CheckboxWidget, 'wscalls', title=_('Webservice calls'), value=True) |
882 |
form.add(CheckboxWidget, 'apiaccess', title=_('API access'), value=True) |
|
882 | 883 |
form.add_submit('submit', _('Submit')) |
883 | 884 |
form.add_submit('cancel', _('Cancel')) |
884 | 885 |
if form.get_submit() == 'cancel': |
885 | 886 |
return redirect('.') |
886 | 887 | |
887 | 888 |
if not form.is_submitted(): |
888 | 889 |
get_response().breadcrumb.append(('export', _('Export'))) |
889 | 890 |
html_top('settings', title = _('Export')) |
... | ... | |
897 | 898 |
self.app_dir = get_publisher().app_dir |
898 | 899 |
self.dirs = dirs |
899 | 900 |
self.settings = settings |
900 | 901 | |
901 | 902 |
def export(self, job): |
902 | 903 |
c = BytesIO() |
903 | 904 |
z = zipfile.ZipFile(c, 'w') |
904 | 905 |
for d in self.dirs: |
905 |
if d not in ('roles', 'categories', 'carddef_categories', 'datasources', 'wscalls', 'mail-templates'): |
|
906 |
if d not in ('roles', 'categories', 'carddef_categories', 'datasources', |
|
907 |
'wscalls', 'mail-templates', 'apiaccess'): |
|
906 | 908 |
continue |
907 | 909 |
path = os.path.join(self.app_dir, d) |
908 | 910 |
if not os.path.exists(path): |
909 | 911 |
continue |
910 | 912 |
for f in os.listdir(path): |
911 | 913 |
if f == '.indexes': |
912 | 914 |
continue |
913 | 915 |
z.write(os.path.join(path, f), os.path.join(d, f)) |
... | ... | |
946 | 948 |
z.write(os.path.join(self.app_dir, 'config', f), os.path.join('config', f)) |
947 | 949 |
z.close() |
948 | 950 | |
949 | 951 |
job.file_content = c.getvalue() |
950 | 952 |
job.store() |
951 | 953 | |
952 | 954 |
dirs = [] |
953 | 955 |
for w in ('formdefs', 'carddefs', 'workflows', 'roles', 'categories', 'carddef_categories', |
954 |
'datasources', 'wscalls', 'mail-templates', 'blockdefs'): |
|
956 |
'datasources', 'wscalls', 'mail-templates', 'blockdefs', 'apiaccess'):
|
|
955 | 957 |
if form.get_widget(w) and form.get_widget(w).parse(): |
956 | 958 |
dirs.append(w) |
957 | 959 |
if not dirs and not form.get_widget('settings').parse(): |
958 | 960 |
return redirect('.') |
959 | 961 | |
960 | 962 |
exporter = Exporter(dirs, settings=form.get_widget('settings').parse()) |
961 | 963 | |
962 | 964 |
job = get_response().add_after_job( |
... | ... | |
1048 | 1050 |
if results['settings']: |
1049 | 1051 |
r += htmltext('<li>%s</li>') % _('Settings') |
1050 | 1052 |
if results['datasources']: |
1051 | 1053 |
r += htmltext('<li>%d %s</li>') % (results['datasources'], _('data sources')) |
1052 | 1054 |
if results['mail-templates']: |
1053 | 1055 |
r += htmltext('<li>%d %s</li>') % (results['mail-templates'], _('mail templates')) |
1054 | 1056 |
if results['wscalls']: |
1055 | 1057 |
r += htmltext('<li>%d %s</li>') % (results['wscalls'], _('webservice calls')) |
1058 |
if results['apiaccess']: |
|
1059 |
r += htmltext('<li>%d %s</li>') % (results['apiaccess'], _('API access')) |
|
1056 | 1060 |
r += htmltext('</ul>') |
1057 | 1061 |
else: |
1058 | 1062 |
r += htmltext('<p>%s %s</p>') % (_('Error:'), reason) |
1059 | 1063 |
r += htmltext('<a href=".">%s</a>') % _('Back') |
1060 | 1064 |
return r.getvalue() |
1061 | 1065 | |
1062 | 1066 |
def import_submit(self, form): |
1063 | 1067 |
return get_publisher().import_zip(form.get_widget('file').parse().fp) |
wcs/publisher.py | ||
---|---|---|
163 | 163 | |
164 | 164 |
self.session_manager_class = sessions.StorageSessionManager |
165 | 165 |
self.set_session_manager(self.session_manager_class(session_class=self.session_class)) |
166 | 166 | |
167 | 167 |
def import_zip(self, fd): |
168 | 168 |
z = zipfile.ZipFile(fd) |
169 | 169 |
results = {'formdefs': 0, 'carddefs': 0, 'workflows': 0, 'categories': 0, 'roles': 0, |
170 | 170 |
'settings': 0, 'datasources': 0, 'wscalls': 0, 'mail-templates': 0, |
171 |
'blockdefs': 0} |
|
171 |
'blockdefs': 0, 'apiaccess': 0}
|
|
172 | 172 | |
173 | 173 |
def _decode_list(data): |
174 | 174 |
rv = [] |
175 | 175 |
for item in data: |
176 | 176 |
if isinstance(item, six.string_types): |
177 | 177 |
item = force_str(item) |
178 | 178 |
elif isinstance(item, list): |
179 | 179 |
item = _decode_list(item) |
180 |
- |