Skip to content

Commit ae076bc

Browse files
committed
Route admin users from notification into submission review mode
Gate SubmissionDetailsModal review actions on isAdmin from the Vuex store rather than an adminReview prop, so admin users arriving via any route automatically see the Review button and side panel. Remove the adminReview prop and all call sites that set it; simplify administration/router.js to props: true.
1 parent 4e4599d commit ae076bc

3 files changed

Lines changed: 87 additions & 13 deletions

File tree

contentcuration/contentcuration/frontend/administration/router.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ const router = new VueRouter({
3434
name: RouteNames.COMMUNITY_LIBRARY_SUBMISSION,
3535
path: '/community-library/:channelId/:submissionId',
3636
component: SubmissionDetailsModal,
37-
props: route => ({
38-
channelId: route.params.channelId,
39-
submissionId: route.params.submissionId,
40-
adminReview: true,
41-
}),
37+
props: true,
4238
},
4339
// Catch-all redirect to channels tab
4440
{
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { shallowMount, createLocalVue } from '@vue/test-utils';
2+
import Vuex from 'vuex';
3+
import VueRouter from 'vue-router';
4+
import SubmissionDetailsModal from '../index.vue';
5+
import {
6+
AdminCommunityLibrarySubmission,
7+
ChannelVersion,
8+
CommunityLibrarySubmission,
9+
} from 'shared/data/resources';
10+
11+
jest.mock('shared/data/resources', () => ({
12+
AdminCommunityLibrarySubmission: { fetchModel: jest.fn() },
13+
ChannelVersion: { fetchCollection: jest.fn() },
14+
CommunityLibrarySubmission: {
15+
fetchModel: jest.fn(),
16+
fetchCollection: jest.fn(() => Promise.resolve({ results: [] })),
17+
},
18+
}));
19+
20+
const localVue = createLocalVue();
21+
localVue.use(Vuex);
22+
localVue.use(VueRouter);
23+
24+
const stubChannel = {
25+
id: 'ch1',
26+
name: 'Test',
27+
thumbnail_url: null,
28+
thumbnail_encoding: null,
29+
description: '',
30+
};
31+
const stubSubmission = {
32+
id: 'sub1',
33+
channel_id: 'ch1',
34+
channel_version: 1,
35+
status: 'PENDING',
36+
version_token: null,
37+
};
38+
const stubChannelVersion = { id: 'cv1' };
39+
40+
function makeStore(isAdmin) {
41+
return new Vuex.Store({
42+
getters: { isAdmin: () => isAdmin },
43+
modules: {
44+
channel: {
45+
namespaced: true,
46+
actions: { loadChannel: jest.fn(() => Promise.resolve(stubChannel)) },
47+
},
48+
errors: { namespaced: true, actions: { handleAxiosError: jest.fn() } },
49+
},
50+
});
51+
}
52+
53+
describe('SubmissionDetailsModal', () => {
54+
beforeEach(() => {
55+
AdminCommunityLibrarySubmission.fetchModel.mockResolvedValue(stubSubmission);
56+
CommunityLibrarySubmission.fetchModel.mockResolvedValue(stubSubmission);
57+
ChannelVersion.fetchCollection.mockResolvedValue([stubChannelVersion]);
58+
});
59+
60+
afterEach(() => jest.clearAllMocks());
61+
62+
it('uses AdminCommunityLibrarySubmission when user is admin', () => {
63+
shallowMount(SubmissionDetailsModal, {
64+
localVue,
65+
store: makeStore(true),
66+
router: new VueRouter(),
67+
propsData: { channelId: 'ch1', submissionId: 'sub1' },
68+
});
69+
expect(AdminCommunityLibrarySubmission.fetchModel).toHaveBeenCalledWith('sub1');
70+
});
71+
72+
it('uses CommunityLibrarySubmission when user is not admin', () => {
73+
shallowMount(SubmissionDetailsModal, {
74+
localVue,
75+
store: makeStore(false),
76+
router: new VueRouter(),
77+
propsData: { channelId: 'ch1', submissionId: 'sub1' },
78+
});
79+
expect(CommunityLibrarySubmission.fetchModel).toHaveBeenCalledWith('sub1');
80+
});
81+
});

contentcuration/contentcuration/frontend/shared/views/communityLibrary/SubmissionDetailsModal/index.vue

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@
7474
</div>
7575
<div class="actions">
7676
<KButton
77-
v-if="adminReview && submission.status === CommunityLibraryStatus.PENDING"
77+
v-if="isAdmin && submission.status === CommunityLibraryStatus.PENDING"
7878
:text="reviewAction$()"
7979
@click="showReviewSidePanel = true"
8080
/>
8181
<ChannelActionsDropdown
82-
v-if="adminReview"
82+
v-if="isAdmin"
8383
primary
8484
:channelId="channelId"
8585
/>
@@ -105,7 +105,7 @@
105105
:channelId="channelId"
106106
/>
107107
<ReviewSubmissionSidePanel
108-
v-if="adminReview && showReviewSidePanel"
108+
v-if="isAdmin && showReviewSidePanel"
109109
:submissionId="submission.id"
110110
:channel="channel"
111111
@close="showReviewSidePanel = false"
@@ -143,10 +143,6 @@
143143
import logging from 'shared/logging';
144144
145145
const props = defineProps({
146-
adminReview: {
147-
type: Boolean,
148-
default: false,
149-
},
150146
channelId: {
151147
type: String,
152148
required: true,
@@ -163,6 +159,7 @@
163159
const route = useRoute();
164160
const router = useRouter();
165161
const store = useStore();
162+
const isAdmin = computed(() => store.getters.isAdmin);
166163
const { windowBreakpoint } = useKResponsiveWindow();
167164
168165
const isModalOpen = computed({
@@ -206,7 +203,7 @@
206203
} = useFetch({
207204
asyncFetchFunc: async () => {
208205
try {
209-
const Resource = props.adminReview
206+
const Resource = isAdmin.value
210207
? AdminCommunityLibrarySubmission
211208
: CommunityLibrarySubmission;
212209
const submission = await Resource.fetchModel(props.submissionId);

0 commit comments

Comments
 (0)