Skip to content
Snippets Groups Projects
Commit cb98845e authored by Timm Fitschen's avatar Timm Fitschen Committed by Henrik tom Wörden
Browse files

f-hot-fix-docs-670 -> dev

parent fdec5e90
No related branches found
No related tags found
No related merge requests found
...@@ -19,5 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -19,5 +19,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,12 +41,18 @@ delimiter // ...@@ -41,12 +41,18 @@ 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 WHERE domain_id=0 and (entity_id=0 and property_id=EntityID) or entity_id=EntityID; DELETE FROM data_type WHERE domain_id=0 and (entity_id=0 and property_id=EntityID) or entity_id=EntityID;
DELETE FROM collection_type WHERE domain_id=0 and (entity_id=0 and property_id=EntityID) or entity_id=EntityID; DELETE FROM collection_type WHERE domain_id=0 and (entity_id=0 and property_id=EntityID) or entity_id=EntityID;
DELETE FROM entities where id=EntityID;
DELETE FROM entity_acl WHERE NOT EXISTS (SELECT 1 FROM entities WHERE entities.acl = entity_acl.id LIMIT 1); -- 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;
DELETE FROM entity_acl WHERE NOT EXISTS (SELECT 1 FROM entities WHERE entities.acl = entity_acl.id LIMIT 1);
END; END;
// //
......
...@@ -36,10 +36,18 @@ BEGIN ...@@ -36,10 +36,18 @@ BEGIN
DECLARE ACLID INT UNSIGNED DEFAULT NULL; DECLARE ACLID INT UNSIGNED DEFAULT NULL;
call entityACL(ACLID, ACL); call entityACL(ACLID, ACL);
UPDATE entities e SET e.description = EntityDescription, e.role=EntityRole, e.acl = ACLID where e.id = EntityID; UPDATE entities e
SET e.description = EntityDescription, e.role=EntityRole, e.acl = ACLID
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 where domain_id=0 AND entity_id=0 AND property_id=EntityID; DELETE from data_type where domain_id=0 AND entity_id=0 AND property_id=EntityID;
......
USE _caosdb_schema_unit_tests;
BEGIN;
CALL tap.no_plan();
-- SETUP
CALL entityACL(@ACLID1, "{acl1}");
CALL entityACL(@ACLID2, "{acl2}");
SELECT entity_id into @TextDatatypeID FROM name_data WHERE value ="TEXT";
-- TESTS
-- TEST insertEntity
SELECT tap.eq(COUNT(id), 0, "No entities")
FROM entities WHERE id>=100;
CALL insertEntity("EntityName", "EntityDesc", "RECORDTYPE", "{acl1}");
SELECT tap.eq(COUNT(entity_id), 1, "Entity has been inserted")
FROM name_data WHERE value="EntityName";
SELECT entity_id INTO @EntityID FROM name_data WHERE value="EntityName";
SELECT tap.ok(@EntityID >= 100, "EntityID greater 99");
SELECT tap.eq(acl, @ACLID1, "correct acl id had been assigned")
FROM entities WHERE id=@EntityID;
-- TEST insertEntityProperty
CALL insertEntity("AProperty", "APropDesc", "PROPERTY", "{acl1}");
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);
SELECT COUNT(*) INTO @x FROM null_data;
SELECT tap.eq(@x, 0, "No data in null_data table");
CALL insertEntityProperty(0, @EntityID, @PropID, "null_data", NULL, NULL, "RECOMMENDED", NULL, NULL, NULL, NULL, 0);
SELECT COUNT(*) INTO @x FROM null_data;
SELECT tap.eq(@x, 1, "One row in null_data table");
-- TEST updateEntity
CALL updateEntity(@EntityID, "NewEntityName", "NewEntityDesc", "RECORD", NULL, NULL, "{acl2}");
SELECT tap.eq(COUNT(entity_id), 0, "Old Entity name not present")
FROM name_data WHERE value="EntityName";
SELECT tap.eq(COUNT(entity_id), 1, "Entity name has been updated")
FROM name_data WHERE value="NewEntityName";
SELECT tap.eq(acl, @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
CALL deleteEntityProperties(@EntityID);
SELECT COUNT(*) INTO @x FROM null_data;
SELECT tap.eq(@x, 0, "data removed from null_data table");
-- TEST deleteEntity
CALL deleteEntity(@EntityID);
CALL deleteEntity(@PropID);
SELECT COUNT(id) INTO @x FROM entities WHERE id>100;
SELECT tap.eq(@x, 0, "entity deleted");
-- TESTS END
CALL tap.finish();
ROLLBACK;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment