Skip to content

Commit

Permalink
Set the proper permission for the "Inventory" tab #128
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <tdruez@nexb.com>
  • Loading branch information
tdruez committed Jun 12, 2024
1 parent 9e8f6c6 commit d73222b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 25 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ Release notes
### Version 5.1.1-dev

- Add visual indicator in hierarchy views, when an object on the far left or far right
also belong or have a hierarchy (relathionship tree).
also belong or have a hierarchy (relationship tree).
https://github.com/nexB/dejacode/issues/70

- Add search and pagination on the Product Inventory tab.
https://github.com/nexB/dejacode/issues/3
https://github.com/nexB/dejacode/issues/112

- Fix an issue displaying the "Delete" button in the "Edit Product Relationship"
modal form.
https://github.com/nexB/dejacode/issues/128

### Version 5.1.0

- Upgrade Python version to 3.12 and Django to 5.0.x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<th style="min-width: 300px;">
{% trans 'Item' %}
{{ filter_productcomponent.form.object_type }}
<button class="btn btn-xs btn-outline-dark ms-2 toggle-details" title="{% trans 'Show/hide details' %}"><i class="fas fa-plus"></i>/<i class="fas fa-minus"></i></button>
<button class="btn btn-xs btn-outline-dark ms-2 toggle-details" data-bs-toggle="tooltip" data-bs-trigger="hover" title="{% trans 'Show/hide details' %}"><i class="fas fa-plus"></i>/<i class="fas fa-minus"></i></button>
</th>
<th style="min-width: 100px;">
{% trans 'Purpose' %}
Expand Down Expand Up @@ -240,27 +240,24 @@
</div>
{% endspaceless %}

{% if compliance_errors %}
<script>
// Select all elements with the class 'toggle-details'
document.querySelectorAll('.toggle-details').forEach(function(toggleDetail) {
// Set the title attribute to add a tooltip
toggleDetail.setAttribute('title', 'Your Tooltip Text Here');

// Add event listener for 'click' event
toggleDetail.addEventListener('click', function() {
// Select all elements with the class 'extra-details'
document.querySelectorAll('.extra-details').forEach(function(extraDetail) {
// Toggle the display property
if (extraDetail.style.display === 'none' || extraDetail.style.display === '') {
extraDetail.style.display = 'table-row';
} else {
extraDetail.style.display = 'none';
}
});
});
});
<script>
// Select all elements with the class 'toggle-details'
document.querySelectorAll('.toggle-details').forEach(function(toggleDetail) {
// Add event listener for 'click' event
toggleDetail.addEventListener('click', function() {
// Select all elements with the class 'extra-details'
document.querySelectorAll('.extra-details').forEach(function(extraDetail) {
// Toggle the display property
if (extraDetail.style.display === 'none' || extraDetail.style.display === '') {
extraDetail.style.display = 'table-row';
} else {
extraDetail.style.display = 'none';
}
});
});
});

{% if compliance_errors %}
const tabInventoryLabel = document.getElementById('tab_inventory-tab');
if (tabInventoryLabel) {
var iconElement = document.createElement('i');
Expand All @@ -269,7 +266,7 @@
iconElement.setAttribute('title', 'Compliance errors');
tabInventoryLabel.insertBefore(iconElement, tabInventoryLabel.firstChild);
// Initialize the tooltip
new bootstrap.Tooltip(iconElement, { container: 'body' });
new bootstrap.Tooltip(iconElement, {container: 'body'});
}
</script>
{% endif %}
{% endif %}
</script>
13 changes: 13 additions & 0 deletions product_portfolio/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ def test_product_portfolio_detail_view_tab_inventory_availability(self):
response.context["tabsets"]["Inventory"]["label"],
)

def test_product_portfolio_detail_view_tab_permissions(self):
self.client.login(username="nexb_user", password="secret")
url = self.product1.get_url("tab_inventory")
ProductPackage.objects.create(
product=self.product1, package=self.package1, dataspace=self.dataspace
)
response = self.client.get(url)
self.assertTrue(response.context["has_edit_productcomponent"])
self.assertTrue(response.context["has_delete_productcomponent"])
self.assertTrue(response.context["has_edit_productpackage"])
self.assertTrue(response.context["has_delete_productpackage"])
self.assertContains(response, 'data-can-delete="yes"')

def test_product_portfolio_detail_view_tab_imports(self):
self.client.login(username="nexb_user", password="secret")
url = self.product1.get_absolute_url()
Expand Down
6 changes: 6 additions & 0 deletions product_portfolio/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,12 @@ def get_context_data(self, **kwargs):
user.has_perm("product_portfolio.change_productpackage"),
]
)
context["has_delete_productpackage"] = user.has_perm(
"product_portfolio.delete_productpackage"
)
context["has_delete_productcomponent"] = user.has_perm(
"product_portfolio.delete_productcomponent"
)

if page_obj:
previous_url, next_url = self.get_previous_next(page_obj)
Expand Down

0 comments on commit d73222b

Please sign in to comment.