Skip to content

Commit 1dc80fe

Browse files
committed
Call endpoint to request submission lock when opening submission to edit
1 parent 80bbb3d commit 1dc80fe

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

web/src/views/SubmissionPortal/StepperView.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ export default defineComponent({
7070
:name="getSubmissionLockedBy().name"
7171
:authenticated="true"
7272
/>
73-
<a href="/submission/home">
73+
<router-link :to="{ name: 'Submission Home'}">
7474
Return to submission list
75-
</a>
75+
</router-link>
7676
</v-alert>
7777
</div>
7878
</template>

web/src/views/SubmissionPortal/store/api.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ interface PaginatedResponse<T> {
5252
results: T[];
5353
}
5454

55+
interface LockOperationResult {
56+
success: boolean;
57+
message: string
58+
locked_by?: User | null;
59+
lock_updated?: string | null;
60+
}
61+
5562
async function createRecord(record: MetadataSubmission) {
5663
const resp = await client.post<MetadataSubmissionRecord>('metadata_submission', {
5764
metadata_submission: record,
@@ -83,8 +90,13 @@ async function getRecord(id: string) {
8390
return resp.data;
8491
}
8592

93+
async function lockSubmission(id: string) {
94+
const resp = await client.put<LockOperationResult>(`metadata_submission/${id}/lock`);
95+
return resp.data;
96+
}
97+
8698
async function unlockSubmission(id: string) {
87-
const resp = await client.put<string>(`metadata_submission/${id}/unlock`);
99+
const resp = await client.put<LockOperationResult>(`metadata_submission/${id}/unlock`);
88100
return resp.data;
89101
}
90102

@@ -97,5 +109,6 @@ export {
97109
getRecord,
98110
listRecords,
99111
updateRecord,
112+
lockSubmission,
100113
unlockSubmission,
101114
};

web/src/views/SubmissionPortal/store/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import CompositionApi, {
33
computed, reactive, Ref, ref, shallowRef, watch,
44
} from '@vue/composition-api';
55
import { clone, forEach } from 'lodash';
6+
import axios from 'axios';
67
import * as api from './api';
78
import { getVariants, HARMONIZER_TEMPLATES } from '../harmonizerApi';
89
import { User } from '@/data/api';
@@ -301,8 +302,22 @@ async function loadRecord(id: string) {
301302
sampleData.value = val.metadata_submission.sampleData;
302303
hasChanged.value = 0;
303304
status.value = isSubmissionStatus(val.status) ? val.status : submissionStatus.InProgress;
304-
_submissionLockedBy = val.locked_by;
305305
_permissionLevel = (val.permission_level as permissionLevelValues);
306+
307+
try {
308+
const lockResponse = await api.lockSubmission(id);
309+
_submissionLockedBy = lockResponse.locked_by || null;
310+
} catch (error) {
311+
if (axios.isAxiosError(error)) {
312+
if (error.response && error.response.status === 409) {
313+
// Another user has the lock
314+
_submissionLockedBy = error.response.data.locked_by || null;
315+
}
316+
} else {
317+
// Something went wrong, and we don't know who has the lock
318+
_submissionLockedBy = null;
319+
}
320+
}
306321
}
307322

308323
watch(payloadObject, () => { hasChanged.value += 1; }, { deep: true });

0 commit comments

Comments
 (0)