Skip to content

Commit 8ce7058

Browse files
Handle deletion of a Channel with a related Community Library Submission (#5551)
* Handle deletion of a Channel with a related Community Library Submission * [pre-commit.ci lite] apply automatic fixes * fix code * [pre-commit.ci lite] apply automatic fixes * fix linting * fix code * fix code --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent d9f08c3 commit 8ce7058

File tree

6 files changed

+174
-59
lines changed

6 files changed

+174
-59
lines changed

contentcuration/contentcuration/frontend/administration/vuex/channelAdmin/actions.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ import { Channel } from 'shared/data/resources';
66
export function loadChannels({ commit }, params) {
77
const extendedParams = {
88
...params,
9-
deleted: Boolean(params.deleted) && params.deleted.toString() === 'true',
109
page_size: params.page_size || 25,
1110
};
1211

12+
if (params.has_community_library_submission === undefined) {
13+
extendedParams.deleted = Boolean(params.deleted) && params.deleted.toString() === 'true';
14+
}
15+
1316
const paramsSerializer = {
1417
indexes: null, // Handle arrays by providing the same query param multiple times
1518
};

contentcuration/contentcuration/frontend/channelEdit/views/TreeView/TreeViewBase.vue

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -261,29 +261,14 @@
261261
@syncing="syncInProgress"
262262
/>
263263
<QuickEditModal />
264-
<MessageDialog
265-
v-model="showDeleteModal"
266-
:header="$tr('deleteTitle')"
267-
>
268-
{{ $tr('deletePrompt') }}
269-
<template #buttons="{ close }">
270-
<VSpacer />
271-
<VBtn
272-
color="primary"
273-
flat
274-
@click="close"
275-
>
276-
{{ $tr('cancel') }}
277-
</VBtn>
278-
<VBtn
279-
color="primary"
280-
data-test="delete"
281-
@click="handleDelete"
282-
>
283-
{{ $tr('deleteChannelButton') }}
284-
</VBtn>
285-
</template>
286-
</MessageDialog>
264+
<RemoveChannelModal
265+
v-if="showDeleteModal && currentChannel"
266+
:channel-id="currentChannel.id"
267+
:can-edit="canEdit"
268+
data-test="delete-modal"
269+
@delete="handleDelete"
270+
@close="showDeleteModal = false"
271+
/>
287272
<VSpeedDial
288273
v-if="showClipboardSpeedDial"
289274
v-model="showClipboard"
@@ -359,9 +344,9 @@
359344
import MainNavigationDrawer from 'shared/views/MainNavigationDrawer';
360345
import ToolBar from 'shared/views/ToolBar';
361346
import ChannelTokenModal from 'shared/views/channel/ChannelTokenModal';
347+
import RemoveChannelModal from 'shared/views/channel/RemoveChannelModal';
362348
import OfflineText from 'shared/views/OfflineText';
363349
import ContentNodeIcon from 'shared/views/ContentNodeIcon';
364-
import MessageDialog from 'shared/views/MessageDialog';
365350
import { RouteNames as ChannelRouteNames } from 'frontend/channelList/constants';
366351
import { titleMixin } from 'shared/mixins';
367352
import DraggableRegion from 'shared/views/draggable/DraggableRegion';
@@ -378,12 +363,12 @@
378363
SubmitToCommunityLibrarySidePanel,
379364
ProgressModal,
380365
ChannelTokenModal,
366+
RemoveChannelModal,
381367
SyncResourcesModal,
382368
Clipboard,
383369
OfflineText,
384370
ContentNodeIcon,
385371
DraggablePlaceholder,
386-
MessageDialog,
387372
SavingIndicator,
388373
QuickEditModal,
389374
},
@@ -590,11 +575,6 @@
590575
inviteCollaborators: 'Invite collaborators',
591576
shareToken: 'Share token',
592577
593-
// Delete channel section
594-
deleteChannelButton: 'Delete channel',
595-
deleteTitle: 'Delete this channel',
596-
deletePrompt: 'This channel will be permanently deleted. This cannot be undone.',
597-
cancel: 'Cancel',
598578
channelDeletedSnackbar: 'Channel deleted',
599579
},
600580
};

contentcuration/contentcuration/frontend/channelList/views/Channel/ChannelItem.vue

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,14 @@
215215
</VCardActions>
216216
</VCard>
217217
<!-- Delete dialog -->
218-
<KModal
218+
<RemoveChannelModal
219219
v-if="deleteDialog"
220-
:title="canEdit ? $tr('deleteTitle') : $tr('removeTitle')"
221-
:submitText="canEdit ? $tr('deleteChannel') : $tr('removeBtn')"
222-
:cancelText="$tr('cancel')"
220+
:channel-id="channelId"
221+
:can-edit="canEdit"
223222
data-test="delete-modal"
224-
@submit="handleDelete"
225-
@cancel="deleteDialog = false"
226-
>
227-
{{ canEdit ? $tr('deletePrompt') : $tr('removePrompt') }}
228-
</KModal>
223+
@delete="handleDelete"
224+
@close="deleteDialog = false"
225+
/>
229226
<!-- Copy dialog -->
230227
<ChannelTokenModal
231228
v-if="channel && channel.published"
@@ -244,6 +241,7 @@
244241
import { RouteNames } from '../../constants';
245242
import ChannelStar from './ChannelStar';
246243
import ChannelTokenModal from 'shared/views/channel/ChannelTokenModal';
244+
import RemoveChannelModal from 'shared/views/channel/RemoveChannelModal';
247245
import Thumbnail from 'shared/views/files/Thumbnail';
248246
import Languages from 'shared/leUtils/Languages';
249247
@@ -252,6 +250,7 @@
252250
components: {
253251
ChannelStar,
254252
ChannelTokenModal,
253+
RemoveChannelModal,
255254
Thumbnail,
256255
},
257256
props: {
@@ -396,18 +395,11 @@
396395
goToWebsite: 'Go to source website',
397396
editChannel: 'Edit channel details',
398397
copyToken: 'Copy channel token',
399-
deleteChannel: 'Delete channel',
400-
deleteTitle: 'Delete this channel',
401-
removeChannel: 'Remove from channel list',
402-
removeBtn: 'Remove',
403-
removeTitle: 'Remove from channel list',
404-
deletePrompt: 'This channel will be permanently deleted. This cannot be undone.',
405-
removePrompt:
406-
'You have view-only access to this channel. Confirm that you want to remove it from your list of channels.',
407398
channelDeletedSnackbar: 'Channel deleted',
408399
channelRemovedSnackbar: 'Channel removed',
409400
channelLanguageNotSetIndicator: 'No language set',
410-
cancel: 'Cancel',
401+
deleteChannel: 'Delete channel',
402+
removeChannel: 'Remove channel',
411403
},
412404
};
413405
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<template>
2+
3+
<KModal
4+
:title="canEdit ? $tr('deleteTitle') : $tr('removeTitle')"
5+
:submitText="canEdit ? $tr('deleteChannel') : $tr('removeBtn')"
6+
:cancelText="$tr('cancel')"
7+
:submitDisabled="loading"
8+
data-test="remove-channel-modal"
9+
@submit="handleSubmit"
10+
@cancel="close"
11+
>
12+
<div
13+
v-if="loading"
14+
class="py-4 text-center"
15+
>
16+
<KCircularLoader :size="24" />
17+
</div>
18+
<template v-else>
19+
<div
20+
v-if="canEdit && hasCommunityLibrarySubmission"
21+
class="mb-3"
22+
data-test="cl-warning"
23+
>
24+
{{ $tr('deleteChannelWithCLWarning') }}
25+
</div>
26+
{{ canEdit ? $tr('deletePrompt') : $tr('removePrompt') }}
27+
</template>
28+
</KModal>
29+
30+
</template>
31+
32+
33+
<script>
34+
35+
import { ref, onMounted } from 'vue';
36+
import client from 'shared/client';
37+
import { Channel } from 'shared/data/resources';
38+
39+
export default {
40+
name: 'RemoveChannelModal',
41+
setup(props, { emit }) {
42+
const loading = ref(false);
43+
const hasCommunityLibrarySubmission = ref(false);
44+
45+
async function fetchCommunityLibrarySubmissionStatus() {
46+
loading.value = true;
47+
try {
48+
const url = Channel.getUrlFunction('has_community_library_submission')(props.channelId);
49+
const response = await client.get(url);
50+
hasCommunityLibrarySubmission.value =
51+
response.data?.has_community_library_submission ?? false;
52+
} catch (error) {
53+
hasCommunityLibrarySubmission.value = false;
54+
} finally {
55+
loading.value = false;
56+
}
57+
}
58+
59+
onMounted(() => {
60+
if (props.canEdit) {
61+
fetchCommunityLibrarySubmissionStatus();
62+
}
63+
});
64+
65+
function handleSubmit() {
66+
emit('delete');
67+
}
68+
69+
function close() {
70+
emit('close');
71+
}
72+
73+
return {
74+
loading,
75+
hasCommunityLibrarySubmission,
76+
handleSubmit,
77+
close,
78+
};
79+
},
80+
props: {
81+
channelId: {
82+
type: String,
83+
required: true,
84+
},
85+
canEdit: {
86+
type: Boolean,
87+
default: false,
88+
},
89+
},
90+
emits: ['delete', 'close'],
91+
$trs: {
92+
deleteTitle: 'Delete this channel',
93+
removeTitle: 'Remove from channel list',
94+
deleteChannel: 'Delete channel',
95+
removeBtn: 'Remove',
96+
cancel: 'Cancel',
97+
deletePrompt: 'This channel will be permanently deleted. This cannot be undone.',
98+
removePrompt:
99+
'You have view-only access to this channel. Confirm that you want to remove it from your list of channels.',
100+
deleteChannelWithCLWarning:
101+
'This channel has been shared with the Community Library. Deleting it here will not remove it from the Community Library — it may still be approved or remain available there.',
102+
},
103+
};
104+
105+
</script>
106+
107+
108+
<style lang="scss" scoped></style>

contentcuration/contentcuration/tests/viewsets/test_channel.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -819,25 +819,43 @@ def test_admin_channel_filter__community_library_live(self):
819819
[submission1.channel.id],
820820
)
821821

822-
def test_admin_channel_filter__has_community_library_submission(self):
823-
self.client.force_authenticate(user=self.admin_user)
824-
822+
def test_has_community_library_submission_endpoint(self):
823+
"""Test the on-demand has_community_library_submission endpoint"""
824+
user = testdata.user()
825+
channel_with_submission = testdata.channel()
826+
channel_with_submission.editors.add(user)
827+
channel_with_submission.version = 1
828+
channel_with_submission.save()
825829
submission = testdata.community_library_submission()
830+
submission.channel = channel_with_submission
831+
submission.author = user
832+
submission.channel_version = channel_with_submission.version
833+
submission.save()
834+
835+
channel_without_submission = testdata.channel()
836+
channel_without_submission.editors.add(user)
826837

827-
testdata.channel() # Another channel without submission
838+
self.client.force_authenticate(user=user)
828839

829840
response = self.client.get(
830-
reverse_with_query(
831-
"admin-channels-list",
832-
query={"has_community_library_submission": True},
841+
reverse(
842+
"channel-has-community-library-submission",
843+
kwargs={"pk": channel_with_submission.id},
833844
),
834845
format="json",
835846
)
836847
self.assertEqual(response.status_code, 200, response.content)
837-
self.assertCountEqual(
838-
[ch["id"] for ch in response.data],
839-
[submission.channel.id],
848+
self.assertTrue(response.data["has_community_library_submission"])
849+
850+
response = self.client.get(
851+
reverse(
852+
"channel-has-community-library-submission",
853+
kwargs={"pk": channel_without_submission.id},
854+
),
855+
format="json",
840856
)
857+
self.assertEqual(response.status_code, 200, response.content)
858+
self.assertFalse(response.data["has_community_library_submission"])
841859

842860
def test_create_channel(self):
843861
user = testdata.user()

contentcuration/contentcuration/viewsets/channel.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,19 @@ def get_published_data(self, request, pk=None) -> Response:
900900

901901
return Response(channel.published_data)
902902

903+
@action(
904+
detail=True,
905+
methods=["get"],
906+
url_path="has_community_library_submission",
907+
url_name="has-community-library-submission",
908+
)
909+
def has_community_library_submission(self, request, pk=None) -> Response:
910+
channel = self.get_object()
911+
has_submission = CommunityLibrarySubmission.objects.filter(
912+
channel_id=channel.id
913+
).exists()
914+
return Response({"has_community_library_submission": has_submission})
915+
903916
def _channel_exists(self, channel_id) -> bool:
904917
"""
905918
Check if a channel exists.
@@ -1051,6 +1064,7 @@ def annotate_queryset(self, queryset):
10511064

10521065

10531066
class AdminChannelFilter(BaseChannelFilter):
1067+
10541068
latest_community_library_submission_status = CharFilter(
10551069
method="filter_latest_community_library_submission_status"
10561070
)

0 commit comments

Comments
 (0)