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.htmlindex 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.pyindex 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 = Ingredienturl = 'nutrition:ingredient:add'- user_fail = Falsedata = {'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.pyindex 01708d29c..929084f05 100644--- a/wger/nutrition/views/ingredient.py+++ b/wger/nutrition/views/ingredient.py@@ -239,7 +239,7 @@ class IngredientEditView(WgerFormMixin, LoginRequiredMixin, PermissionRequiredMireturn 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 = Ingredientform_class = IngredientFormtitle = gettext_lazy('Add a new ingredient')+ permission_required = 'nutrition.add_ingredient'def form_valid(self, form):form.instance.language = load_language()