Hi!

couch_db:set_security is:

set_security(#db{update_pid=Pid}=Db, {NewSecProps}) when is_list(NewSecProps) ->
    check_is_admin(Db),
    ok = validate_security_object(NewSecProps),
    ok = gen_server:call(Pid, {set_security, NewSecProps}, infinity),
    {ok, _} = ensure_full_commit(Db),
    ok;
set_security(_, _) ->
    throw(bad_request).

So you just mismatch the first clause and falls into second one. You
have no reason to do couch_doc:from_json_obj(Json), your Json is valid
here, except a typo in members roles definition.


--
,,,^..^,,,


On Tue, Sep 22, 2015 at 5:29 AM, Jamie Diprose <[email protected]> wrote:
> Hi (sorry if this got sent twice)
>
> I'm trying to set the database security document ("_security"), from the
> Erlang API. I've tried by saving a document with the id "_security" and by
> using the *couch_db:set_security* method - both fail and I have no idea why.
>
> 1) Saving a document with the id "_security" gives the following error:
>
> {"error":"bad_request","reason":"Only reserved document ids may start with
>> underscore."}
>
>
> 2) So I tried using the set_security method:
>
> add_security_doc(Username) ->
>> ?LOG_INFO("add_security_doc: ~p", [Username]),
>> UsernameBinary = unicode:characters_to_binary(Username),
>>
>> DbOptions = [{user_ctx, #user_ctx{roles = [<<"_admin">>]}}],
>>     {ok, UserDb} = couch_db:open_int(UsernameBinary, DbOptions),
>>
>> try
>> Json = {[
>>  {<<"members">>, {[{<<"names">>, []}, {<<"roles">>, UsernameBinary]}]}},
>>  {<<"admins">>, {[{<<"names">>, [UsernameBinary]}, {<<"roles">>, []}]}}
>> ]},
>>
>> couch_db:set_security(UserDb, couch_doc:from_json_obj(Json))
>> after
>> couch_db:close(UserDb)
>> end.
>
>
> But this gives the error:
>
> {"error":"bad_request","reason":""}
>
>
> Anyone have any idea what I'm doing wrong?
>
> Thanks for your help
>
> Jamie

Reply via email to