Fix 500s listing permissions for nonexistent users or vhosts.
This commit is contained in:
parent
5f11115ec8
commit
f5d0d494b9
|
|
@ -16,7 +16,8 @@
|
|||
|
||||
-module(rabbit_mgmt_wm_permissions_user).
|
||||
|
||||
-export([init/1, to_json/2, content_types_provided/2, is_authorized/2]).
|
||||
-export([init/1, to_json/2, content_types_provided/2, resource_exists/2,
|
||||
is_authorized/2]).
|
||||
|
||||
-include("rabbit_mgmt.hrl").
|
||||
-include_lib("webmachine/include/webmachine.hrl").
|
||||
|
|
@ -29,6 +30,12 @@ init(_Config) -> {ok, #context{}}.
|
|||
content_types_provided(ReqData, Context) ->
|
||||
{[{"application/json", to_json}], ReqData, Context}.
|
||||
|
||||
resource_exists(ReqData, Context) ->
|
||||
{case rabbit_mgmt_wm_user:user(ReqData) of
|
||||
{ok, _} -> true;
|
||||
{error, _} -> false
|
||||
end, ReqData, Context}.
|
||||
|
||||
to_json(ReqData, Context) ->
|
||||
User = rabbit_mgmt_util:id(user, ReqData),
|
||||
Perms = rabbit_auth_backend_internal:list_user_permissions(User),
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@
|
|||
|
||||
-module(rabbit_mgmt_wm_permissions_vhost).
|
||||
|
||||
-export([init/1, to_json/2, content_types_provided/2, is_authorized/2]).
|
||||
-export([init/1, to_json/2, content_types_provided/2, resource_exists/2,
|
||||
is_authorized/2]).
|
||||
|
||||
-include("rabbit_mgmt.hrl").
|
||||
-include_lib("webmachine/include/webmachine.hrl").
|
||||
|
|
@ -29,6 +30,9 @@ init(_Config) -> {ok, #context{}}.
|
|||
content_types_provided(ReqData, Context) ->
|
||||
{[{"application/json", to_json}], ReqData, Context}.
|
||||
|
||||
resource_exists(ReqData, Context) ->
|
||||
{rabbit_vhost:exists(rabbit_mgmt_wm_vhost:id(ReqData)), ReqData, Context}.
|
||||
|
||||
to_json(ReqData, Context) ->
|
||||
VHost = rabbit_mgmt_util:id(vhost, ReqData),
|
||||
Perms = rabbit_auth_backend_internal:list_vhost_permissions(VHost),
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
-export([init/1, resource_exists/2, to_json/2,
|
||||
content_types_provided/2, content_types_accepted/2,
|
||||
is_authorized/2, allowed_methods/2, accept_content/2,
|
||||
delete_resource/2, put_user/1]).
|
||||
delete_resource/2, user/1, put_user/1]).
|
||||
|
||||
-import(rabbit_misc, [pget/2]).
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
-export([init/1, resource_exists/2, to_json/2,
|
||||
content_types_provided/2, content_types_accepted/2,
|
||||
is_authorized/2, allowed_methods/2, accept_content/2,
|
||||
delete_resource/2, put_vhost/2]).
|
||||
delete_resource/2, id/1, put_vhost/2]).
|
||||
|
||||
-import(rabbit_misc, [pget/2]).
|
||||
|
||||
|
|
|
|||
|
|
@ -174,6 +174,9 @@ permissions_list_test() ->
|
|||
2 = length(http_get("/users/myuser1/permissions")),
|
||||
1 = length(http_get("/users/myuser2/permissions")),
|
||||
|
||||
http_get("/users/notmyuser/permissions", ?NOT_FOUND),
|
||||
http_get("/vhosts/notmyvhost/permissions", ?NOT_FOUND),
|
||||
|
||||
http_delete("/users/myuser1", ?NO_CONTENT),
|
||||
http_delete("/users/myuser2", ?NO_CONTENT),
|
||||
http_delete("/vhosts/myvhost1", ?NO_CONTENT),
|
||||
|
|
|
|||
Loading…
Reference in New Issue