org links don't show if user doesn't have permissions

This commit is contained in:
chrisw
2018-03-20 16:11:57 +00:00
parent a6eeb3cd73
commit c47a4ab830
5 changed files with 18 additions and 7 deletions

View File

@@ -11,6 +11,7 @@
&-item, &-item,
&-sub-item { &-sub-item {
@include bold-24;
list-style: none; list-style: none;
margin-bottom: $gutter-half; margin-bottom: $gutter-half;
} }

View File

@@ -56,6 +56,9 @@ def add_organisation():
@user_has_permissions() @user_has_permissions()
def organisation_dashboard(org_id): def organisation_dashboard(org_id):
organisation_services = organisations_client.get_organisation_services(org_id) organisation_services = organisations_client.get_organisation_services(org_id)
for service in organisation_services:
has_permission = current_user.has_permission_for_service(service['id'], 'view_activity')
service.update({'has_permission_to_view': has_permission})
return render_template( return render_template(
'views/organisations/organisation/index.html', 'views/organisations/organisation/index.html',

View File

@@ -16,7 +16,11 @@
<ul> <ul>
{% for service in organisation_services %} {% for service in organisation_services %}
<li class="browse-list-item"> <li class="browse-list-item">
<a href="{{ url_for('main.service_dashboard', service_id=service['id']) }}" class="browse-list-link">{{ service['name'] }}</a> {% if service.has_permission_to_view %}
<a href="{{ url_for('main.service_dashboard', service_id=service['id']) }}" class="browse-list-link">{{ service['name'] }}</a>
{% else %}
{{ service['name'] }}
{% endif %}
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>

View File

@@ -99,14 +99,17 @@ def test_organisation_services_show(
assert len(page.select('.browse-list-item')) == 3 assert len(page.select('.browse-list-item')) == 3
for i in range(0, 3): for i in range(0, 2):
service_name = mock_get_organisation_services(mock_get_organisation['id'])[i]['name'] service_name = mock_get_organisation_services(mock_get_organisation['id'])[i]['name']
service_id = mock_get_organisation_services(mock_get_organisation['id'])[i]['id'] service_id = mock_get_organisation_services(mock_get_organisation['id'])[i]['id']
assert normalize_spaces(page.select('.browse-list-item')[i].text) == service_name assert normalize_spaces(page.select('.browse-list-item')[i].text) == service_name
assert normalize_spaces( if i > 1:
page.select('.browse-list-item a')[i]['href'] assert normalize_spaces(
) == '/services/{}'.format(service_id) page.select('.browse-list-item a')[i]['href']
) == '/services/{}'.format(service_id)
else:
assert page.select('.browse-list-item')[i].find('a') is None
def test_view_team_members( def test_view_team_members(

View File

@@ -2756,12 +2756,12 @@ def mock_update_service_organisation(mocker):
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def mock_get_organisation_services(mocker): def mock_get_organisation_services(mocker, api_user_active):
def _get_organisation_services(organisation_id): def _get_organisation_services(organisation_id):
return [ return [
service_json('12345', 'service one'), service_json('12345', 'service one'),
service_json('67890', 'service two'), service_json('67890', 'service two'),
service_json('09876', 'service three') service_json(SERVICE_ONE_ID, 'service one', [api_user_active.id])
] ]
return mocker.patch( return mocker.patch(