backoffice: agenda datasources are readonly (#48282)

This commit is contained in:
Lauréline Guérin 2021-02-16 14:42:08 +01:00
parent caa0994caa
commit e99ffa8876
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 20 additions and 1 deletions

View File

@ -375,6 +375,22 @@ def test_data_sources_view(pub):
CardDef.wipe()
def test_data_sources_agenda_view(pub):
create_superuser(pub)
NamedDataSource.wipe()
data_source = NamedDataSource(name='foobar')
data_source.data_source = {'type': 'json', 'value': 'http://some.url'}
data_source.external = 'agenda'
data_source.store()
app = login(get_app(pub))
resp = app.get('/backoffice/settings/data-sources/%s/' % data_source.id)
assert 'This data source is readonly.' in resp
assert '/backoffice/settings/data-sources/%s/edit' % data_source.id not in resp
assert '/backoffice/settings/data-sources/%s/delete' % data_source.id not in resp
def test_data_sources_edit(pub):
create_superuser(pub)
NamedDataSource.wipe()

View File

@ -233,6 +233,8 @@ class NamedDataSourcePage(Directory):
self.datasource = instance or NamedDataSource.get(component)
except KeyError:
raise errors.TraversalError()
if self.datasource.external == 'agenda':
self.datasource.readonly = True
self.datasource_ui = NamedDataSourceUI(self.datasource)
get_response().breadcrumb.append((component + '/', self.datasource.name))
self.snapshots_dir = SnapshotsDirectory(self.datasource)
@ -241,7 +243,8 @@ class NamedDataSourcePage(Directory):
r = TemplateIO(html=True)
if self.datasource.is_readonly():
r += htmltext('<div class="infonotice"><p>%s</p></div>') % _('This data source is readonly.')
r += utils.snapshot_info_block(snapshot=self.datasource.snapshot_object)
if hasattr(self.datasource, 'snapshot_object'):
r += utils.snapshot_info_block(snapshot=self.datasource.snapshot_object)
r += htmltext('<ul id="sidebar-actions">')
if not self.datasource.is_readonly():
r += htmltext('<li><a href="delete" rel="popup">%s</a></li>') % _('Delete')