Skip to content

Commit

Permalink
Merge branch 'main' into bc/custom-prime-theme
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs authored Oct 15, 2024
2 parents 99e2622 + 2f3dfb2 commit c08991a
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 37 deletions.
52 changes: 39 additions & 13 deletions pydatalab/src/pydatalab/routes/v0_1/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,20 +284,46 @@ def save_collection(collection_id):

@COLLECTIONS.route("/collections/<collection_id>", methods=["DELETE"])
def delete_collection(collection_id: str):
result = flask_mongo.db.collections.delete_one(
{"collection_id": collection_id, **get_default_permissions(user_only=True)}
)

if result.deleted_count != 1:
return (
jsonify(
with flask_mongo.cx.start_session() as session:
with session.start_transaction():
collection_immutable_id = flask_mongo.db.collections.find_one(
{"collection_id": collection_id, **get_default_permissions(user_only=True)},
projection={"_id": 1},
)["_id"]
result = flask_mongo.db.collections.delete_one(
{"collection_id": collection_id, **get_default_permissions(user_only=True)}
)
if result.deleted_count != 1:
return (
jsonify(
{
"status": "error",
"message": f"Authorization required to attempt to delete collection with {collection_id=} from the database.",
}
),
401,
)

# If successful, remove collection from all matching items relationships
flask_mongo.db.items.update_many(
{
"status": "error",
"message": f"Authorization required to attempt to delete collection with {collection_id=} from the database.",
}
),
401,
)
"relationships": {
"$elemMatch": {
"immutable_id": collection_immutable_id,
"type": "collections",
}
}
},
{
"$pull": {
"relationships": {
"immutable_id": collection_immutable_id,
"type": "collections",
}
}
},
)

return (
jsonify(
{
Expand Down
6 changes: 5 additions & 1 deletion pydatalab/tests/server/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def test_cell_from_scratch(client):


@pytest.mark.dependency(depends=["test_create_cell"])
def test_create_collections(client, default_collection):
def test_create_collections(client, default_collection, database):
# Check no collections initially
response = client.get("/collections")
assert len(response.json["data"]) == 0, response.json
Expand Down Expand Up @@ -530,12 +530,16 @@ def test_create_collections(client, default_collection):
assert response.json["item_data"]["collections"][0]["collection_id"] == "test_collection_2"

# Test that collections can be deleted and relationships to items are removed
deleted_id = database.collections.find_one({"collection_id": new_collection.collection_id})[
"_id"
]
response = client.delete(f"/collections/{new_collection.collection_id}")
assert response.status_code == 200, response.json
assert response.json["status"] == "success"
response = client.get(f"/collections/{new_collection.collection_id}")
assert response.status_code == 404, response.json
test_id = ids.pop()
assert database.items.find_one({"relationships.immutable_id": deleted_id}) is None
response = client.get(f"/get-item-data/{test_id}")
assert response.status_code == 200, response.json
assert response.json["status"] == "success"
Expand Down
6 changes: 3 additions & 3 deletions webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@
"mermaid": "^10.1.0",
"primeicons": "^7.0.0",
"primevue": "^4.0.0",
"qrcode-vue3": "^1.6.8",
"serve": "^14.2.1",
"stream-browserify": "^3.0.0",
"tinymce": "^5.10.9",
"vue": "^3.2.4",
"vue-qrcode-reader": "^5.5.7",
"vue-router": "^4.0.0-0",
"vue-select": "^4.0.0-beta.6",
"vue3-easy-data-table": "^1.5.45",
"vuex": "^4.0.0-0",
"qrcode-vue3": "^1.6.8",
"vue-qrcode-reader": "^5.5.7"
"vuex": "^4.0.0-0"
},
"devDependencies": {
"@babel/core": "^7.24.8",
Expand Down
6 changes: 4 additions & 2 deletions webapp/src/components/datablocks/DataBlockBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
/>
<input v-model="BlockTitle" class="form-control-plaintext block-title" type="text" />
<span class="blocktype-label ml-auto mr-3">{{ blockType }}</span>
<span class="block-header-icon"><StyledBlockInfo :block-info="blockInfo" /></span>
<span v-if="blockInfo" class="block-header-icon"
><StyledBlockInfo :block-info="blockInfo"
/></span>
<font-awesome-icon
:icon="['fa', 'sync']"
class="block-header-icon"
Expand Down Expand Up @@ -170,7 +172,7 @@ export default {
return this.$store.state.updatingDelayed[this.block_id];
},
blockInfo() {
return this.$store.state.blocksInfos[this.blockType];
return this.$store.state.blocksInfos?.[this.blockType];
},
BlockTitle: createComputedSetterForBlockField("title"),
BlockDescription: createComputedSetterForBlockField("freeform_comment"),
Expand Down
5 changes: 4 additions & 1 deletion webapp/src/components/datablocks/NotImplementedBlock.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<template>
<DataBlockBase>
<div class="alert alert-danger">This block type has not been implemented!</div>
<div class="alert alert-danger">
This block type is not implemented/installed for this <i>datalab</i> instance. Please contact
your <i>datalab</i> administrator.
</div>
</DataBlockBase>
</template>

Expand Down
17 changes: 3 additions & 14 deletions webapp/src/views/EditPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ export default {
return this.$store.state.files;
},
blocksInfos() {
if (Object.keys(this.$store.state.blocksInfos).length == 0) {
getBlocksInfos();
}
return this.$store.state.blocksInfos;
},
itemApiUrl() {
Expand All @@ -202,7 +205,6 @@ export default {
},
},
created() {
getBlocksInfos();
this.getSampleData();
this.interval = setInterval(() => this.setLastModified(), 30000);
},
Expand Down Expand Up @@ -250,19 +252,6 @@ export default {
behavior: "smooth",
});
},
change_a_block(event, block_id) {
let item_id = this.item_id;
let new_data = {
block_id: 7,
a_new_field: "foo bar",
};
console.log(new_data);
this.$store.commit("updateBlockData", {
item_id,
block_id,
block_data: new_data,
});
},
getBlockDisplayType(block_id) {
var type = this.blocks[block_id].blocktype;
if (type in blockTypes) {
Expand Down
6 changes: 3 additions & 3 deletions webapp/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3945,9 +3945,9 @@ caniuse-api@^3.0.0:
lodash.uniq "^4.5.0"

caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001517, caniuse-lite@^1.0.30001520, caniuse-lite@^1.0.30001640:
version "1.0.30001641"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001641.tgz#3572862cd18befae3f637f2a1101cc033c6782ac"
integrity sha512-Phv5thgl67bHYo1TtMY/MurjkHhV4EDaCosezRXgZ8jzA/Ub+wjxAvbGvjoFENStinwi5kCyOYV3mi5tOGykwA==
version "1.0.30001668"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001668.tgz"
integrity sha512-nWLrdxqCdblixUO+27JtGJJE/txpJlyUy5YN1u53wLZkP0emYCo5zgS6QYft7VUYR42LGgi/S5hdLZTrnyIddw==

case-sensitive-paths-webpack-plugin@^2.3.0:
version "2.4.0"
Expand Down

0 comments on commit c08991a

Please sign in to comment.