kazu2012 / persevere-framework

Automatically exported from code.google.com/p/persevere-framework
0 stars 0 forks source link

Properties with readonly attribute set can not be updated via PUT. #222

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. Start with clean persevere install.

2. Define the Test class, in WEB-INF/jslib/test.js as follows:

        Class({
          id : "Test",
          properties : {
            title : { type : "string" },
            created : { type : "integer", optional : true }
          },
          prototype : {
            initialize : function() {
              this.created = (new Date()).getTime();
            }
          }
        });

3. Start up persevere and make a POST request to create a new Test object:

        POST /Test '{title: "test1"}'

4. Observe that the object was created properly. Then update the newly created 
object using the
PUT request as follows:

        PUT /Test/1 'title: "test2"}'

What is the expected output? 

        HTTP/1.1 200 OK
        '{id: 1, title: "test2", created: 123456}'

What do you see instead?

        HTTP/1.1 403 Forbidden
        "TypeError: property is a readonly property for property created"

What version of the product are you using? On what operating system?

Using svn r571 on OSX (Leopard).

Original issue reported on code.google.com by Micha.Ni...@gmail.com on 27 Jul 2009 at 9:11

GoogleCodeExporter commented 8 years ago
Sorry, the file WEB-INF/jslib/test.js was wrong in the original report. It 
should be like this:

Class({
  id : "Test",
  properties : {
    title : { type : "string" },
    created : { type : "integer", readonly : true, optional : true }
  },
  prototype : {
    initialize : function() {
      this.created = (new Date()).getTime();
    }
  }
});

Original comment by Micha.Ni...@gmail.com on 27 Jul 2009 at 9:14

GoogleCodeExporter commented 8 years ago
Sorry, you can't use PUT for differential updates, the semantics of a PUT (per 
RFC 
2616) indicate that the entity must be a full representation of the object. 
Consequently, omitting a property that existed before indicates that the client 
is 
requesting that the property be removed. In order to do a PUT with your object, 
you 
need to actually look at the full object (returned by the POST or a GET), and 
include 
the created property, unchanged.

I have considered allow for differential updates like this with a POST (like 
POST 
/Test/1 '{title: "test2"}'). Would you like that?

Original comment by kris...@gmail.com on 27 Jul 2009 at 9:23

GoogleCodeExporter commented 8 years ago
Sorry, I did not realize that. But it also fails when you do a PUT with the 
complete
object:

        GET /Test/1

        HTTP/1.1 200 OK
        '{id: "1", title: "test1", created: 1248728516129}'

Then:

        PUT /Test/1 '{id: "1", title: "test1", created: 1248728516129}'

        HTTP/1.1 403 Forbidden
        "TypeError: property is a readonly property for property created"

With respect to the POST update, sure that sounds like a useful thing to have.

Original comment by Micha.Ni...@gmail.com on 27 Jul 2009 at 9:34

GoogleCodeExporter commented 8 years ago
Add support for POST-based incremental updates to objects, and fixed problem 
with 
setting a property value with same number.

Original comment by kris...@gmail.com on 28 Jul 2009 at 2:03