Skip to content
Snippets Groups Projects
Commit 26938d6a authored by Cam Saül's avatar Cam Saül
Browse files

Merge pull request #289 from metabase/delete_org

add DELETE /api/org/:id; add button on superadmin page
parents 73e3cbaf c1433b1a
No related branches found
No related tags found
No related merge requests found
......@@ -794,6 +794,18 @@ CoreServices.factory('Organization', ['$resource', '$cookies', function($resourc
}
}
},
delete: {
url: '/api/org/:orgId',
method: 'DELETE',
params: {
orgId: '@id'
},
headers: {
'X-CSRFToken': function() {
return $cookies.csrftoken;
}
}
},
members: {
url: '/api/org/:orgId/members',
method: 'GET',
......
......@@ -37,6 +37,18 @@ OrganizationControllers.controller('OrganizationListController', ['$scope', 'Org
}, function(error) {
console.log("Error getting organizations: ", error);
});
$scope.deleteOrganization = function(organization) {
Organization.delete({
orgId: organization.id
}, function() {
$scope.organizations = _.filter($scope.organizations, function(org) {
return org.id !== organization.id;
});
}, function(err) {
console.log("Error deleting Org:", err);
});
};
}
]);
......@@ -60,14 +72,13 @@ OrganizationControllers.controller('OrganizationDetailController', ['$scope', '$
// provide a relevant save() function
$scope.save = function(organization) {
Organization.update(organization,
function(org) {
$scope.organization = org;
},
function(error) {
console.log(error);
});
Organization.update(organization, function(org) {
$scope.organization = org;
}, function(error) {
console.log(error);
});
};
} else {
// assume we are creating a new org
$scope.organization = {};
......
......@@ -11,8 +11,9 @@
<h3 class="text-normal text-centered">Loading ...</h3>
</div>
<ul>
<li class="py2 border-bottom" ng-repeat="org in organizations">
<ul class="List">
<li class="List-item List-section py2 border-bottom" ng-repeat="org in organizations">
<button class="Button Button--remove float-right" ng-click="deleteOrganization(org)" delete-confirm>Delete</button>
<div>
<h4><a class="link" href="/superadmin/organization/{{org.id}}">{{org.name}}</a></h4>
<span>{{org.description}}</span>
......
......@@ -11,6 +11,8 @@
[metabase.util :as util]
[ring.util.request :as req]))
;; ## /api/org Endpoints
(defendpoint GET "/"
"Fetch a list of all `Orgs`. Superusers get all organizations; normal users simpliy see the orgs they are members of."
[]
......@@ -30,6 +32,9 @@
(grant-org-perm id *current-user-id* true) ; now that the Org exists, add the creator as the first admin member
new-org)) ; make sure the api response is still the newly created org
;; ## /api/org/:id Endpoints
(defendpoint GET "/:id"
"Fetch `Org` with ID."
[id]
......@@ -55,6 +60,14 @@
:name name))
(sel :one Org :id id))
(defendpoint DELETE "/:id"
"Delete an `Org`. You must be a superuser to do this."
[id]
(check-superuser)
(cascade-delete Org :id id))
;; ## /api/org/:id/members Endpoints
(defendpoint GET "/:id/members"
"Get a list of `Users` who are members of (i.e., have `OrgPerms` for) `Org`."
......
......@@ -189,6 +189,20 @@
(expect "Not found."
((user->client :rasta) :put 404 "org/1000" {}))
;; ## DELETE /api/org/:id
(expect
[true
false]
(let [org-name (random-name)
{org-id :id} (ins Org :name org-name :slug org-name)]
[(exists? Org :name org-name)
(do ((user->client :crowberto) :delete 204 (format "org/%d" org-id))
(exists? Org :name org-name))]))
;; Check that an admin for Org (non-superuser) can't delete it
(expect "You don't have permissions to do that."
((user->client :rasta) :delete 403 (format "org/%d" (:id @test-org))))
;; # MEMBERS ENDPOINTS
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment