feat: Enhance Adventure and Collection Management
- Added support for multiple collections in AdventureSerializer, allowing adventures to be linked to multiple collections. - Implemented validation to ensure collections belong to the current user during adventure creation and updates. - Introduced a signal to update adventure publicity based on the public status of linked collections. - Updated file permission checks to consider multiple collections when determining access rights. - Modified AdventureImageViewSet and AttachmentViewSet to check access against collections instead of a single collection. - Enhanced AdventureViewSet to support filtering and sorting adventures based on collections. - Updated frontend components to manage collections more effectively, including linking and unlinking adventures from collections. - Adjusted API endpoints and data structures to accommodate the new collections feature. - Improved user experience with appropriate notifications for collection actions.
This commit is contained in:
@@ -20,22 +20,10 @@ export const load = (async (event) => {
|
||||
};
|
||||
} else {
|
||||
let adventure = (await request.json()) as AdditionalAdventure;
|
||||
let collection: Collection | null = null;
|
||||
|
||||
if (adventure.collection) {
|
||||
let res2 = await fetch(`${endpoint}/api/collections/${adventure.collection}/`, {
|
||||
headers: {
|
||||
Cookie: `sessionid=${event.cookies.get('sessionid')}`
|
||||
},
|
||||
credentials: 'include'
|
||||
});
|
||||
collection = await res2.json();
|
||||
}
|
||||
|
||||
return {
|
||||
props: {
|
||||
adventure,
|
||||
collection
|
||||
adventure
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -360,12 +360,18 @@
|
||||
? `🌍 ${$t('adventures.public')}`
|
||||
: `🔒 ${$t('adventures.private')}`}
|
||||
</div>
|
||||
{#if data.props.collection}
|
||||
<!-- {#if data.props.collection}
|
||||
<div class="badge badge-sm badge-outline">
|
||||
📚 <a href="/collections/{data.props.collection.id}" class="link"
|
||||
>{data.props.collection.name}</a
|
||||
>
|
||||
</div>
|
||||
{/if} -->
|
||||
{#if adventure.collections && adventure.collections.length > 0}
|
||||
<div class="badge badge-sm badge-outline">
|
||||
📚
|
||||
<p>{adventure.collections.length} {$t('navbar.collections')}</p>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -362,12 +362,21 @@
|
||||
} else {
|
||||
let adventure = event.detail;
|
||||
|
||||
// add the collection id to the adventure collections array
|
||||
if (!adventure.collections) {
|
||||
adventure.collections = [collection.id];
|
||||
} else {
|
||||
if (!adventure.collections.includes(collection.id)) {
|
||||
adventure.collections.push(collection.id);
|
||||
}
|
||||
}
|
||||
|
||||
let res = await fetch(`/api/adventures/${adventure.id}/`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ collection: collection.id.toString() })
|
||||
body: JSON.stringify({ collections: adventure.collections })
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
@@ -550,6 +559,7 @@
|
||||
on:close={() => {
|
||||
isShowingLinkModal = false;
|
||||
}}
|
||||
collectionId={collection.id}
|
||||
on:add={addAdventure}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user