diff options
author | Jan Lehnardt <jan@apache.org> | 2020-01-03 18:53:09 +0100 |
---|---|---|
committer | Joan Touzet <wohali@users.noreply.github.com> | 2020-01-04 07:51:35 +0000 |
commit | 04aef08e82a8331c3a2b3b56b2988fb283669226 (patch) | |
tree | 7ba8e5690cdb7fe04ed6e2a7eb8f825bea6a684a | |
parent | ab5938d4d5b8b48dbf2acafcb1e646fa6cf7247f (diff) | |
download | couchdb-04aef08e82a8331c3a2b3b56b2988fb283669226.tar.gz |
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.
-rw-r--r-- | src/couch/src/couch_doc.erl | 5 | ||||
-rw-r--r-- | 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 4a49372c7..33ad14f0b 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 a85630f7e..916b63207 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]), |