disable external recipes in hosted version

This commit is contained in:
vabene1111 2021-11-04 15:56:22 +01:00
parent 4b5edb4230
commit d681e3ced3
4 changed files with 20 additions and 9 deletions

View File

@ -63,6 +63,7 @@ from cookbook.serializer import (FoodSerializer, IngredientSerializer,
ViewLogSerializer, CookLogSerializer, RecipeBookEntrySerializer, ViewLogSerializer, CookLogSerializer, RecipeBookEntrySerializer,
RecipeOverviewSerializer, SupermarketSerializer, ImportLogSerializer, RecipeOverviewSerializer, SupermarketSerializer, ImportLogSerializer,
BookmarkletImportSerializer, SupermarketCategorySerializer, UserFileSerializer, SupermarketCategoryRelationSerializer, AutomationSerializer) BookmarkletImportSerializer, SupermarketCategorySerializer, UserFileSerializer, SupermarketCategoryRelationSerializer, AutomationSerializer)
from recipes import settings
class StandardFilterMixin(ViewSetMixin): class StandardFilterMixin(ViewSetMixin):
@ -718,10 +719,8 @@ def get_recipe_file(request, recipe_id):
@group_required('user') @group_required('user')
def sync_all(request): def sync_all(request):
if request.space.demo: if request.space.demo or settings.HOSTED:
messages.add_message( messages.add_message(request, messages.ERROR, _('This feature is not yet available in the hosted version of tandoor!'))
request, messages.ERROR, _('This feature is not available in the demo version!')
)
return redirect('index') return redirect('index')
monitors = Sync.objects.filter(active=True).filter(space=request.user.userpreference.space) monitors = Sync.objects.filter(active=True).filter(space=request.user.userpreference.space)

View File

@ -25,6 +25,7 @@ from cookbook.helper.recipe_url_import import parse_cooktime
from cookbook.models import (Comment, Food, Ingredient, Keyword, Recipe, from cookbook.models import (Comment, Food, Ingredient, Keyword, Recipe,
RecipeImport, Step, Sync, Unit, UserPreference) RecipeImport, Step, Sync, Unit, UserPreference)
from cookbook.tables import SyncTable from cookbook.tables import SyncTable
from recipes import settings
@group_required('user') @group_required('user')
@ -37,6 +38,10 @@ def sync(request):
messages.add_message(request, messages.WARNING, _('You have more users than allowed in your space.')) messages.add_message(request, messages.WARNING, _('You have more users than allowed in your space.'))
return HttpResponseRedirect(reverse('index')) return HttpResponseRedirect(reverse('index'))
if request.space.demo or settings.HOSTED:
messages.add_message(request, messages.ERROR, _('This feature is not yet available in the hosted version of tandoor!'))
return redirect('index')
if request.method == "POST": if request.method == "POST":
if not has_group_permission(request.user, ['admin']): if not has_group_permission(request.user, ['admin']):
messages.add_message(request, messages.ERROR, _('You do not have the required permissions to view this page!')) messages.add_message(request, messages.ERROR, _('You do not have the required permissions to view this page!'))

View File

@ -1,14 +1,12 @@
import os import os
from django.contrib import messages from django.contrib import messages
from django.db.models import Q
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render, redirect
from django.urls import reverse from django.urls import reverse
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from django.views.generic import UpdateView from django.views.generic import UpdateView
from django.views.generic.edit import FormMixin from django.views.generic.edit import FormMixin
from django_scopes import scopes_disabled
from cookbook.forms import (CommentForm, ExternalRecipeForm, from cookbook.forms import (CommentForm, ExternalRecipeForm,
MealPlanForm, MealPlanForm,
@ -17,12 +15,13 @@ from cookbook.forms import (CommentForm, ExternalRecipeForm,
from cookbook.helper.permission_helper import (GroupRequiredMixin, from cookbook.helper.permission_helper import (GroupRequiredMixin,
OwnerRequiredMixin, OwnerRequiredMixin,
group_required) group_required)
from cookbook.models import (Comment, Ingredient, MealPlan, from cookbook.models import (Comment, MealPlan,
MealType, Recipe, RecipeBook, RecipeImport, MealType, Recipe, RecipeImport,
Storage, Sync, UserPreference) Storage, Sync, UserPreference)
from cookbook.provider.dropbox import Dropbox from cookbook.provider.dropbox import Dropbox
from cookbook.provider.local import Local from cookbook.provider.local import Local
from cookbook.provider.nextcloud import Nextcloud from cookbook.provider.nextcloud import Nextcloud
from recipes import settings
@group_required('guest') @group_required('guest')
@ -126,6 +125,10 @@ def edit_storage(request, pk):
messages.add_message(request, messages.ERROR, _('You cannot edit this storage!')) messages.add_message(request, messages.ERROR, _('You cannot edit this storage!'))
return HttpResponseRedirect(reverse('list_storage')) return HttpResponseRedirect(reverse('list_storage'))
if request.space.demo or settings.HOSTED:
messages.add_message(request, messages.ERROR, _('This feature is not yet available in the hosted version of tandoor!'))
return redirect('index')
if request.method == "POST": if request.method == "POST":
form = StorageForm(request.POST, instance=instance) form = StorageForm(request.POST, instance=instance)
if form.is_valid(): if form.is_valid():

View File

@ -19,6 +19,7 @@ from cookbook.helper.permission_helper import (GroupRequiredMixin,
from cookbook.models import (InviteLink, MealPlan, MealType, Recipe, from cookbook.models import (InviteLink, MealPlan, MealType, Recipe,
RecipeBook, RecipeImport, ShareLink, Step, UserPreference) RecipeBook, RecipeImport, ShareLink, Step, UserPreference)
from cookbook.views.edit import SpaceFormMixing from cookbook.views.edit import SpaceFormMixing
from recipes import settings
class RecipeCreate(GroupRequiredMixin, CreateView): class RecipeCreate(GroupRequiredMixin, CreateView):
@ -90,6 +91,9 @@ class StorageCreate(GroupRequiredMixin, CreateView):
obj.created_by = self.request.user obj.created_by = self.request.user
obj.space = self.request.space obj.space = self.request.space
obj.save() obj.save()
if self.request.space.demo or settings.HOSTED:
messages.add_message(self.request, messages.ERROR, _('This feature is not yet available in the hosted version of tandoor!'))
return redirect('index')
return HttpResponseRedirect(reverse('edit_storage', kwargs={'pk': obj.pk})) return HttpResponseRedirect(reverse('edit_storage', kwargs={'pk': obj.pk}))
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):