|
12 | 12 | -include_lib("khepri/include/khepri.hrl"). |
13 | 13 | -include_lib("rabbit_common/include/rabbit.hrl"). |
14 | 14 |
|
| 15 | +-include("include/khepri.hrl"). |
| 16 | + |
15 | 17 | -export([create/1, |
16 | 18 | update/2, |
17 | 19 | get/1, |
@@ -489,13 +491,12 @@ set_user_permissions_in_khepri(Username, VHostName, UserPermission) -> |
489 | 491 | end)), rw). |
490 | 492 |
|
491 | 493 | set_user_permissions_in_khepri_tx(Username, VHostName, UserPermission) -> |
| 494 | + %% TODO: Check user presence in a transaction. |
492 | 495 | Path = khepri_user_permission_path( |
493 | | - #if_all{conditions = |
494 | | - [Username, |
495 | | - #if_node_exists{exists = true}]}, |
| 496 | + Username, |
496 | 497 | VHostName), |
497 | 498 | Extra = #{keep_while => |
498 | | - #{rabbit_db_vhost:khepri_vhost_path(VHostName) => |
| 499 | + #{rabbit_db_user:khepri_user_path(Username) => |
499 | 500 | #if_node_exists{exists = true}}}, |
500 | 501 | Ret = khepri_tx:put( |
501 | 502 | Path, UserPermission, Extra), |
@@ -877,14 +878,13 @@ set_topic_permissions_in_khepri(Username, VHostName, TopicPermission) -> |
877 | 878 | set_topic_permissions_in_khepri_tx(Username, VHostName, TopicPermission) -> |
878 | 879 | #topic_permission{topic_permission_key = |
879 | 880 | #topic_permission_key{exchange = ExchangeName}} = TopicPermission, |
| 881 | + %% TODO: Check user presence in a transaction. |
880 | 882 | Path = khepri_topic_permission_path( |
881 | | - #if_all{conditions = |
882 | | - [Username, |
883 | | - #if_node_exists{exists = true}]}, |
| 883 | + Username, |
884 | 884 | VHostName, |
885 | 885 | ExchangeName), |
886 | 886 | Extra = #{keep_while => |
887 | | - #{rabbit_db_vhost:khepri_vhost_path(VHostName) => |
| 887 | + #{rabbit_db_user:khepri_user_path(Username) => |
888 | 888 | #if_node_exists{exists = true}}}, |
889 | 889 | Ret = khepri_tx:put(Path, TopicPermission, Extra), |
890 | 890 | case Ret of |
@@ -1094,15 +1094,14 @@ clear_in_khepri() -> |
1094 | 1094 |
|
1095 | 1095 | khepri_user_path(Username) |
1096 | 1096 | when ?IS_KHEPRI_PATH_CONDITION(Username) -> |
1097 | | - [?MODULE, users, Username]. |
| 1097 | + ?KHEPRI_ROOT_PATH ++ [users, Username]. |
1098 | 1098 |
|
1099 | 1099 | khepri_user_permission_path(Username, VHostName) |
1100 | | - when ?IS_KHEPRI_PATH_CONDITION(Username) andalso |
1101 | | - ?IS_KHEPRI_PATH_CONDITION(VHostName) -> |
1102 | | - [?MODULE, users, Username, user_permissions, VHostName]. |
| 1100 | + when ?IS_KHEPRI_PATH_CONDITION(Username) -> |
| 1101 | + (rabbit_db_vhost:khepri_vhost_path(VHostName) ++ |
| 1102 | + [user_permissions, Username]). |
1103 | 1103 |
|
1104 | 1104 | khepri_topic_permission_path(Username, VHostName, Exchange) |
1105 | | - when ?IS_KHEPRI_PATH_CONDITION(Username) andalso |
1106 | | - ?IS_KHEPRI_PATH_CONDITION(VHostName) andalso |
1107 | | - ?IS_KHEPRI_PATH_CONDITION(Exchange) -> |
1108 | | - [?MODULE, users, Username, topic_permissions, VHostName, Exchange]. |
| 1105 | + when ?IS_KHEPRI_PATH_CONDITION(Username) -> |
| 1106 | + (rabbit_db_exchange:khepri_exchange_path(VHostName, Exchange) ++ |
| 1107 | + [user_permissions, Username]). |
0 commit comments