Skip to content
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

Feature/writable api #20

Merged
merged 13 commits into from
Dec 1, 2020
Merged

Feature/writable api #20

merged 13 commits into from
Dec 1, 2020

Conversation

annashamray
Copy link
Collaborator

@annashamray annashamray changed the title Feature/writable api [WIP] Feature/writable api Nov 17, 2020
@codecov-io
Copy link

codecov-io commented Nov 19, 2020

Codecov Report

Merging #20 (df9184d) into master (3cedd3c) will increase coverage by 2.28%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #20      +/-   ##
==========================================
+ Coverage   89.87%   92.16%   +2.28%     
==========================================
  Files          44       54      +10     
  Lines         889     1148     +259     
==========================================
+ Hits          799     1058     +259     
  Misses         90       90              
Impacted Files Coverage Δ
src/objecttypes/core/tests/factories.py 100.00% <ø> (ø)
src/objecttypes/api/filters.py 100.00% <100.00%> (ø)
src/objecttypes/api/serializers.py 100.00% <100.00%> (ø)
src/objecttypes/api/urls.py 100.00% <100.00%> (ø)
src/objecttypes/api/validators.py 100.00% <100.00%> (ø)
src/objecttypes/api/views.py 100.00% <100.00%> (ø)
src/objecttypes/core/constants.py 100.00% <100.00%> (ø)
...cttypes/core/migrations/0009_auto_20201111_1649.py 100.00% <100.00%> (ø)
...cttypes/core/migrations/0010_auto_20201111_1707.py 100.00% <100.00%> (ø)
...cttypes/core/migrations/0011_auto_20201111_1737.py 100.00% <100.00%> (ø)
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 77dddb9...df9184d. Read the comment docs.

@annashamray annashamray changed the title [WIP] Feature/writable api Feature/writable api Nov 19, 2020


class ObjectVersionAPITests(TokenAuthMixin, APITestCase):
def test_get_versions(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test where there are 2 Objecttypes, with each 1 version. Then, check that if you retrieve /objecttypes/<uuid>/versions and the inline version URLs in /objecttypes/<uuid> only contain 1 version (and not also the version object from the other objecttype).

I had this issue quite often when working with nested viewsets.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_get_objecttypes_with_versions is added


@swagger_auto_schema(request_body=no_body)
@action(detail=True, methods=["post"])
def publish(self, request, *args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that this is an action BUT we have 3 statusses: draft, published and deprecated. There is no status field that can be modified on a version object. So, how do we mark a version as deprecated?

I think we should just add the status field to a writable field so you can set published like that, and also set deprecated. We should only block changing these 2 back to draft.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I quite like publish endpoint, it makes API consistent with admin page, and also with our Catalogi API.

Do we really need deprecated status? We don't use it anywhere now. Maybe we can just get rid of it.
Or we can add DELETE action to the Version resource and switch status to depricated in this case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I quite like publish endpoint, it makes API consistent with admin page

That's not really a good reason. The admin can just as well set the status field (in fact, it does that ofcourse, but via a publish function).

and also with our Catalogi API.

Hmm, that's a valid argument: Consistency.
Since we disagree, I'll ask a third party :)

Do we really need deprecated status? We don't use it anywhere now.

It was added because of DCAT/Metadata catalogus

Or we can add DELETE action to the Version resource and switch status to depricated in this case?

No, this is unexpected behaviour. Plus, if we ever introduce a new status it will be weird.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of a DELETE call:

  • on draft resources -> actual DB delete
  • on published resources -> mark deprecated. Mistakes can then be correct be publishing it again, if need be?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that "draft" is set automatically, "publish" is set by an action and "deprecated" is set with a HTTP method.

  1. I'll make the decision to set the status with PUT/PATCH only. Setting non-draft to draft is not allowed.
  2. DELETE should be allowed on versions that are in draft.
  3. DELETE should also be allowed on objecttypes that have no versions

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll change the implementation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the implementation is changed:

  • DELETE is supported now
  • "publish" action is removed



class ObjectTypeSerializer(serializers.HyperlinkedModelSerializer):
versions = ObjectVersionSerializer(many=True)
versions = NestedHyperlinkedRelatedField(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just realized that this change breaks compatibility with Objects API validator. But I like that it's consistent with Zaken API now.
@joeribekker Should we display all versions data here? Or I can make a small change in Objects API

Copy link
Member

@joeribekker joeribekker Nov 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this as well. I don't see the need to expand this property by default.

If you manually saw that this breaks Objects API validation, then please change yes, BUT it also means its a blind spot in our CI-setup. You can make an issue for that :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, we don't have integration tests and we don't even have docker-compose with two APIs now. Perhaps we can set up a separate repo with integration tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it, but lets make an issue for now so it won't be missed again.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@annashamray annashamray mentioned this pull request Nov 27, 2020
@joeribekker joeribekker merged commit f81f314 into master Dec 1, 2020
@joeribekker joeribekker deleted the feature/writable-api branch December 1, 2020 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

As developer I want write access to the Objecttypes API and publish new versions
4 participants