diff --git a/pydatalab/pydatalab/models/people.py b/pydatalab/pydatalab/models/people.py index 0eb8281c1..38b97ac56 100644 --- a/pydatalab/pydatalab/models/people.py +++ b/pydatalab/pydatalab/models/people.py @@ -67,7 +67,7 @@ class Person(Entry): type: str = Field("people", const=True) """The entry type as a string.""" - identities: List[Identity] + identities: List[Identity] = Field(default_factory=list) """A list of identities attached to this person, e.g., email addresses, OAuth accounts.""" display_name: Optional[str] @@ -87,11 +87,6 @@ def add_missing_type(cls, v): def set_default_type(cls, _): return "people" - class Config: - allow_population_by_field_name = True - extra = "forbid" - json_encoders = {bson.ObjectId: str} - @staticmethod def new_user_from_identity( identity: Identity, use_display_name: bool = True, use_contact_email: bool = True diff --git a/pydatalab/pydatalab/routes/items.py b/pydatalab/pydatalab/routes/items.py index b9ae00a87..f2b9e2097 100644 --- a/pydatalab/pydatalab/routes/items.py +++ b/pydatalab/pydatalab/routes/items.py @@ -264,8 +264,12 @@ def _create_sample(sample_dict: dict, copy_from_item_id: str = None) -> tuple[di if CONFIG.TESTING: new_sample["creator_ids"] = [] + new_sample["creators"] = [ + {"display_name": "Public testing user", "contact_email": "datalab@odbx.science"} + ] else: new_sample["creator_ids"] = [current_user.person.immutable_id] + new_sample["creators"] = [{"display_name": current_user.person.display_name}] # check to make sure that item_id isn't taken already if flask_mongo.db.items.find_one({"item_id": sample_dict["item_id"]}): @@ -311,6 +315,9 @@ def _create_sample(sample_dict: dict, copy_from_item_id: str = None) -> tuple[di "date": new_sample.date, "name": new_sample.name, "creator_ids": new_sample.creator_ids, + "creators": [c.json() for c in new_sample.creators] + if new_sample.creators + else None, }, }, 201, # 201: Created diff --git a/webapp/src/server_fetch_utils.js b/webapp/src/server_fetch_utils.js index b643fb932..63de8f07a 100644 --- a/webapp/src/server_fetch_utils.js +++ b/webapp/src/server_fetch_utils.js @@ -95,7 +95,7 @@ export function createNewSample(item_id, date, name, startingData = {}, copyFrom console.log("received the following data from fetch new-sample:"); console.log(response_json.sample_list_entry); console.log(`item_id: ${item_id}`); - store.commit("appendToSampleList", response_json.sample_list_entry); + store.commit("prependToSampleList", response_json.sample_list_entry); // store.commit('createSampleData', { // "item_id": item_id, // "sample_data": response_json.sample_data diff --git a/webapp/src/store/index.js b/webapp/src/store/index.js index 2c9d5cbb8..02d772e19 100644 --- a/webapp/src/store/index.js +++ b/webapp/src/store/index.js @@ -33,6 +33,10 @@ export default createStore({ // sampleSummary is a json object summarizing the new sample state.sample_list.push(sampleSummary); }, + prependToSampleList(state, sampleSummary) { + // sampleSummary is a json object summarizing the new sample + state.sample_list.unshift(sampleSummary); + }, deleteFromSampleList(state, sample_summary) { const index = state.sample_list.indexOf(sample_summary); if (index > -1) {