Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Fix ingredient permission issue

Roland Geider81058b944373
diff --git a/wger/nutrition/templates/ingredient/overview.html b/wger/nutrition/templates/ingredient/overview.html
index d4431676a..334eec676 100644
--- a/wger/nutrition/templates/ingredient/overview.html
+++ b/wger/nutrition/templates/ingredient/overview.html
@@ -38,10 +38,14 @@
</div>
{% else %}
<p>
- <a href="{% url 'nutrition:ingredient:add' %}"
- class="btn btn-light btn-block">
- {% translate "No ingredients." %} {% translate "Add one now." %}
- </a>
+ {% if perms.nutrition.add_ingredient %}
+ <a href="{% url 'nutrition:ingredient:add' %}"
+ class="btn btn-light btn-block">
+ {% translate "No ingredients." %} {% translate "Add one now." %}
+ </a>
+ {% else %}
+ {% translate "No ingredients." %}
+ {% endif %}
</p>
{% endif %}
diff --git a/wger/nutrition/tests/test_ingredient.py b/wger/nutrition/tests/test_ingredient.py
index 5f4ad034c..4b8146d4b 100644
--- a/wger/nutrition/tests/test_ingredient.py
+++ b/wger/nutrition/tests/test_ingredient.py
@@ -117,7 +117,6 @@ class AddIngredientTestCase(WgerAddTestCase):
object_class = Ingredient
url = 'nutrition:ingredient:add'
- user_fail = False
data = {
'name': 'A new ingredient',
'sodium': 2,
@@ -134,7 +133,7 @@ class AddIngredientTestCase(WgerAddTestCase):
def post_test_hook(self):
"""
- Test that the creation date and the status are correctly set
+ Test that the creation date is correctly set
"""
if self.current_user == 'admin':
ingredient = Ingredient.objects.get(pk=self.pk_after)
@@ -142,8 +141,6 @@ class AddIngredientTestCase(WgerAddTestCase):
ingredient.created.replace(microsecond=0),
datetime.datetime.now(tz=datetime.timezone.utc).replace(microsecond=0),
)
- elif self.current_user == 'test':
- ingredient = Ingredient.objects.get(pk=self.pk_after)
class IngredientNameShortTestCase(WgerTestCase):
diff --git a/wger/nutrition/views/ingredient.py b/wger/nutrition/views/ingredient.py
index 01708d29c..929084f05 100644
--- a/wger/nutrition/views/ingredient.py
+++ b/wger/nutrition/views/ingredient.py
@@ -239,7 +239,7 @@ class IngredientEditView(WgerFormMixin, LoginRequiredMixin, PermissionRequiredMi
return context
-class IngredientCreateView(WgerFormMixin, CreateView):
+class IngredientCreateView(WgerFormMixin, PermissionRequiredMixin, CreateView):
"""
Generic view to add a new ingredient
"""
@@ -248,6 +248,7 @@ class IngredientCreateView(WgerFormMixin, CreateView):
model = Ingredient
form_class = IngredientForm
title = gettext_lazy('Add a new ingredient')
+ permission_required = 'nutrition.add_ingredient'
def form_valid(self, form):
form.instance.language = load_language()