1. 07 Mar, 2019 2 commits
  2. 13 Dec, 2018 4 commits
  3. 31 Oct, 2018 1 commit
  4. 06 Jul, 2018 1 commit
    • Denis Laxalde's avatar
      Detect bad mime types upon data submission views · d2b673a15823
      Denis Laxalde authored
      Previously, we did "request.json_body" in every data submission views
      (like entity creation or update, with HTTP method being POST or PUT).
      This instruction might fail with JSONDecodeError exception if the body
      fails to JSON decode. This would result in a 500 error response. Rather
      we want to return a 40x response indicating that this is a client error.
      
      So we now raise a 415 Unsupported Media Type error through a
      _json_body() helper function every times we need to decode JSON body of
      incoming requests. Notice that since json module only has
      JSONDecodeError exception on Python3+, we catch ValueError on Python2.
      
      A functional test is added for entity creation view.
      d2b673a15823
  5. 26 Jun, 2018 3 commits
  6. 19 Jun, 2018 1 commit
    • Denis Laxalde's avatar
      Use resource interfaces for context of API views · fe8187f8d252
      Denis Laxalde authored
      We define interfaces (using zope.interface) for main resource classes
      and refer to these interfaces (as dotted names) in API views' context
      instead of registering these views against the resource classes
      directly.
      
      The idea is to make it possible for downstream applications to register
      their own resource classes that could be selected by standard API views.
      
      Interfaces have attributes and methods declared based on what appears to
      be needed on API views. We use interface inheritance to reduce
      duplication (e.g. the IMapped interface is a base for all interface but
      IRoot; IRelatedEntities is a base for IRelatedEntity).
      
      Notice that this somehow conflicts with the Mappable abstract class that
      was defined previously in resources module; so we drop this abstract
      class and replace it by an IMapped interface.
      fe8187f8d252
  7. 20 Jun, 2018 1 commit
    • Denis Laxalde's avatar
      Move permission check logic from get_entities() view to the resource · 52dcc1f1a143
      Denis Laxalde authored
      Instead of assuming that the context resource in get_entities() view has
      an "etype" attribute (which won't be true anymore in next changeset), we
      delegate permission check to the resource object in the form of an
      has_perm() method. This is step towards defining abstract interfaces for
      resource classes.
      52dcc1f1a143
  8. 19 Jun, 2018 2 commits
    • Denis Laxalde's avatar
      Implement attributes of Paginable resource as properties · 62934d2097ac
      Denis Laxalde authored
      I'm getting into trouble while trying to reuse this class in a multiple
      inheritance context because the proper __init__ method is never called.
      So, let's get rid of __init__ in Paginable and implement 'limit',
      'offset' and '_has_next' attributes, previously defined in __init__ as
      reified properties. Notice that, since _has_next may be changed (in
      paginate() method), we also need a setter for this property.
      
      Accordingly, drop super() calls in resource classes inheriting from
      Paginable and mention that this class should be used as a mixin.
      62934d2097ac
    • Denis Laxalde's avatar
      Add a CollectionMapper for unspecified entity types · 62523c338920
      Denis Laxalde authored
      This is useful for representing collection of heterogeneous entities.
      
      This mapper would be selected by its regid only, with no extra argument
      in contrast with other 'jsonschema.collection' mappers that either
      accepts an "etype" parameter or a relation context. This mapper does not
      handle submission (i.e. entity creation) since the target entity type is
      unspecified; so we return a "false" JSON Schema for "creation" role.
      
      In tests, we rename prior test case CollectionMapperTC as
      EntityCollectionMapperTC and add back a CollectionMapperTC explicitly
      testing the new mapper class.
      62523c338920
  9. 02 May, 2018 1 commit
  10. 17 Apr, 2018 1 commit
  11. 11 Apr, 2018 1 commit
  12. 09 Apr, 2018 2 commits
  13. 05 Apr, 2018 1 commit
  14. 30 Mar, 2018 4 commits
  15. 27 Mar, 2018 1 commit
    • Denis Laxalde's avatar
      Add a dedicated error view for cubicweb's RequestError · 1db2dd27c01e
      Denis Laxalde authored
      This view will be selected upon any exception which is a subclass of
      cubicweb.web.RequestError when the request has Accept:application/json.
      Previously, the "generic_error" view would have been called, but it
      cannot accurately handle CubicWeb's web exceptions (it always returns
      500, whereas these web exceptions may have a different status code).
      
      Why are these views selected? This is because the RootResource matches
      for any request with this Accept:application/json header. (In fact, we'd
      want to use this error view only when the request comes from a
      sub-resource of the RootResource; but that's not easy to achieve.)
      
      So this new error view convert a cubicweb.web.RequestError into an
      application/problem+json response. This is thus not backward compatible
      with what CubicWeb would return.
      
      In added test, we use the "format_date" "ajax" controller (of CubicWeb)
      with missing argument which then responds with a RemoteCallFailed (with
      a 500 status) that is called by our view.
      1db2dd27c01e
  16. 20 Mar, 2018 1 commit
    • Denis Laxalde's avatar
      Let yams_match respect Predicate.__call__ interface · ee7941762504
      Denis Laxalde authored
      CubicWeb's Predicate's __call__ method's interface is:
      
        def __call__(self, cls, req, **kwargs):
      
      In yams_match, we had 'rtype' and 'role' as non-keyword arguments, thus
      producing TypeError upon calls of a class's __select__ without all
      required arguments. We change this to have 'rtype' and 'role' option
      (though score will still be 0 if they are unspecified) so that we now
      respect base interface.
      ee7941762504
  17. 19 Mar, 2018 9 commits
  18. 16 Mar, 2018 4 commits
    • Denis Laxalde's avatar
      Export InlinedRelationItemMapper · b5a22b9b39cf
      Denis Laxalde authored
      It's probably not meant to be part of the public API but I need it
      downstream at the moment.
      b5a22b9b39cf
    • Denis Laxalde's avatar
      e7d22a6c2a56
    • Denis Laxalde's avatar
      Use the appropriate item mapper in RelationMapper.serialize() · cd3ba66cecb3
      Denis Laxalde authored
      Instead of duplicating the logic of serialization of items in this
      method, we now rely on a dedicate "jsonschema.item" mapper (properly
      selected with relation information) to serialize each item of the
      relation.
      cd3ba66cecb3
    • Denis Laxalde's avatar
      Let "relation" mappers serialize related entities directly · 3a0223d5a4d1
      Denis Laxalde authored
      Previously, the set of related entities was computed within
      "jsonschema.relation" mappers and their serialize() method accepted only
      the main "entity" from which this "related" set was computed. This is
      asymmetric with "jsonschema.collection" which serialize() method handles
      a list of entities. So we make the former mappers accept the set of
      related directly as an argument to their serialize() method. This set is
      computed by "jsonschema.entity" mapper.
      
      This is a step forward merging "jsonschema.relation" mappers (for
      non-final relation) with "jsonschema.collection" mappers.
      3a0223d5a4d1