1:- module(bc_api_actor, [
    2    bc_set_actor/1,  % +User
    3    bc_actor/1,      % -User
    4    bc_unset_actor/0
    5]).

Access to the current API user */

    9% Threadlocal for the current user.
   10% Automatically set/unset by the admin interface.
   11
   12:- thread_local(actor/1).
 bc_set_actor(+User) is det
Sets thread-local for the current user. Must be called from the REST handlers.
   19bc_set_actor(User):-
   20    retractall(actor(_)),
   21    assertz(actor(User)),
   22    Username = User.username,
   23    debug(bc_api_actor, 'set current actor to ~p', [Username]).
 bc_actor(-User) is det
Retrieves the current API user. Throws error(no_actor_set) when no user is set.
   31bc_actor(User):-
   32    (   actor(User)
   33    ;   throw(error(no_actor_set))), !.
 bc_unset_actor is det
Unsets the author thread-local. Must be called from the REST handlers.
   40bc_unset_actor:-
   41    retractall(actor(_)),
   42    debug(bc_data_cur_actor, 'actor unset', [])