From bad44c540a692f56af832cfc59fe29f73aad59fa Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 5 Feb 2015 16:22:52 -0800 Subject: [PATCH] also guard deleteEntity and getEntityProperties with canEdit. make canEdit available to javascript --- .../entities/src/EntityScriptingInterface.cpp | 44 +++++++++++-------- .../entities/src/EntityScriptingInterface.h | 5 ++- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 8aa3c31a5e..35c0bb1ddb 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -73,30 +73,33 @@ EntityItemID EntityScriptingInterface::identifyEntity(EntityItemID entityID) { EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID entityID) { EntityItemProperties results; - EntityItemID identity = identifyEntity(entityID); - if (_entityTree) { - _entityTree->lockForRead(); - EntityItem* entity = const_cast(_entityTree->findEntityByEntityItemID(identity)); + + if (canEdit()) { + EntityItemID identity = identifyEntity(entityID); + if (_entityTree) { + _entityTree->lockForRead(); + EntityItem* entity = const_cast(_entityTree->findEntityByEntityItemID(identity)); - if (entity) { - results = entity->getProperties(); + if (entity) { + results = entity->getProperties(); - // TODO: improve sitting points and naturalDimensions in the future, - // for now we've included the old sitting points model behavior for entity types that are models - // we've also added this hack for setting natural dimensions of models - if (entity->getType() == EntityTypes::Model) { - const FBXGeometry* geometry = _entityTree->getGeometryForEntity(entity); - if (geometry) { - results.setSittingPoints(geometry->sittingPoints); - Extents meshExtents = geometry->getUnscaledMeshExtents(); - results.setNaturalDimensions(meshExtents.maximum - meshExtents.minimum); + // TODO: improve sitting points and naturalDimensions in the future, + // for now we've included the old sitting points model behavior for entity types that are models + // we've also added this hack for setting natural dimensions of models + if (entity->getType() == EntityTypes::Model) { + const FBXGeometry* geometry = _entityTree->getGeometryForEntity(entity); + if (geometry) { + results.setSittingPoints(geometry->sittingPoints); + Extents meshExtents = geometry->getUnscaledMeshExtents(); + results.setNaturalDimensions(meshExtents.maximum - meshExtents.minimum); + } } - } - } else { - results.setIsUnknownID(); + } else { + results.setIsUnknownID(); + } + _entityTree->unlock(); } - _entityTree->unlock(); } return results; @@ -148,6 +151,9 @@ EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const E void EntityScriptingInterface::deleteEntity(EntityItemID entityID) { + if (! canEdit()) + return; + EntityItemID actualID = entityID; // if the entity is unknown, attempt to look it up diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 6700a86731..19003c3349 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -60,9 +60,12 @@ public: void setEntityTree(EntityTree* modelTree) { _entityTree = modelTree; } EntityTree* getEntityTree(EntityTree*) { return _entityTree; } - bool canEdit(); public slots: + + // returns true if the DomainServer will allow this Node/Avatar to make changes + Q_INVOKABLE bool canEdit(); + /// adds a model with the specific properties Q_INVOKABLE EntityItemID addEntity(const EntityItemProperties& properties);