Standardize how Creators and Contributors are linked to existing HydroShare users
horsburgh opened this issue · comments
The Contributor object does not have the link to the user's profile that is in the Creator object. So, I can create a Contributor, but I can't link a contributor to an existing HydroShare user.
I think we should standardize creating/adding Authors and Creators that are existing HydroShare users by passing an ID or name or something and then having the creator/contributor information copied from the profile.
I've been thinking about the best way to approach this. We'll need to add an endpoint to hydroshare that returns a User representation in json. Then we can build a model here for that User object. Once we have those two pieces, I think I'll just add a class method to the Contributor/Creator models that takes a User model and returns a new instance of the Contributor/Creator. Usage will look something like this.
hs = HydroShare()
user = hs.user(5) # just accepts the user id for now.
user_creator = Creator.from_user(user)
res = hs.create()
res.metadata.creators = [user_creator]
res.save()
I think specifying the user's ID is a good start. We might consider allowing input of the username or email.
username/email would work just as well without complicating the implementation. I'll add both of those to the endpoint too.
i'm retracting my previous comment in the interest in time. Leaving it to only retrieving by id for now.
2168869
This is generally working. Creating an Author/Creator from an existing HydroShare user adds the creator and is linked to the user's profile page. Creating a contributor copies all of the metadata over, but the Contributor's name is not linked to their profile. When you do the same operation in the web user interface, the name of the contributor is linked to the user's profile.
I think to finish this off, the Contributor's name should be linked to that user's HydroShare profile when the contributor is a HydroShare user - consistent with the behavior of the web user interface.
The latest commit addresses this, along with tests. It was an oversight, I didn't look at contributor close enough.