| summaryrefslogtreecommitdiff | 
diff options
| -rw-r--r-- | src/ataxia_client.erl | 9 | ||||
| -rw-r--r-- | src/ataxia_server.erl | 44 | 
2 files changed, 36 insertions, 17 deletions
| diff --git a/src/ataxia_client.erl b/src/ataxia_client.erl index 4703b9f..dec16e6 100644 --- a/src/ataxia_client.erl +++ b/src/ataxia_client.erl @@ -12,7 +12,7 @@     [        add/4,        add_at/5, -      reserve/3, +      reserve/2,        fetch/3,        update/4, @@ -102,19 +102,18 @@ add (DB, ReadPerm, WritePerm, Value) ->  -spec reserve     (        atom(), -      ataxia_security:user(),        ataxia_id:type()     )     -> ('ok' | 'unavailable'). -reserve (DB, User, ID) -> +reserve (DB, ID) ->     DBNode = get_db_node_for(ID), -   Reply = rpc:call(DBNode, ataxia_server, reserve, [DB, User, ID]), +   Reply = rpc:call(DBNode, ataxia_server, reserve, [DB, ID]),     io:format     (        "~nataxia_client:reserve(~p) ! ~p -> ~p.~n", -      [{DB, User, ID}, DBNode, Reply] +      [{DB, ID}, DBNode, Reply]     ),     Reply. diff --git a/src/ataxia_server.erl b/src/ataxia_server.erl index dccd0db..8a49616 100644 --- a/src/ataxia_server.erl +++ b/src/ataxia_server.erl @@ -35,16 +35,27 @@  %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%-spec query_transaction (shr_db_query:type()) -> 'ok'. -%query_transaction (Query) -> -%   DB = shr_db_query:get_database(Query), -%   ID = shr_db_query:get_entry_id(Query), -%   [Item] = mnesia:read(DB, ID), -%   {ok, UpdatedItem} = shr_db_query:apply_to(Query, Item), -% -%   mnesia:write(DB, UpdatedItem, sticky_write), -% -%   ok. +-spec update_internals +   ( +      atom(), +      ataxia_security:user(), +      ataxic:meta(), +      ataxia_id:type() +   ) +   -> 'ok'. +update_internals (DB, User, OP, ID) -> +   [Entry] = mnesia:read(DB, ID), + +   true = +      ataxia_security:can_access +      ( +         ataxia_entry:get_write_permission(Entry), +         User +      ), + +   mnesia:write(DB, ataxic:apply_to(OP, Entry), sticky_write), + +   ok.  -spec add_new_item (atom(), ataxia_entry:type()) -> 'ok'.  add_new_item (DB, Item) -> @@ -154,8 +165,17 @@ fetch_all (_DB, _User, _Cond) ->        ataxia_id:type()     )     -> ({'aborted', any()} | 'ok'). -update (_DB, _User, _Update, _ID) -> -   {aborted, unimplemented}. +update (DB, User, Update, ID) -> +   case +      mnesia:transaction +      ( +         fun update_internals/4, +         [DB, User, Update, ID] +      ) +   of +      {atomic, ok} -> ok; +      Other -> {aborted, Other} +   end.  -spec update_any     ( | 


