mirror of
https://gitee.com/dgiiot/dgiot.git
synced 2024-12-02 12:18:30 +08:00
feat: add get_childrole user
This commit is contained in:
parent
13d4148880
commit
b829eedfed
@ -51,7 +51,7 @@ Dlink协议是针对物联网开发领域设计的一种数据交换规范,数
|
|||||||
|
|
||||||
|
|
||||||
## payload设计
|
## payload设计
|
||||||
### 属性上报 ($dg/user/{deviceId}/properties/report)
|
### 属性上报 ($dg/thing/{productId}/{deviceAddr}/properties/report)
|
||||||
+ dlink json格式
|
+ dlink json格式
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
|
|
||||||
properties_report(ProductId, DevAddr, Payload) when is_map(Payload) ->
|
properties_report(ProductId, DevAddr, Payload) when is_map(Payload) ->
|
||||||
|
io:format("~s ~p ProductId ~p, DevAddr ~p, Payload: ~p ~n", [?FILE, ?LINE, ProductId, DevAddr, Payload]),
|
||||||
dgiot_task:save_td(ProductId, DevAddr, Payload, #{});
|
dgiot_task:save_td(ProductId, DevAddr, Payload, #{});
|
||||||
|
|
||||||
properties_report(ProductId, DevAddr, Payload) ->
|
properties_report(ProductId, DevAddr, Payload) ->
|
||||||
@ -34,7 +35,7 @@ properties_report(ProductId, DevAddr, Payload) ->
|
|||||||
(_) ->
|
(_) ->
|
||||||
pass
|
pass
|
||||||
end, dgiot_bridge:get_proctol_channel(ProductId)),
|
end, dgiot_bridge:get_proctol_channel(ProductId)),
|
||||||
%% io:format("~s ~p ProductId ~p, DevAddr ~p, Payload: ~p ~n", [?FILE, ?LINE, ProductId, DevAddr, Payload]),
|
io:format("~s ~p ProductId ~p, DevAddr ~p, Payload: ~p ~n", [?FILE, ?LINE, ProductId, DevAddr, Payload]),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
login(_A, _B, _C) ->
|
login(_A, _B, _C) ->
|
||||||
|
@ -549,6 +549,17 @@
|
|||||||
"type": "number",
|
"type": "number",
|
||||||
"default": 1,
|
"default": 1,
|
||||||
"description": "limit, 显示多少条记录,显示100条记录 eg:100"
|
"description": "limit, 显示多少条记录,显示100条记录 eg:100"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "include",
|
||||||
|
"in": "query",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false,
|
||||||
|
"enum": [
|
||||||
|
false,
|
||||||
|
true
|
||||||
|
],
|
||||||
|
"description": "include 是否包含子部门用户"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
@ -33,8 +33,9 @@
|
|||||||
put_User_Role/3,
|
put_User_Role/3,
|
||||||
put_roleuser/2,
|
put_roleuser/2,
|
||||||
post_roleuser/2,
|
post_roleuser/2,
|
||||||
get_roleuser/2,
|
get_roleuser/3,
|
||||||
del_roleuser/2
|
del_roleuser/2,
|
||||||
|
get_UserIds/1
|
||||||
]).
|
]).
|
||||||
-export([create_user/2, delete_user/2, put_user/2, disableusere/3, check_roles/1]).
|
-export([create_user/2, delete_user/2, put_user/2, disableusere/3, check_roles/1]).
|
||||||
-export([login_by_account/2, login_by_token/2, login_by_mail_phone/1, do_login/1]).
|
-export([login_by_account/2, login_by_token/2, login_by_mail_phone/1, do_login/1]).
|
||||||
@ -81,6 +82,14 @@ role_ets(RoleId) ->
|
|||||||
_ -> pass
|
_ -> pass
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
get_UserIds(RoleId) ->
|
||||||
|
case dgiot_data:get(?ROLE_USER_ETS, RoleId) of
|
||||||
|
not_find ->
|
||||||
|
[];
|
||||||
|
UserIds ->
|
||||||
|
UserIds
|
||||||
|
end.
|
||||||
|
|
||||||
save_RoleIds(UserId, RoleId) ->
|
save_RoleIds(UserId, RoleId) ->
|
||||||
case dgiot_data:get(?USER_ROLE_ETS, UserId) of
|
case dgiot_data:get(?USER_ROLE_ETS, UserId) of
|
||||||
not_find ->
|
not_find ->
|
||||||
@ -261,25 +270,29 @@ refresh_session(Token) ->
|
|||||||
}).
|
}).
|
||||||
|
|
||||||
|
|
||||||
get_roleuser(Filter, SessionToken) ->
|
get_roleuser(Filter, IncludeChild, SessionToken) ->
|
||||||
case dgiot_parse:query_object(<<"_Role">>, Filter,
|
case dgiot_parse:query_object(<<"_Role">>, Filter,
|
||||||
[{"X-Parse-Session-Token", SessionToken}], [{from, rest}]) of
|
[{"X-Parse-Session-Token", SessionToken}], [{from, rest}]) of
|
||||||
{ok, #{<<"results">> := Roles}} ->
|
{ok, #{<<"results">> := Roles}} ->
|
||||||
Users =
|
Users =
|
||||||
lists:foldl(fun(#{<<"objectId">> := RoleId} = Role, Acc) ->
|
lists:foldl(fun(#{<<"objectId">> := RoleId} = Role, Acc) ->
|
||||||
|
ChildRoleIds =
|
||||||
|
case IncludeChild of
|
||||||
|
true ->
|
||||||
|
dgiot_role:get_childrole(RoleId);
|
||||||
|
false ->
|
||||||
|
[RoleId]
|
||||||
|
end,
|
||||||
|
UserIds =
|
||||||
|
lists:foldl(fun(ChildRoleId, Acc2) ->
|
||||||
|
Acc2 ++ dgiot_parse_auth:get_UserIds(ChildRoleId)
|
||||||
|
end, [], ChildRoleIds),
|
||||||
UsersQuery =
|
UsersQuery =
|
||||||
#{<<"where">> => #{<<"$relatedTo">> => #{
|
#{<<"where">> => #{<<"objectId">> => #{<<"$in">> => UserIds}},
|
||||||
<<"object">> => #{
|
<<"keys">> => []
|
||||||
<<"__type">> => <<"Pointer">>,
|
|
||||||
<<"className">> => <<"_Role">>,
|
|
||||||
<<"objectId">> => RoleId
|
|
||||||
},
|
|
||||||
<<"key">> => <<"users">>}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
case dgiot_parse:query_object(<<"_User">>, UsersQuery) of
|
case dgiot_parse:query_object(<<"_User">>, UsersQuery) of
|
||||||
{ok, #{<<"results">> := Results}} ->
|
{ok, #{<<"results">> := Results}} ->
|
||||||
|
|
||||||
Acc ++ lists:foldl(fun(X, Acc2) ->
|
Acc ++ lists:foldl(fun(X, Acc2) ->
|
||||||
Acc2 ++ [X#{<<"role">> => maps:with([<<"org_type">>, <<"tag">>, <<"depname">>], Role)}]
|
Acc2 ++ [X#{<<"role">> => maps:with([<<"org_type">>, <<"tag">>, <<"depname">>], Role)}]
|
||||||
end, [], Results);
|
end, [], Results);
|
||||||
|
@ -65,7 +65,8 @@ get_childrole(Role) ->
|
|||||||
{error, not_find} ->
|
{error, not_find} ->
|
||||||
[Role];
|
[Role];
|
||||||
Values ->
|
Values ->
|
||||||
childrole(Values, dgiot_utils:unique_1(Values ++ [Role]))
|
FlatValues = dgiot_utils:unique_1(lists:flatten(Values)),
|
||||||
|
dgiot_utils:unique_1(lists:flatten(childrole(FlatValues, FlatValues ++ [Role])))
|
||||||
end.
|
end.
|
||||||
|
|
||||||
childrole([], Acc) ->
|
childrole([], Acc) ->
|
||||||
@ -75,7 +76,8 @@ childrole([Role | Roles], Acc) ->
|
|||||||
{error, not_find} ->
|
{error, not_find} ->
|
||||||
childrole(Roles, Acc);
|
childrole(Roles, Acc);
|
||||||
Values ->
|
Values ->
|
||||||
childrole(dgiot_utils:unique_1(Roles ++ Values), Acc ++ Values)
|
FlatValues = dgiot_utils:unique_1(lists:flatten(Values)),
|
||||||
|
childrole(dgiot_utils:unique_1(Roles ++ FlatValues), Acc ++ FlatValues)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
load_roles() ->
|
load_roles() ->
|
||||||
|
@ -204,8 +204,9 @@ do_request(post_logout, #{<<"sessionToken">> := SessionToken}, _Context, _Req)
|
|||||||
%% RoleUser 概要: 导库 描述:json文件导库
|
%% RoleUser 概要: 导库 描述:json文件导库
|
||||||
%% OperationId:get_roleuser
|
%% OperationId:get_roleuser
|
||||||
%% 请求:GET /iotapi/roleuser
|
%% 请求:GET /iotapi/roleuser
|
||||||
do_request(get_roleuser, #{<<"where">> := Where} = Filter, #{<<"sessionToken">> := SessionToken} = _Context, _Req0) ->
|
do_request(get_roleuser, #{<<"where">> := Where} = Filter, #{<<"sessionToken">> := SessionToken} = Context, _Req0) ->
|
||||||
dgiot_parse_auth:get_roleuser(Filter#{<<"where">> => jsx:decode(Where, [return_maps])}, SessionToken);
|
IncludeChild = maps:get(<<"include">>, Context, false),
|
||||||
|
dgiot_parse_auth:get_roleuser(Filter#{<<"where">> => jsx:decode(Where, [return_maps])}, IncludeChild, SessionToken);
|
||||||
|
|
||||||
%% Role模版 概要: 导库 描述:json文件导库
|
%% Role模版 概要: 导库 描述:json文件导库
|
||||||
%% OperationId:put_roleuser
|
%% OperationId:put_roleuser
|
||||||
|
Loading…
Reference in New Issue
Block a user