invite link basics

This commit is contained in:
vabene1111
2022-06-01 17:42:07 +02:00
parent f41e4c62d4
commit 2afab2aec8
9 changed files with 714 additions and 9 deletions

View File

@@ -20,7 +20,7 @@ from cookbook.models import (Automation, BookmarkletImport, Comment, CookLog, Cu
RecipeBookEntry, RecipeImport, ShareLink, ShoppingList,
ShoppingListEntry, ShoppingListRecipe, Step, Storage, Supermarket,
SupermarketCategory, SupermarketCategoryRelation, Sync, SyncLog, Unit,
UserFile, UserPreference, ViewLog, Space, UserSpace)
UserFile, UserPreference, ViewLog, Space, UserSpace, InviteLink)
from cookbook.templatetags.custom_tags import markdown
from recipes.settings import MEDIA_URL, AWS_ENABLED
@@ -1026,6 +1026,21 @@ class AutomationSerializer(serializers.ModelSerializer):
read_only_fields = ('created_by',)
class InviteLinkSerializer(WritableNestedModelSerializer):
group = GroupSerializer()
def create(self, validated_data):
validated_data['created_by'] = self.context['request'].user
validated_data['space'] = self.context['request'].space
return super().create(validated_data)
class Meta:
model = InviteLink
fields = (
'id', 'uuid', 'email', 'group', 'valid_until', 'used_by', 'created_by', 'created_at',)
read_only_fields = ('id', 'uuid', 'email', 'created_by', 'created_at',)
# CORS, REST and Scopes aren't currently working
# Scopes are evaluating before REST has authenticated the user assigning a None space
# I've made the change below to fix the bookmarklet, other serializers likely need a similar/better fix