mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
You can now add and remove users for ownership history
This commit is contained in:
+2
-2
@@ -1,9 +1,9 @@
|
||||
class Usecase:
|
||||
def __init__(self, file, **settings):
|
||||
self.file = file
|
||||
self.settings = {"actor": None}
|
||||
self.settings = {"person": None, "organisation": None}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
self.file.remove(self.settings["actor"])
|
||||
return self.file.createIfcPersonAndOrganization(self.settings["person"], self.settings["organisation"])
|
||||
@@ -27,7 +27,7 @@ class Usecase:
|
||||
elif inverse.is_a("IfcPersonAndOrganization"):
|
||||
ifcopenshell.api.run("owner.remove_person_and_organisation", self.file, person_and_organisation=inverse)
|
||||
elif inverse.is_a("IfcActor"):
|
||||
ifcopenshell.api.run("owner.remove_actor", self.file, actor=inverse)
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=inverse)
|
||||
elif inverse.is_a("IfcResourceLevelRelationship") and not inverse.is_a("IfcOrganizationRelationship"):
|
||||
if inverse.RelatedResourceObjects == (self.settings["organisation"],):
|
||||
self.file.remove(inverse)
|
||||
|
||||
@@ -28,7 +28,7 @@ class Usecase:
|
||||
elif inverse.is_a("IfcPersonAndOrganization"):
|
||||
ifcopenshell.api.run("owner.remove_person_and_organisation", self.file, person_and_organisation=inverse)
|
||||
elif inverse.is_a("IfcActor"):
|
||||
ifcopenshell.api.run("owner.remove_actor", self.file, actor=inverse)
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=inverse)
|
||||
elif inverse.is_a("IfcResourceLevelRelationship"):
|
||||
if inverse.RelatedResourceObjects == (self.settings["person"],):
|
||||
self.file.remove(inverse)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, **settings):
|
||||
self.file = file
|
||||
@@ -6,4 +9,15 @@ class Usecase:
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
for inverse in self.file.get_inverse(self.settings["person_and_organisation"]):
|
||||
if inverse.is_a("IfcDocumentInformation"):
|
||||
if inverse.Editors == (self.settings["person_and_organisation"],):
|
||||
inverse.Editors = None
|
||||
elif inverse.is_a("IfcActor"):
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=inverse)
|
||||
elif inverse.is_a("IfcResourceLevelRelationship"):
|
||||
if inverse.RelatedResourceObjects == (self.settings["person_and_organisation"],):
|
||||
self.file.remove(inverse)
|
||||
elif inverse.is_a("IfcOwnerHistory"):
|
||||
self.file.remove(inverse)
|
||||
self.file.remove(self.settings["person_and_organisation"])
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class TestAddPersonAndOrganisation(test.bootstrap.IFC4):
|
||||
def test_adding(self):
|
||||
person = self.file.createIfcPerson()
|
||||
organisation = self.file.createIfcOrganization()
|
||||
person_and_organisation = ifcopenshell.api.run(
|
||||
"owner.add_person_and_organisation", self.file, person=person, organisation=organisation
|
||||
)
|
||||
@@ -0,0 +1,45 @@
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class TestRemovePersonAndOrganisation(test.bootstrap.IFC4):
|
||||
def test_removing(self):
|
||||
user = self.file.createIfcPersonAndOrganization()
|
||||
ifcopenshell.api.run("owner.remove_person_and_organisation", self.file, person_and_organisation=user)
|
||||
assert len(self.file.by_type("IfcPersonAndOrganization")) == 0
|
||||
|
||||
def test_deleting_actors(self):
|
||||
user = self.file.createIfcPersonAndOrganization()
|
||||
self.file.createIfcActor(GlobalId=ifcopenshell.guid.new(), TheActor=user)
|
||||
ifcopenshell.api.run("owner.remove_person_and_organisation", self.file, person_and_organisation=user)
|
||||
assert len(self.file.by_type("IfcActor")) == 0
|
||||
|
||||
def test_ensuring_document_information_should_not_be_left_in_an_invalid_set_cardinality(self):
|
||||
user = self.file.createIfcPersonAndOrganization()
|
||||
document_information = self.file.createIfcDocumentInformation(Editors=[user])
|
||||
ifcopenshell.api.run("owner.remove_person_and_organisation", self.file, person_and_organisation=user)
|
||||
assert document_information.Editors is None
|
||||
|
||||
def test_deleting_resource_approval_relationships(self):
|
||||
user = self.file.createIfcPersonAndOrganization()
|
||||
self.file.createIfcResourceApprovalRelationship(RelatedResourceObjects=[user])
|
||||
ifcopenshell.api.run("owner.remove_person_and_organisation", self.file, person_and_organisation=user)
|
||||
assert len(self.file.by_type("IfcResourceApprovalRelationship")) == 0
|
||||
|
||||
def test_deleting_resource_constraint_relationships(self):
|
||||
user = self.file.createIfcPersonAndOrganization()
|
||||
self.file.createIfcResourceConstraintRelationship(RelatedResourceObjects=[user])
|
||||
ifcopenshell.api.run("owner.remove_person_and_organisation", self.file, person_and_organisation=user)
|
||||
assert len(self.file.by_type("IfcResourceConstraintRelationship")) == 0
|
||||
|
||||
def test_deleting_external_reference_relationships(self):
|
||||
user = self.file.createIfcPersonAndOrganization()
|
||||
self.file.createIfcExternalReferenceRelationship(RelatedResourceObjects=[user])
|
||||
ifcopenshell.api.run("owner.remove_person_and_organisation", self.file, person_and_organisation=user)
|
||||
assert len(self.file.by_type("IfcExternalReferenceRelationship")) == 0
|
||||
|
||||
def test_deleting_owner_history(self):
|
||||
user = self.file.createIfcPersonAndOrganization()
|
||||
self.file.createIfcOwnerHistory(OwningUser=user)
|
||||
ifcopenshell.api.run("owner.remove_person_and_organisation", self.file, person_and_organisation=user)
|
||||
assert len(self.file.by_type("IfcOwnerHistory")) == 0
|
||||
Reference in New Issue
Block a user