anchor.diff:          {error, _} -> throw({error, not_found});
           {ok, User} -> apply(db:get(?MODULE, Domain), delete, [Domain, User#uce_user.id])
       end;
  -delete(Domain, Id) ->
  +delete(Domain, {Uid, _} = Id) ->
       case exists(Domain, Id) of
           true ->
  -            apply(db:get(?MODULE, Domain), delete, [Domain, Id]);
  +            % delete the default role
  +            case catch uce_role:delete(Domain, {Uid, Domain}) of
  +                {error, Reason} when Reason /= not_found ->
  +                    throw({error, Reason});
  +                _ ->
  +                    apply(db:get(?MODULE, Domain), delete, [Domain, Id])
  +            end;
           false ->
               throw({error, not_found})
       end.
  
positive.code:         true ->
              throw({error,conflict});
          false ->
              apply(db:get(?MODULE, Domain), add, [Domain, User]),
              uce_role:add(Domain, #uce_role{id={UId, Domain}}),
              uce_user:addRole(Domain, {UId, Domain}, {"default", []}),
              uce_user:addRole(Domain, {UId, Domain}, {UId, []}),
              {ok, UId}
      end.
  
  
negative.code:         true ->
              apply(db:get(?MODULE, Domain), update, [Domain, User]);
          false ->
              throw({error, not_found}) 
     end.
  
  list(Domain) ->
      apply(db:get(?MODULE, Domain), list, [Domain]).
  