Skip to content

Commit

Permalink
Add permission to the tab view #3
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <tdruez@nexb.com>
  • Loading branch information
tdruez committed Dec 19, 2023
1 parent e5a5231 commit 374f163
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions product_portfolio/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,12 +500,6 @@ def get_context_data(self, **kwargs):

context = super().get_context_data(**kwargs)

context["has_change_productcomponent_permission"] = user.has_perm(
"product_portfolio.change_productcomponent"
)
context["has_change_productpackage_permission"] = user.has_perm(
"product_portfolio.change_productpackage"
)
context["has_change_codebaseresource_permission"] = user.has_perm(
"product_portfolio.change_codebaseresource"
)
Expand All @@ -521,7 +515,7 @@ def get_context_data(self, **kwargs):

context["has_edit_productpackage"] = all(
[
context["has_change_productpackage_permission"],
user.has_perm("product_portfolio.change_productpackage"),
context["has_change_permission"],
]
)
Expand All @@ -537,7 +531,7 @@ def get_context_data(self, **kwargs):
)
context["has_edit_productcomponent"] = all(
[
context["has_change_productcomponent_permission"],
user.has_perm("product_portfolio.change_productcomponent"),
context["has_change_permission"],
]
)
Expand Down Expand Up @@ -588,7 +582,7 @@ class ProductTabInventoryView(
tab_id = "inventory"

def get_context_data(self, **kwargs):
context_data = super().get_context_data(**kwargs)
context = super().get_context_data(**kwargs)

user = self.request.user
dataspace = user.dataspace
Expand Down Expand Up @@ -698,9 +692,9 @@ def get_context_data(self, **kwargs):
if isinstance(inventory_item, ProductPackage)
]

context_data["vulnerable_purls"] = vulnerablecode.get_vulnerable_purls(packages)
context["vulnerable_purls"] = vulnerablecode.get_vulnerable_purls(packages)

context_data.update(
context.update(
{
"filter_productcomponent": filter_productcomponent,
"inventory_items": dict(objects_by_feature.items()),
Expand All @@ -709,16 +703,31 @@ def get_context_data(self, **kwargs):
}
)

perms = guardian_get_perms(user, self.object)
has_product_change_permission = "change_product" in perms
context["has_edit_productcomponent"] = all(
[
has_product_change_permission,
user.has_perm("product_portfolio.change_productcomponent"),
]
)
context["has_edit_productpackage"] = all(
[
has_product_change_permission,
user.has_perm("product_portfolio.change_productpackage"),
]
)

if page_obj:
previous_url, next_url = self.get_previous_next(page_obj)
context_data.update(
context.update(
{
"previous_url": (previous_url or "") + f"#{self.tab_id}",
"next_url": (next_url or "") + f"#{self.tab_id}",
}
)

return context_data
return context

@staticmethod
def inject_scan_data(scancodeio, feature_grouped, dataspace_uuid):
Expand Down

0 comments on commit 374f163

Please sign in to comment.