Skip to content

Commit

Permalink
add ability to remove myself from the owner list (#3379)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmuehsig authored and Scott Bommarito committed Dec 7, 2016
1 parent 4a325ed commit a72832e
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/NuGetGallery/Views/Packages/ManagePackageOwners.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<li>
<span data-bind="text: name"></span> <em data-bind="visible: current">(that&#8217;s you!)</em>
<em data-bind="visible: pending">(pending approval)</em>
<a href="#" title="Remove as owner of @Model.Title" data-bind="visible: !current, click: $root.removeOwner">Remove</a>
<a href="#" title="Remove as owner of @Model.Title" data-bind="visible: !current || $parent.hasMoreThanOneOwner, click: $root.removeOwner">Remove</a>
</li>
</ul>

Expand Down Expand Up @@ -58,6 +58,10 @@
message: ko.observable(''),
hasMoreThanOneOwner: function() {
return true;
},
addOwner: function () {
var newUsername = viewModel.newOwnerUsername();
var message = viewModel.newOwnerMessage();
Expand Down Expand Up @@ -117,6 +121,15 @@
var package = viewModel.package;
var headers = { '__RequestVerificationToken': $('input[name=""__RequestVerificationToken""]').val() };
var proceedToRemoveFunction = true;
if (item.current) {
proceedToRemoveFunction = confirm("Are you sure you want to remove yourself from the owners?");
}
if (proceedToRemoveFunction === false)
return;
$.ajax({
url: '@Url.Action("RemovePackageOwner", "JsonApi")?id=' + package.id + '&username=' + item.name(),
cache: false,
Expand All @@ -126,6 +139,10 @@
contentType: 'application/json; charset=utf-8',
success: function (data) {
if (data.success) {
if (item.current) {
window.location.href = '@Url.Package(Model.Id)';
}
viewModel.owners.remove(item);
// when an operation succeeds, always clear the error message
Expand All @@ -139,6 +156,24 @@
}
};
viewModel.hasMoreThanOneOwner = ko.computed(function () {
if (this.owners().length < 2)
return false;
var approvedOwner = 0;
ko.utils.arrayForEach(this.owners(), function (owner) {
if (owner.pending() === false)
approvedOwner++;
});
if (approvedOwner >= 2)
return true;
return false;
}, viewModel);
ko.applyBindings(viewModel);
// Load initial owners.
Expand Down

0 comments on commit a72832e

Please sign in to comment.