New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass db open options to fabric_view_map #645

Merged
merged 1 commit into from Jul 7, 2017

Conversation

Projects
None yet
2 participants
@eiri
Member

eiri commented Jul 5, 2017

Overview

We don't set db open options to fabric_view_map and missing user_ctx when opening databases. For admin-only database we inject user_ctx for after doc check, pulling it from passed accumulator with assumption it is always #vacc record. This is incorrect in case of list or mango queries and breaks fabric abstraction, where it is spec'ed for acc to be type any()

This patch allows to pass db open options and user_ctx along with it to fabric:query_view/7 and modifies chttpd show and view handlers accordingly.

Testing recommendations

Javascript test suite should pass:

make javascript

For manual check on admin-only database the following should work:

echo '{"name": "demo", "password": "apple", "roles": [], "type": "user"}' | curl -u $CRED http://localhost:15984/_users/org.couchdb.user:demo

...

echo '{"views": {"names": {"map": "function(doc) { emit(doc.name); }"}}, "lists": {"names": "function(head, req) { var row; while (row = getRow()) { send(\"name: \" + row.key + \"\\n\"); } }"}}}' | curl -u $CRED http://localhost:15984/_users/_design/users 

Then

$ curl -u $CRED http://localhost:15984/_users/_design/users/_view/names?include_docs=true
$ curl  -u $CRED "http://localhost:15984/_users/_design/users/_list/names/names"

Checklist

  • Code is written and works correctly;
  • Changes are covered by tests;
  • Documentation reflects the changes;

@eiri eiri referenced this pull request Jul 5, 2017

Merged

Pass UserCtx to fabric's all_docs from mango query #627

1 of 3 tasks complete
@eiri

This comment has been minimized.

Show comment
Hide comment
@eiri

eiri Jul 5, 2017

Member

End-points _list and _show are not working on _users as well. _show because of the missing user context and _list because it is using not #vacc record as an acc for query_view and crashing on request. So this fix needs a bit different approach, changing PR on WIP for now.

Member

eiri commented Jul 5, 2017

End-points _list and _show are not working on _users as well. _show because of the missing user context and _list because it is using not #vacc record as an acc for query_view and crashing on request. So this fix needs a bit different approach, changing PR on WIP for now.

@eiri eiri changed the title from Pass db open options in fabric_view_map to [WIP] Pass db open options in fabric_view_map Jul 5, 2017

@eiri eiri changed the title from [WIP] Pass db open options in fabric_view_map to Pass db open options to fabric_view_map Jul 6, 2017

Pass db open options to fabric_view_map
Pass database open options and user_ctx to query_view
to allow proper access for _view and _list queries.
@tonysun83

This comment has been minimized.

Show comment
Hide comment
@tonysun83

tonysun83 Jul 7, 2017

Contributor

Tested _show and that lead to 500

[error] 2017-07-07T17:59:08.236067Z node1@127.0.0.1 <0.7836.0> 354b71b309 req_err(1517023101) case_clause : {forbidden,<<"Only administrators can view design docs in the users database.">>}
    [<<"chttpd_show:maybe_open_doc/2 L26">>,<<"chttpd_show:handle_doc_show_req/3 L52">>,<<"chttpd:process_request/1 L295">>,<<"chttpd:handle_request_int/1 L231">>,<<"mochiweb_http:headers/6 L122">>,<<"proc_lib:init_p_do_apply/3 L237">>]

This is a different bug though.

Contributor

tonysun83 commented Jul 7, 2017

Tested _show and that lead to 500

[error] 2017-07-07T17:59:08.236067Z node1@127.0.0.1 <0.7836.0> 354b71b309 req_err(1517023101) case_clause : {forbidden,<<"Only administrators can view design docs in the users database.">>}
    [<<"chttpd_show:maybe_open_doc/2 L26">>,<<"chttpd_show:handle_doc_show_req/3 L52">>,<<"chttpd:process_request/1 L295">>,<<"chttpd:handle_request_int/1 L231">>,<<"mochiweb_http:headers/6 L122">>,<<"proc_lib:init_p_do_apply/3 L237">>]

This is a different bug though.

@tonysun83

This comment has been minimized.

Show comment
Hide comment
@tonysun83

tonysun83 Jul 7, 2017

Contributor

+1

Contributor

tonysun83 commented Jul 7, 2017

+1

@eiri eiri merged commit 3e4da60 into apache:master Jul 7, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@eiri eiri deleted the cloudant:pass-user_ctx-in-fabric_view_map branch Jul 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment