Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Present dialog if attempting to remove self from dandiset #1125

Merged
merged 3 commits into from
Jul 25, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 59 additions & 11 deletions web/src/components/DLP/DandisetOwnersDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,35 @@
</v-col>
<v-col class="grey lighten-3">
<div class="my-6">
<v-dialog
v-model="selfRemovalWarningDialog"
width="40vw"
>
<v-card>
<v-card-title>
Remove yourself from this Dandiset?
</v-card-title>
<v-card-subtitle>
To regain ownership of this dandiset, you will
need another owner or an admin to add you.
</v-card-subtitle>
<v-card-actions>
<v-spacer />
<v-btn
color="secondary"
jjnesbitt marked this conversation as resolved.
Show resolved Hide resolved
@click="selfRemovalWarningDialog = false"
>
Cancel
</v-btn>
<v-btn
color="error"
jjnesbitt marked this conversation as resolved.
Show resolved Hide resolved
@click="removeOwner(user)"
>
Confirm
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-card
v-for="(owner, i) in newOwners"
:key="i"
Expand Down Expand Up @@ -249,20 +278,39 @@ export default defineComponent({
}
}

function removeOwner(owner: User) {
newOwners.value.splice(newOwners.value.map(
(u: User) => 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);
}
}

Expand Down Expand Up @@ -294,22 +342,22 @@ export default defineComponent({
}
}

const user = computed(() => dandiRest.user);

return {
searchQuery,
searchResults,
newOwners,
throttledUpdate,
addOwner,
user,
ownerIsCurrentUser,
selfRemovalWarningDialog,
removeOwner,
isSelected,
save,
clearForm,
addSelected,
checkBoxHandler,
selectedUsers,
user,
adminWarningDisplay,
};
},
Expand Down