Skip to content

Commit e4c43a2

Browse files
Prevent inconsistent states beteween public channels and community ch… (#5500)
* Prevent inconsistent states beteween public channels and community channels * [pre-commit.ci lite] apply automatic fixes * fix linting * fix linting * fixing code according to comments * [pre-commit.ci lite] apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 60e0ad8 commit e4c43a2

File tree

6 files changed

+332
-0
lines changed

6 files changed

+332
-0
lines changed

contentcuration/contentcuration/frontend/administration/components/ConfirmationDialog.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
:header="title"
66
:text="text"
77
>
8+
<div
9+
v-if="errorText"
10+
class="error-text lighten-4 ma-3 pa-2 red red--text"
11+
>
12+
{{ errorText }}
13+
</div>
814
<template #buttons="{ close }">
915
<VBtn
1016
flat
@@ -17,6 +23,7 @@
1723
color="primary"
1824
dark
1925
data-test="confirm"
26+
:disabled="disableSubmit"
2027
@click="$emit('confirm')"
2128
>
2229
{{ confirmButtonText }}
@@ -55,6 +62,14 @@
5562
type: String,
5663
default: 'Cancel',
5764
},
65+
errorText: {
66+
type: String,
67+
default: '',
68+
},
69+
disableSubmit: {
70+
type: Boolean,
71+
default: false,
72+
},
5873
},
5974
computed: {
6075
show: {

contentcuration/contentcuration/frontend/administration/pages/Channels/ChannelActionsDropdown.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
v-model="makePublicDialog"
1515
title="Make channel public"
1616
:text="`All users will be able to view and import content from ${name}.`"
17+
:error-text="communityChannelErrorMessage"
18+
:disable-submit="isCommunityChannel"
1719
data-test="confirm-public"
1820
confirmButtonText="Make public"
1921
@confirm="makePublicHandler"
@@ -124,6 +126,7 @@
124126
import ConfirmationDialog from '../../components/ConfirmationDialog';
125127
import { RouteNames } from '../../constants';
126128
import { channelExportMixin } from 'shared/views/channel/mixins';
129+
import { CommunityLibraryStatus } from 'shared/constants';
127130
128131
export default {
129132
name: 'ChannelActionsDropdown',
@@ -160,6 +163,16 @@
160163
},
161164
};
162165
},
166+
isCommunityChannel() {
167+
const status = this.channel.latest_community_library_submission_status;
168+
return status === CommunityLibraryStatus.APPROVED || status === CommunityLibraryStatus.LIVE;
169+
},
170+
communityChannelErrorMessage() {
171+
if (this.isCommunityChannel) {
172+
return 'This channel has been added to the Community Library and cannot be marked public.';
173+
}
174+
return '';
175+
},
163176
},
164177
methods: {
165178
...mapActions('channelAdmin', [

contentcuration/contentcuration/models.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,22 @@ def make_public(self, bypass_signals=False):
12681268

12691269
return self
12701270

1271+
def is_community_channel(self):
1272+
return self.community_library_submissions.filter(
1273+
status__in=[
1274+
community_library_submission.STATUS_APPROVED,
1275+
community_library_submission.STATUS_LIVE,
1276+
]
1277+
).exists()
1278+
1279+
def clean(self):
1280+
super().clean()
1281+
if self.public and self.is_community_channel():
1282+
raise ValidationError(
1283+
"This channel has been added to the Community Library and cannot be marked public.",
1284+
code="public_community_conflict",
1285+
)
1286+
12711287
def mark_publishing(self, user):
12721288
self.history.create(actor_id=to_pk(user), action=channel_history.PUBLICATION)
12731289
self.main_tree.publishing = True
@@ -2626,6 +2642,12 @@ def save(self, *args, **kwargs):
26262642
code="impossibly_high_channel_version",
26272643
)
26282644

2645+
if self.channel.public:
2646+
raise ValidationError(
2647+
"Cannot create a community library submission for a public channel.",
2648+
code="public_channel_submission",
2649+
)
2650+
26292651
if self.pk is None:
26302652
# When creating a new submission, ensure the channel has a versioned database
26312653
# (it might not have if the channel was published before versioned databases

contentcuration/contentcuration/viewsets/channel.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,15 @@ class Meta:
11111111
list_serializer_class = BulkListSerializer
11121112
nested_writes = True
11131113

1114+
def validate_public(self, value):
1115+
if value and hasattr(self, "instance") and self.instance:
1116+
if self.instance.is_community_channel():
1117+
raise ValidationError(
1118+
"This channel has been added to the Community Library and cannot be marked public.",
1119+
code="public_community_conflict",
1120+
)
1121+
return value
1122+
11141123

11151124
class AdminChannelViewSet(ChannelViewSet, RESTUpdateModelMixin, RESTDestroyModelMixin):
11161125
pagination_class = CatalogListPagination

contentcuration/contentcuration/viewsets/community_library_submission.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ def update(self, instance, validated_data):
121121
"Cannot resolve a community library submission that is not pending."
122122
)
123123

124+
if (
125+
"status" in validated_data
126+
and validated_data["status"]
127+
== community_library_submission_constants.STATUS_APPROVED
128+
and instance.channel.public
129+
):
130+
raise ValidationError(
131+
"Cannot approve a community library submission for a channel that has been marked public."
132+
)
133+
124134
if "status" not in validated_data or validated_data["status"] not in [
125135
community_library_submission_constants.STATUS_APPROVED,
126136
community_library_submission_constants.STATUS_REJECTED,

0 commit comments

Comments
 (0)