Skip to content

Commit

Permalink
Merge pull request #1125 from dandi/754-owner-self-removal
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnesbitt authored Jul 25, 2022
2 parents 3b07b73 + 84a0c97 commit f13b5fc
Showing 1 changed file with 61 additions and 11 deletions.
72 changes: 61 additions & 11 deletions web/src/components/DLP/DandisetOwnersDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,37 @@
</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"
elevation="0"
@click="selfRemovalWarningDialog = false"
>
Cancel
</v-btn>
<v-btn
color="error"
elevation="0"
@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 +280,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 +344,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

0 comments on commit f13b5fc

Please sign in to comment.