You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2020/01/03 17:56:27 UTC
[couchdb] 02/02: feat: allow special document member _access
This is an automated email from the ASF dual-hosted git repository.
jan pushed a commit to branch feat/prepare-access
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 9e584a17b9e980150bd9cdd238f49e4d21e51034
Author: Jan Lehnardt <ja...@apache.org>
AuthorDate: Fri Jan 3 18:53:09 2020 +0100
feat: allow special document member _access
This is in preparation for per-document access control which is
going to use this field. We are adding this in 3.0 because per-
document access control will not be ready for 3.0, but added in
3.1 or later.
This commit allows a future version of CouchDB with per-document
access control to replicate with CouchDB 3.0, to make upgrades and
interoperability easy.
The per-documnet access control code is not going to store the
_access property in the document body like this patch does, but
is going to store it in an extra field inside of #doc and
assert access control for a document without having to load the
entire document body.
---
src/couch/src/couch_doc.erl | 5 +++++
src/couch/test/eunit/couch_db_doc_tests.erl | 5 ++---
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/couch/src/couch_doc.erl b/src/couch/src/couch_doc.erl
index 4a49372..33ad14f 100644
--- a/src/couch/src/couch_doc.erl
+++ b/src/couch/src/couch_doc.erl
@@ -300,6 +300,11 @@ transfer_fields([{<<"_conflicts">>, _} | Rest], Doc, DbName) ->
transfer_fields([{<<"_deleted_conflicts">>, _} | Rest], Doc, DbName) ->
transfer_fields(Rest, Doc, DbName);
+% special field for per doc access control, for future compatibility
+transfer_fields([{<<"_access">>, _} = Field | Rest],
+ #doc{body=Fields} = Doc, DbName) ->
+ transfer_fields(Rest, Doc#doc{body=[Field|Fields]}, DbName);
+
% special fields for replication documents
transfer_fields([{<<"_replication_state">>, _} = Field | Rest],
#doc{body=Fields} = Doc, DbName) ->
diff --git a/src/couch/test/eunit/couch_db_doc_tests.erl b/src/couch/test/eunit/couch_db_doc_tests.erl
index a85630f..916b632 100644
--- a/src/couch/test/eunit/couch_db_doc_tests.erl
+++ b/src/couch/test/eunit/couch_db_doc_tests.erl
@@ -84,9 +84,8 @@ should_allow_access_in_doc_keys_test(_DbName) ->
Expected = {[{<<"_id">>,<<"foo">>}, {<<"_access">>, [<<"test">>]}]},
EJson = Expected,
Doc = couch_doc:from_json_obj(EJson),
- NewEJson = couch_doc:to_json_obj(Doc),
- NewEJson = Expected,
- ok.
+ NewEJson = couch_doc:to_json_obj(Doc, []),
+ ?_assertEqual(NewEJson, Expected).
open_db(DbName) ->
{ok, Db} = couch_db:open_int(DbName, [?ADMIN_CTX]),