From d12d6328f1001552ad8ce0f44bc1271eeb94ddbb Mon Sep 17 00:00:00 2001 From: nsensfel Date: Mon, 18 Feb 2019 18:37:29 +0100 Subject: ... --- src/shared/struct/map/shr_map_marker.erl | 55 +++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 19 deletions(-) (limited to 'src/shared/struct/map/shr_map_marker.erl') diff --git a/src/shared/struct/map/shr_map_marker.erl b/src/shared/struct/map/shr_map_marker.erl index 35ba195..3899c23 100644 --- a/src/shared/struct/map/shr_map_marker.erl +++ b/src/shared/struct/map/shr_map_marker.erl @@ -4,10 +4,9 @@ %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -type name() :: binary(). --type type() :: 'none'. --type collection() :: orddict:orddict(name(), type()). +-type type() :: {ataxia_security:permission(), list(shr_location:type())}. --export_type([name/0, type/0, collection/0]). +-export_type([name/0, type/0]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -15,16 +14,16 @@ -export ( [ - get/2, - empty_collection/0 + can_access/2, + get_locations/1 ] ). -export ( [ - decode_collection/1, - encode_collection/1 + decode/1, + encode/1 ] ). @@ -35,18 +34,36 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec get (name(), collection()) -> ('not_found' | {'ok', type()}). -get (Name, Collection) -> - case orddict:find(Name, Collection) of - error -> not_found; - Other -> Other - end. +-spec can_access (ataxia_security:user(), type()) -> boolean(). +can_access (User, {Permission, _Locations}) -> + ataxia_security:can_access(User, Permission). --spec empty_collection () -> collection(). -empty_collection () -> orddict:new(). +-spec get_locations (type()) -> boolean(). +get_locations ({_Permission, Locations}) -> + Locations. --spec encode_collection (collection()) -> list(any()). -encode_collection (_Collection) -> []. +-spec encode (type()) -> {list(any())}. +encode ({Permission, Locations}) -> + { + [ + { + <<"p">>, + ataxia_security:permission_to_json(fun (E) -> E end, Permission) + }, + { <<"l">>, lists:map(fun shr_location:encode/1, Locations) } + ] + }. --spec decode_collection (map()) -> collection(). -decode_collection (_Map) -> orddict:new(). +-spec decode (map()) -> type(). +decode (Map) -> + EncodedPermission = maps:get("p", Map), + EncodedLocations = maps:get("l", Map), + + Permission = + ataxia_security:permission_from_json(fun (E) -> E end, EncodedPermission), + Locations = lists:map(fun shr_location:decode/1, EncodedLocations), + + { + Permission, + Locations + }. -- cgit v1.2.3-70-g09d2