diff --git a/web/src/components/DLP/DandisetOwnersDialog.vue b/web/src/components/DLP/DandisetOwnersDialog.vue index 7a97c907a..02592e21c 100644 --- a/web/src/components/DLP/DandisetOwnersDialog.vue +++ b/web/src/components/DLP/DandisetOwnersDialog.vue @@ -100,6 +100,37 @@
+ + + + Remove yourself from this Dandiset? + + + To regain ownership of this dandiset, you will + need another owner or an admin to add you. + + + + + Cancel + + + Confirm + + + + u.username, - ).indexOf(owner.username), 1); + const user = computed(() => dandiRest.user); + function ownerIsCurrentUser(owner: User) { + return user.value && user.value.username === owner.username; } - function checkBoxHandler(user: User) { + const selfRemovalWarningDialog = ref(false); + function removeOwner(owner: User | null) { + if (owner === null) { + throw new Error('Cannot remove null owner from dandiset!'); + } + + // If current user, open dialog and wait for second call to this function + if (ownerIsCurrentUser(owner) && selfRemovalWarningDialog.value === false) { + selfRemovalWarningDialog.value = true; + return; + } + + // Remove at index + const index = newOwners.value.findIndex((u) => u.username === owner.username); + newOwners.value.splice(index, 1); + + // Set dialog to false in any case + selfRemovalWarningDialog.value = false; + } + + function checkBoxHandler(_user: User) { const selectedUsersUsernames = selectedUsers.value.map((u: User) => u.username); - if (selectedUsersUsernames.includes(user.username)) { + if (selectedUsersUsernames.includes(_user.username)) { selectedUsers.value = selectedUsers.value.splice( - selectedUsersUsernames.indexOf(user.username), 1, + selectedUsersUsernames.indexOf(_user.username), 1, ); } else { - selectedUsers.value.push(user); + selectedUsers.value.push(_user); } } @@ -294,14 +344,15 @@ export default defineComponent({ } } - const user = computed(() => dandiRest.user); - return { searchQuery, searchResults, newOwners, throttledUpdate, addOwner, + user, + ownerIsCurrentUser, + selfRemovalWarningDialog, removeOwner, isSelected, save, @@ -309,7 +360,6 @@ export default defineComponent({ addSelected, checkBoxHandler, selectedUsers, - user, adminWarningDisplay, }; },