Skip to content
Snippets Groups Projects
Verified Commit 6cf1905b authored by Timm Fitschen's avatar Timm Fitschen
Browse files

Merge branch 'dev' into f-versioning

parents 875e1c24 31f1be01
Branches
Tags
No related merge requests found
...@@ -21,5 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -21,5 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* POV with the 'name' property, e.g. `FIND ENTITY WITH name = something` * POV with the 'name' property, e.g. `FIND ENTITY WITH name = something`
[caosdb-server#51](https://gitlab.com/caosdb/caosdb-server/-/issues/51) [caosdb-server#51](https://gitlab.com/caosdb/caosdb-server/-/issues/51)
- Fixed several bugs when an Entity inherits from itself (#18, caosdb-server #85). - Fixed several bugs when an Entity inherits from itself (#18, caosdb-server #85).
- Bug in `updateEntity.sql` (when updating the primary name without a prior call
to `deleteEntityProperties`). Same thing for `deleteEntity`.
### Security ### ### Security ###
...@@ -41,21 +41,29 @@ delimiter // ...@@ -41,21 +41,29 @@ delimiter //
CREATE PROCEDURE db_2_0.deleteEntity(in EntityID INT UNSIGNED) CREATE PROCEDURE db_2_0.deleteEntity(in EntityID INT UNSIGNED)
BEGIN BEGIN
-- detele file properties
DELETE FROM files where file_id=EntityID; DELETE FROM files where file_id=EntityID;
-- delete datatype stuff
DELETE FROM data_type DELETE FROM data_type
WHERE ( domain_id = 0 WHERE ( domain_id = 0
AND entity_id = 0 AND entity_id = 0
AND property_id = EntityID ) AND property_id = EntityID )
OR datatype = EntityID; OR datatype = EntityID;
DELETE FROM collection_type DELETE FROM collection_type
WHERE domain_id = 0 WHERE domain_id = 0
AND entity_id = 0 AND entity_id = 0
AND property_id = EntityID; AND property_id = EntityID;
DELETE FROM entities WHERE id=EntityID; -- delete primary name (in case this is called without a prior call to deleteEntityProperties)
DELETE FROM name_data
WHERE domain_id = 0
AND entity_id = EntityID
AND property_id = 20;
DELETE FROM entities where id=EntityID;
-- clean up unused acl
DELETE FROM entity_acl DELETE FROM entity_acl
WHERE NOT EXISTS ( WHERE NOT EXISTS (
SELECT 1 FROM entities SELECT 1 FROM entities
......
...@@ -99,8 +99,14 @@ BEGIN ...@@ -99,8 +99,14 @@ BEGIN
e.acl = ACLID e.acl = ACLID
WHERE e.id = EntityID; WHERE e.id = EntityID;
-- clean up primary name, because updateEntity might be called without a
-- prior call to deleteEntityProperties.
DELETE FROM name_data
WHERE domain_id = 0 AND entity_id = EntityID AND property_id = 20;
IF EntityName IS NOT NULL THEN IF EntityName IS NOT NULL THEN
INSERT INTO name_data (domain_id, entity_id, property_id, value, status, pidx) VALUES (0, EntityID, 20, EntityName, "FIX", 0); INSERT INTO name_data
(domain_id, entity_id, property_id, value, status, pidx)
VALUES (0, EntityID, 20, EntityName, "FIX", 0);
END IF; END IF;
DELETE FROM data_type DELETE FROM data_type
......
...@@ -9,30 +9,29 @@ DELETE FROM feature_config WHERE _key = "ENTITY_VERSIONING"; ...@@ -9,30 +9,29 @@ DELETE FROM feature_config WHERE _key = "ENTITY_VERSIONING";
CALL entityACL(@ACLID1, "{acl1}"); CALL entityACL(@ACLID1, "{acl1}");
CALL entityACL(@ACLID2, "{acl2}"); CALL entityACL(@ACLID2, "{acl2}");
SELECT id into @TextDatatypeID FROM entities WHERE name ="TEXT" and role="DATATYPE"; SELECT entity_id into @TextDatatypeID FROM name_data WHERE value ="TEXT";
-- TESTS -- TESTS
-- TEST insertEntity -- TEST insertEntity
SELECT COUNT(id) INTO @x FROM entities WHERE id>100; SELECT tap.eq(COUNT(id), 0, "No entities")
SELECT tap.eq(@x, 0, "No entities"); FROM entities WHERE id>=100;
CALL insertEntity("EntityName", "EntityDesc", "RECORDTYPE", "{acl1}"); CALL insertEntity("EntityName", "EntityDesc", "RECORDTYPE", "{acl1}");
SELECT tap.eq(COUNT(entity_id), 1, "Entity has been inserted")
FROM name_data WHERE value="EntityName";
SELECT COUNT(id) INTO @x FROM entities WHERE name="EntityName"; SELECT entity_id INTO @EntityID FROM name_data WHERE value="EntityName";
SELECT tap.eq(@x, 1, "Entity has been inserted"); SELECT tap.ok(@EntityID >= 100, "EntityID greater 99");
SELECT acl INTO @x FROM entities WHERE name="EntityName";
SELECT tap.eq(@x, @ACLID1, "correct acl id had been assigned");
SELECT id INTO @EntityID FROM entities WHERE name="EntityName"; SELECT tap.eq(acl, @ACLID1, "correct acl id had been assigned")
SELECT tap.ok(@EntityID > 100, "EntityID greater 100"); FROM entities WHERE id=@EntityID;
-- TEST insertEntityProperty -- TEST insertEntityProperty
CALL insertEntity("AProperty", "APropDesc", "PROPERTY", "{acl1}"); CALL insertEntity("AProperty", "APropDesc", "PROPERTY", "{acl1}");
SELECT id INTO @PropID FROM entities WHERE name="AProperty"; SELECT entity_id INTO @PropID FROM name_data WHERE value="AProperty";
INSERT INTO data_type (domain_id, entity_id, property_id, datatype) VALUES (0, 0, @PropID, @TextDatatypeID); INSERT INTO data_type (domain_id, entity_id, property_id, datatype) VALUES (0, 0, @PropID, @TextDatatypeID);
SELECT COUNT(*) INTO @x FROM null_data; SELECT COUNT(*) INTO @x FROM null_data;
...@@ -45,13 +44,17 @@ SELECT tap.eq(@x, 1, "One row in null_data table"); ...@@ -45,13 +44,17 @@ SELECT tap.eq(@x, 1, "One row in null_data table");
CALL updateEntity(@EntityID, "NewEntityName", "NewEntityDesc", "RECORD", NULL, NULL, "{acl2}"); CALL updateEntity(@EntityID, "NewEntityName", "NewEntityDesc", "RECORD", NULL, NULL, "{acl2}");
SELECT COUNT(id) INTO @x FROM entities WHERE name="EntityName"; SELECT tap.eq(COUNT(entity_id), 0, "Old Entity name not present")
SELECT tap.eq(@x, 0, "Old Entity name not present"); FROM name_data WHERE value="EntityName";
SELECT COUNT(id) INTO @x FROM entities WHERE name="NewEntityName"; SELECT tap.eq(COUNT(entity_id), 1, "Entity name has been updated")
SELECT tap.eq(@x, 1, "Entity name has been updated"); FROM name_data WHERE value="NewEntityName";
SELECT acl INTO @x FROM entities WHERE name="NewEntityName"; SELECT tap.eq(acl, @ACLID2, "acl has been updated")
SELECT tap.eq(@x, @ACLID2, "acl has been updated"); FROM entities WHERE id=@EntityID;
-- CALL updateEntity again an update the Name
CALL updateEntity(@EntityID, "NewerEntityName", "NewerEntityDesc", "RECORD", NULL, NULL, "{acl2}");
CALL updateEntity(@EntityID, "NewEntityName", "NewEntityDesc", "RECORD", NULL, NULL, "{acl2}");
-- TEST deleteEntityProperties -- TEST deleteEntityProperties
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment