diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2010-09-08 17:18:02 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2010-09-08 17:18:02 +0100 |
commit | 2fb283b24b41f8c12f6b62ba023a1ea03815a213 (patch) | |
tree | ffbfdf1cc2b4f480e1b3274cc5a02c2d94fd178c | |
parent | efa751c2b583d4902928ced8950acc3f2e801caa (diff) | |
download | rabbitmq-server-2fb283b24b41f8c12f6b62ba023a1ea03815a213.tar.gz |
Don't trample on admin status updating password, refactor.bug22983
-rw-r--r-- | src/rabbit_access_control.erl | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/src/rabbit_access_control.erl b/src/rabbit_access_control.erl index b4af5b09..e4bb6918 100644 --- a/src/rabbit_access_control.erl +++ b/src/rabbit_access_control.erl @@ -241,15 +241,9 @@ delete_user(Username) -> R. change_password(Username, Password) -> - R = rabbit_misc:execute_mnesia_transaction( - rabbit_misc:with_user( - Username, - fun () -> - ok = mnesia:write(rabbit_user, - #user{username = Username, - password = Password}, - write) - end)), + R = update_user(Username, fun(User) -> + User#user{password = Password} + end), rabbit_log:info("Changed password for user ~p~n", [Username]), R. @@ -260,20 +254,22 @@ clear_admin(Username) -> set_admin(Username, false). set_admin(Username, IsAdmin) -> - R = rabbit_misc:execute_mnesia_transaction( - rabbit_misc:with_user( - Username, - fun () -> - {ok, User} = lookup_user(Username), - ok = mnesia:write(rabbit_user, - User#user{username = Username, - is_admin = IsAdmin}, - write) - end)), + R = update_user(Username, fun(User) -> + User#user{is_admin = IsAdmin} + end), rabbit_log:info("Set user admin flag for user ~p to ~p~n", [Username, IsAdmin]), R. +update_user(Username, Fun) -> + rabbit_misc:execute_mnesia_transaction( + rabbit_misc:with_user( + Username, + fun () -> + {ok, User} = lookup_user(Username), + ok = mnesia:write(rabbit_user, Fun(User), write) + end)). + list_users() -> [{Username, IsAdmin} || #user{username = Username, is_admin = IsAdmin} <- |