mirror of
https://gitee.com/dgiiot/dgiot.git
synced 2024-12-12 12:16:01 +08:00
fix: post_device
This commit is contained in:
parent
e35f6ef352
commit
95c87909c0
@ -139,7 +139,7 @@ handle_message(check, #state{env = #{<<"offline">> := OffLine, <<"checktime">> :
|
|||||||
|
|
||||||
|
|
||||||
handle_message({sync_parse, Pid, 'after', get, _Token, <<"Device">>, #{<<"results">> := Results} = ResBody}, State) ->
|
handle_message({sync_parse, Pid, 'after', get, _Token, <<"Device">>, #{<<"results">> := Results} = ResBody}, State) ->
|
||||||
%% io:format("~s ~p ~p ~p ~n", [?FILE, ?LINE, Pid,Header]),
|
%% io:format("~s ~p ~p ~p ~n", [?FILE, ?LINE, Pid,Results]),
|
||||||
NewResults = lists:foldl(fun(#{<<"objectId">> := DeviceId} = Device, Acc) ->
|
NewResults = lists:foldl(fun(#{<<"objectId">> := DeviceId} = Device, Acc) ->
|
||||||
case dgiot_device:lookup(DeviceId) of
|
case dgiot_device:lookup(DeviceId) of
|
||||||
{ok, #{<<"status">> := Status, <<"isEnable">> := IsEnable, <<"longitude">> := Longitude, <<"latitude">> := Latitude, <<"time">> := Time}} ->
|
{ok, #{<<"status">> := Status, <<"isEnable">> := IsEnable, <<"longitude">> := Longitude, <<"latitude">> := Latitude, <<"time">> := Time}} ->
|
||||||
|
@ -101,29 +101,30 @@ post(Device) ->
|
|||||||
IsEnable = maps:get(<<"isEnable">>, Device, false),
|
IsEnable = maps:get(<<"isEnable">>, Device, false),
|
||||||
insert_mnesia(DeviceId, dgiot_role:get_acls(Device), Status, dgiot_datetime:now_secs(), IsEnable, ProductId, Devaddr, DeviceSecret, node(), Longitude, Latitude).
|
insert_mnesia(DeviceId, dgiot_role:get_acls(Device), Status, dgiot_datetime:now_secs(), IsEnable, ProductId, Devaddr, DeviceSecret, node(), Longitude, Latitude).
|
||||||
|
|
||||||
|
post(#{<<"ACL">> := _Acl} = Device, _SessionToken) ->
|
||||||
|
dgiot_device_cache:post(Device);
|
||||||
|
|
||||||
post(Device, SessionToken) ->
|
post(Device, SessionToken) ->
|
||||||
Devaddr = maps:get(<<"devaddr">>, Device),
|
Devaddr = maps:get(<<"devaddr">>, Device),
|
||||||
Product = maps:get(<<"product">>, Device),
|
Product = maps:get(<<"product">>, Device),
|
||||||
ProductId = maps:get(<<"objectId">>, Product),
|
ProductId = maps:get(<<"objectId">>, Product),
|
||||||
DeviceId = maps:get(<<"objectId">>, Device, dgiot_parse_id:get_deviceid(ProductId, Devaddr)),
|
DeviceId = maps:get(<<"objectId">>, Device, dgiot_parse_id:get_deviceid(ProductId, Devaddr)),
|
||||||
ACL = maps:get(<<"ACL">>, Product, #{}),
|
SetAcl =
|
||||||
DefaultAcl = #{<<"*">> => #{<<"read">> => true}, <<"role:admin">> => #{<<"read">> => true, <<"write">> => true}},
|
case dgiot_auth:get_session(dgiot_utils:to_binary(SessionToken)) of
|
||||||
SetAcl = case dgiot_auth:get_session(dgiot_utils:to_binary(SessionToken)) of
|
|
||||||
#{<<"roles">> := Roles} = _User ->
|
#{<<"roles">> := Roles} = _User ->
|
||||||
[#{<<"name">> := Role} | _] = maps:values(Roles),
|
[#{<<"name">> := Role} | _] = maps:values(Roles),
|
||||||
GetAcl = ACL#{
|
#{
|
||||||
<<"role:", Role/binary>> => #{
|
<<"role:", Role/binary>> => #{
|
||||||
<<"read">> => true,
|
<<"read">> => true,
|
||||||
<<"write">> => true
|
<<"write">> => true
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
GetAcl;
|
|
||||||
Err ->
|
Err ->
|
||||||
io:format("~s ~p R = ~p.~n", [?FILE, ?LINE, Err]),
|
?LOG(error, "~s ~p DeviceId ~p Err = ~p.~n", [?FILE, ?LINE, DeviceId, Err]),
|
||||||
DefaultAcl
|
#{<<"role:admin">> => #{<<"read">> => true, <<"write">> => true}}
|
||||||
end,
|
end,
|
||||||
dgiot_parse:update_object(<<"Device">>, DeviceId, #{<<"ACL">> => SetAcl}),
|
dgiot_parse:update_object(<<"Device">>, DeviceId, #{<<"ACL">> => SetAcl}),
|
||||||
dgiot_device_cache:post(Device).
|
dgiot_device_cache:post(Device#{<<"ACL">> => SetAcl}).
|
||||||
|
|
||||||
put(Device) ->
|
put(Device) ->
|
||||||
DeviceId = maps:get(<<"objectId">>, Device),
|
DeviceId = maps:get(<<"objectId">>, Device),
|
||||||
|
Loading…
Reference in New Issue
Block a user