Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
vabene1111 committed Jul 5, 2023
2 parents c077a64 + 7a2ccc0 commit c78b7a6
Show file tree
Hide file tree
Showing 33 changed files with 10,295 additions and 4,334 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@ jobs:
# Standard build config
- name: Standard
dockerfile: Dockerfile
platforms: linux/amd64,linux/arm64
platforms: linux/amd64,linux/arm64,linux/arm/v7
suffix: ""
continue-on-error: false
# Raspi build config
- name: Raspi
dockerfile: Dockerfile-raspi
platforms: linux/arm/v7
suffix: "-raspi"
continue-on-error: true
steps:
- uses: actions/checkout@v3

Expand Down
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM python:3.10-alpine3.15
FROM python:3.10-alpine3.18

#Install all dependencies.
RUN apk add --no-cache postgresql-libs postgresql-client gettext zlib libjpeg libwebp libxml2-dev libxslt-dev py-cryptography openldap
RUN apk add --no-cache postgresql-libs postgresql-client gettext zlib libjpeg libwebp libxml2-dev libxslt-dev openldap

#Print all logs without buffering it.
ENV PYTHONUNBUFFERED 1
Expand All @@ -15,6 +15,10 @@ WORKDIR /opt/recipes

COPY requirements.txt ./

RUN \
if [ `apk --print-arch` = "armv7" ]; then \
printf "[global]\nextra-index-url=https://www.piwheels.org/simple\n" > /etc/pip.conf ; \
fi
RUN apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev zlib-dev jpeg-dev libwebp-dev openssl-dev libffi-dev cargo openldap-dev python3-dev git && \
echo -n "INPUT ( libldap.so )" > /usr/lib/libldap_r.so && \
python -m venv venv && \
Expand Down
33 changes: 0 additions & 33 deletions Dockerfile-raspi

This file was deleted.

5 changes: 5 additions & 0 deletions cookbook/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def delete_space_action(modeladmin, request, queryset):
class SpaceAdmin(admin.ModelAdmin):
list_display = ('name', 'created_by', 'max_recipes', 'max_users', 'max_file_storage_mb', 'allow_sharing')
search_fields = ('name', 'created_by__username')
autocomplete_fields = ('created_by',)
filter_horizontal = ('food_inherit',)
list_filter = ('max_recipes', 'max_users', 'max_file_storage_mb', 'allow_sharing')
date_hierarchy = 'created_at'
actions = [delete_space_action]
Expand All @@ -50,6 +52,8 @@ class SpaceAdmin(admin.ModelAdmin):
class UserSpaceAdmin(admin.ModelAdmin):
list_display = ('user', 'space',)
search_fields = ('user__username', 'space__name',)
filter_horizontal = ('groups',)
autocomplete_fields = ('user', 'space',)


admin.site.register(UserSpace, UserSpaceAdmin)
Expand All @@ -60,6 +64,7 @@ class UserPreferenceAdmin(admin.ModelAdmin):
search_fields = ('user__username',)
list_filter = ('theme', 'nav_color', 'default_page',)
date_hierarchy = 'created_at'
filter_horizontal = ('plan_share', 'shopping_share',)

@staticmethod
def name(obj):
Expand Down
7 changes: 7 additions & 0 deletions cookbook/helper/permission_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,10 @@ def switch_user_active_space(user, space):
return us
except ObjectDoesNotExist:
return None


class IsReadOnlyDRF(permissions.BasePermission):
message = 'You cannot interact with this object as it is not owned by you!'

def has_permission(self, request, view):
return request.method in SAFE_METHODS
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 4.1.9 on 2023-06-30 20:34

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('cookbook', '0194_alter_food_properties_food_amount'),
]

operations = [
migrations.AddField(
model_name='invitelink',
name='internal_note',
field=models.TextField(blank=True, null=True),
),
migrations.AddField(
model_name='userspace',
name='internal_note',
field=models.TextField(blank=True, null=True),
),
migrations.AddField(
model_name='userspace',
name='invite_link',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='cookbook.invitelink'),
),
migrations.AlterField(
model_name='userpreference',
name='theme',
field=models.CharField(choices=[('TANDOOR', 'Tandoor'), ('BOOTSTRAP', 'Bootstrap'), ('DARKLY', 'Darkly'), ('FLATLY', 'Flatly'), ('SUPERHERO', 'Superhero'), ('TANDOOR_DARK', 'Tandoor Dark (INCOMPLETE)')], default='TANDOOR', max_length=128),
),
]
24 changes: 5 additions & 19 deletions cookbook/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ class UserSpace(models.Model, PermissionModelMixin):
# that having more than one active space should just break certain parts of the application and not leak any data
active = models.BooleanField(default=False)

invite_link = models.ForeignKey("InviteLink", on_delete=models.PROTECT, null=True, blank=True)
internal_note = models.TextField(blank=True, null=True)

created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

Expand Down Expand Up @@ -719,25 +722,6 @@ class Ingredient(ExportModelOperationsMixin('ingredient'), models.Model, Permiss
space = models.ForeignKey(Space, on_delete=models.CASCADE)
objects = ScopedManager(space='space')

def __str__(self):
food = ""
unit = ""
if self.always_use_plural_food and self.food.plural_name not in (None, "") and not self.no_amount:
food = self.food.plural_name
else:
if self.amount > 1 and self.food.plural_name not in (None, "") and not self.no_amount:
food = self.food.plural_name
else:
food = str(self.food)
if self.always_use_plural_unit and self.unit.plural_name not in (None, "") and not self.no_amount:
unit = self.unit.plural_name
else:
if self.amount > 1 and self.unit is not None and self.unit.plural_name not in (None, "") and not self.no_amount:
unit = self.unit.plural_name
else:
unit = str(self.unit)
return str(self.amount) + ' ' + str(unit) + ' ' + str(food)

class Meta:
ordering = ['order', 'pk']
indexes = (
Expand Down Expand Up @@ -1144,6 +1128,8 @@ class InviteLink(ExportModelOperationsMixin('invite_link'), models.Model, Permis
created_by = models.ForeignKey(User, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)

internal_note = models.TextField(blank=True, null=True)

space = models.ForeignKey(Space, on_delete=models.CASCADE)
objects = ScopedManager(space='space')

Expand Down
8 changes: 4 additions & 4 deletions cookbook/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ def create(self, validated_data):

class Meta:
model = UserSpace
fields = ('id', 'user', 'space', 'groups', 'active', 'created_at', 'updated_at',)
read_only_fields = ('id', 'created_at', 'updated_at', 'space')
fields = ('id', 'user', 'space', 'groups', 'active', 'internal_note', 'invite_link', 'created_at', 'updated_at',)
read_only_fields = ('id', 'invite_link', 'created_at', 'updated_at', 'space')


class SpacedModelSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -1245,7 +1245,7 @@ def create(self, validated_data):
class Meta:
model = InviteLink
fields = (
'id', 'uuid', 'email', 'group', 'valid_until', 'used_by', 'reusable', 'created_by', 'created_at',)
'id', 'uuid', 'email', 'group', 'valid_until', 'used_by', 'reusable', 'internal_note', 'created_by', 'created_at',)
read_only_fields = ('id', 'uuid', 'created_by', 'created_at',)


Expand Down Expand Up @@ -1362,7 +1362,7 @@ class Meta:
model = Recipe
fields = (
'name', 'description', 'keywords', 'steps', 'working_time',
'waiting_time', 'internal', 'nutrition', 'servings', 'servings_text',
'waiting_time', 'internal', 'nutrition', 'servings', 'servings_text', 'source_url',
)

def create(self, validated_data):
Expand Down
2 changes: 1 addition & 1 deletion cookbook/templatetags/theming_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def theme_url(request):
@register.simple_tag
def nav_color(request):
if not request.user.is_authenticated:
return 'primary'
return 'navbar-light bg-primary'

if request.user.userpreference.nav_color.lower() in ['light', 'warning', 'info', 'success']:
return f'navbar-light bg-{request.user.userpreference.nav_color.lower()}'
Expand Down
24 changes: 24 additions & 0 deletions cookbook/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@ def destroy(self, request, *args, **kwargs):
return super().destroy(request, *args, **kwargs)

def get_queryset(self):
internal_note = self.request.query_params.get('internal_note', None)
if internal_note is not None:
self.queryset = self.queryset.filter(internal_note=internal_note)

if is_space_owner(self.request.user, self.request.space):
return self.queryset.filter(space=self.request.space)
else:
Expand Down Expand Up @@ -1047,6 +1051,21 @@ def get_queryset(self):
Q(created_by=self.request.user)
| Q(shoppinglist__shared=self.request.user)
| Q(created_by__in=list(self.request.user.get_shopping_share()))
).prefetch_related(
'created_by',
'food',
'food__properties',
'food__properties__property_type',
'food__inherit_fields',
'food__supermarket_category',
'food__onhand_users',
'food__substitute',
'food__child_inherit_fields',

'unit',
'list_recipe',
'list_recipe__mealplan',
'list_recipe__mealplan__recipe',
).distinct().all()

if pk := self.request.query_params.getlist('id', []):
Expand Down Expand Up @@ -1165,6 +1184,11 @@ class InviteLinkViewSet(viewsets.ModelViewSet, StandardFilterMixin):
permission_classes = [CustomIsSpaceOwner & CustomIsAdmin & CustomTokenHasReadWriteScope]

def get_queryset(self):

internal_note = self.request.query_params.get('internal_note', None)
if internal_note is not None:
self.queryset = self.queryset.filter(internal_note=internal_note)

if is_space_owner(self.request.user, self.request.space):
self.queryset = self.queryset.filter(space=self.request.space).all()
return super().get_queryset()
Expand Down
2 changes: 1 addition & 1 deletion cookbook/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def invite_link(request, token):
link.used_by = request.user
link.save()

user_space = UserSpace.objects.create(user=request.user, space=link.space, active=False)
user_space = UserSpace.objects.create(user=request.user, space=link.space, internal_note=link.internal_note, invite_link=link, active=False)

if request.user.userspace_set.count() == 1:
user_space.active = True
Expand Down
4 changes: 3 additions & 1 deletion docs/install/docker/ipv6_plain/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "2.4"
services:
db_recipes:
restart: always
image: postgres:11-alpine
image: postgres:15-alpine
volumes:
- ${POSTGRES_DATA_DIR:-./postgresql}:/var/lib/postgresql/data
env_file:
Expand All @@ -22,6 +22,7 @@ services:
- ./.env
volumes:
- staticfiles:/opt/recipes/staticfiles
# Do not make this a bind mount, see https://docs.tandoor.dev/install/docker/#volumes-vs-bind-mounts
- nginx_config:/opt/recipes/nginx/conf.d
- ${MEDIA_FILES_DIR:-./mediafiles}:/opt/recipes/mediafiles
depends_on:
Expand All @@ -41,6 +42,7 @@ services:
depends_on:
- web_recipes
volumes:
# Do not make this a bind mount, see https://docs.tandoor.dev/install/docker/#volumes-vs-bind-mounts
- nginx_config:/etc/nginx/conf.d:ro
- staticfiles:/static:ro
- ${MEDIA_FILES_DIR:-./mediafiles}:/media:ro
Expand Down
4 changes: 3 additions & 1 deletion docs/install/docker/nginx-proxy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3"
services:
db_recipes:
restart: always
image: postgres:11-alpine
image: postgres:15-alpine
volumes:
- ./postgresql:/var/lib/postgresql/data
env_file:
Expand All @@ -17,6 +17,7 @@ services:
- ./.env
volumes:
- staticfiles:/opt/recipes/staticfiles
# Do not make this a bind mount, see https://docs.tandoor.dev/install/docker/#volumes-vs-bind-mounts
- nginx_config:/opt/recipes/nginx/conf.d
- ./mediafiles:/opt/recipes/mediafiles
depends_on:
Expand All @@ -32,6 +33,7 @@ services:
depends_on:
- web_recipes
volumes:
# Do not make this a bind mount, see https://docs.tandoor.dev/install/docker/#volumes-vs-bind-mounts
- nginx_config:/etc/nginx/conf.d:ro
- staticfiles:/static:ro
- ./mediafiles:/media:ro
Expand Down
4 changes: 3 additions & 1 deletion docs/install/docker/plain/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3"
services:
db_recipes:
restart: always
image: postgres:11-alpine
image: postgres:15-alpine
volumes:
- ./postgresql:/var/lib/postgresql/data
env_file:
Expand All @@ -15,6 +15,7 @@ services:
- ./.env
volumes:
- staticfiles:/opt/recipes/staticfiles
# Do not make this a bind mount, see https://docs.tandoor.dev/install/docker/#volumes-vs-bind-mounts
- nginx_config:/opt/recipes/nginx/conf.d
- ./mediafiles:/opt/recipes/mediafiles
depends_on:
Expand All @@ -30,6 +31,7 @@ services:
depends_on:
- web_recipes
volumes:
# Do not make this a bind mount, see https://docs.tandoor.dev/install/docker/#volumes-vs-bind-mounts
- nginx_config:/etc/nginx/conf.d:ro
- staticfiles:/static:ro
- ./mediafiles:/media:ro
Expand Down
4 changes: 3 additions & 1 deletion docs/install/docker/traefik-nginx/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3"
services:
db_recipes:
restart: always
image: postgres:11-alpine
image: postgres:15-alpine
volumes:
- ./postgresql:/var/lib/postgresql/data
env_file:
Expand All @@ -17,6 +17,7 @@ services:
- ./.env
volumes:
- staticfiles:/opt/recipes/staticfiles
# Do not make this a bind mount, see https://docs.tandoor.dev/install/docker/#volumes-vs-bind-mounts
- nginx_config:/opt/recipes/nginx/conf.d
- ./mediafiles:/opt/recipes/mediafiles
depends_on:
Expand All @@ -30,6 +31,7 @@ services:
env_file:
- ./.env
volumes:
# Do not make this a bind mount, see https://docs.tandoor.dev/install/docker/#volumes-vs-bind-mounts
- nginx_config:/etc/nginx/conf.d:ro
- staticfiles:/static:ro
- ./mediafiles:/media:ro
Expand Down
2 changes: 1 addition & 1 deletion docs/install/swag.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ services:
db_recipes:
restart: always
container_name: db_recipes
image: postgres:11-alpine
image: postgres:15-alpine
volumes:
- ./recipes/db:/var/lib/postgresql/data
env_file:
Expand Down
Loading

0 comments on commit c78b7a6

Please sign in to comment.