App: Expose allowObject for groups in python

This commit is contained in:
Benjamin Nauck
2025-06-22 23:25:52 +02:00
parent b3c83df151
commit d2f35cee55
2 changed files with 33 additions and 0 deletions

View File

@@ -318,3 +318,30 @@ int GroupExtensionPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*
{
return 0;
}
// def allowObject(self, obj: Any) -> bool:
PyObject* GroupExtensionPy::allowObject(PyObject* args)
{
PyObject* object;
if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) {
return nullptr;
}
auto* docObj = static_cast<DocumentObjectPy*>(object);
if (!docObj->getDocumentObjectPtr()
|| !docObj->getDocumentObjectPtr()->isAttachedToDocument()) {
PyErr_SetString(Base::PyExc_FC_GeneralError, "Cannot check an invalid object");
return nullptr;
}
if (docObj->getDocumentObjectPtr()->getDocument()
!= getGroupExtensionPtr()->getExtendedObject()->getDocument()) {
PyErr_SetString(Base::PyExc_FC_GeneralError,
"Cannot check an object from another document from this group");
return nullptr;
}
GroupExtension* grp = getGroupExtensionPtr();
bool allowed = grp->allowObject(docObj->getDocumentObjectPtr());
return PyBool_FromLong(allowed ? 1 : 0);
}