views: flag connectors with open access on homepage (#42123)

This commit is contained in:
Valentin Deniaud 2020-06-09 16:26:42 +02:00 committed by Frédéric Péters
parent 8ade392b04
commit 3ba4e0e6e3
4 changed files with 51 additions and 5 deletions

View File

@ -597,6 +597,14 @@ class BaseResource(models.Model):
exception_to_text(exc_value),
exc_info=exc_info)
@property
def has_open_access_right(self):
return AccessRight.objects.filter(
resource_type=ContentType.objects.get_for_model(self),
resource_pk=self.pk,
apiuser__key=''
).exists()
@six.python_2_unicode_compatible
class AccessRight(models.Model):

View File

@ -54,6 +54,10 @@ div#logs table tr.level-critical {
select#id_msg_class { max-width: 30em; }
.connector.is-open a {
color: #088a08;
}
li span.connector-name {
display: block;
position: absolute;
@ -61,15 +65,20 @@ li span.connector-name {
width: 100%;
}
li span.connector-type {
li span.connector-details {
display: block;
font-size: 80%;
opacity: 0.6;
color: #576b6b;
position: absolute;
bottom: 2ex;
width: 100%;
}
li span.connector-details .connector-open {
color: #088a08;
font-weight: bold;
}
ul.connectors {
clear: both;
}

View File

@ -19,9 +19,15 @@
<div>
<ul class="objects-list single-links connectors">
{% for a in apps %}
<li class="connector {{ a.get_css_class_name }} status-{{ a.get_availability_status.status }}"
><a href="{{ a.get_absolute_url }}"><span class="connector-name">{{ a.title }}</span>
<span class="connector-type">({{ a.get_verbose_name }})</span></a></li>
{% with a.has_open_access_right as is_open %}
<li class="connector {{ a.get_css_class_name }} status-{{ a.get_availability_status.status }} {% if is_open %}is-open{% endif %}">
<a href="{{ a.get_absolute_url }}">
<span class="connector-name">{{ a.title }}</span>
<span class="connector-details">({{ a.get_verbose_name }}{% if is_open %},
<span class="connector-open">{% trans "open access" %}</span>{% endif %})</span>
</a>
</li>
{% endwith %}
{% endfor %}
</ul>
</div>

View File

@ -560,3 +560,26 @@ def test_manager_add_open_access_warning(app, admin_user):
resp.form['confirm_open_access'] = True
resp.form.submit().follow()
assert AccessRight.objects.count() == 2
def test_manager_open_access_flag(app, admin_user):
csv = CsvDataSource.objects.create(csv_file=File(StringIO('1;t\n'), 't.csv'), slug='t', title='t')
api = ApiUser.objects.create(username='test', fullname='test', keytype='', key='test')
app = login(app)
resp = app.get('/manage/', status=200)
assert len(resp.pyquery('li.connector')) == 1
assert not 'open access' in resp.text
obj_type = ContentType.objects.get_for_model(csv)
AccessRight.objects.create(codename='can_access', apiuser=api, resource_type=obj_type,
resource_pk=csv.pk)
resp = app.get('/manage/', status=200)
assert not 'open access' in resp.text
api.key = ''
api.save()
resp = app.get('/manage/', status=200)
assert 'open access' in resp.text