inpho / inphosite

The InPhO API
https://inphoproject.org
15 stars 5 forks source link

Duplicate entities should throw API error #120

Closed JaimieMurdock closed 11 years ago

JaimieMurdock commented 11 years ago

At present, creating a new entity through the admin interface does a check against the fuzzymatch script. However, this is not reflected in the API. The API should be changed so that if a duplicate entity is attempted, it first returns an HTTP error code and then can be overridden with a query string parameter.

alefrost commented 11 years ago

From our meeting last Friday I just want to recap to make sure I have the details right.

Does that all sound correct?

JaimieMurdock commented 11 years ago

The second point seems a bit fuzzy. The purpose is to check if an entity with that label already exists. If so, then redirect to that entry with a 302.

Also make sure that if it creates an entry, it issues a 303, rather than a 302.

On 09/03/2013 04:27 PM, alefrost wrote:

From our meeting last Friday I just want to recap to make sure I have the details right.

  • All entity controller files will need to be edited to have the same change
  • The function to change is |create()| and should be kept the same except a check to first return a HTTP 302 error before redirecting

Does that all sound correct?

— Reply to this email directly or view it on GitHub https://github.com/inpho/inphosite/issues/120#issuecomment-23744154.

alefrost commented 11 years ago

create() in entity.py:182 has an if statement:

c.entity = Session.query(Entity).filter(Entity.label==label).first()
if c.entity:                                                                     
    redirect(c.entity.url(filetype, action="view"), code=303)

I would assume that it is designed to fire off a redirect if the given label already exists in the database. However, after some testing, I found that the if statement near the end of the function at entity.py:200 is what fires the redirect in the case of, lets say, "Time Travel" was entered.

if redirect:
    sleep(5) # TODO: figure out database slowness so this can be removed
    redirect(c.entity.url(filetype, action="view"), code=303)
else:
    return "200 OK" 

Would it be sufficient to change the error code in the redirect that appears to be firing to be 302 and in the else return 303 and whatever message would accompany that?

alefrost commented 11 years ago

change entity.py:create() to hold all duplicate code from all other entity files. Have unique create() function pass the valid_params to entity.py's create() function.

alefrost commented 11 years ago

I have made those changes, but I'm not sure what else may call entity.py:create(). I'm on the master branch, so I'll wait to hear back about what to do before doing a push.

alefrost commented 11 years ago

fixed in "dev" branch

alefrost commented 11 years ago

merged dev branch