def dump(self, obj, *args, **kwargs): """Dump object. Override the parent method to add the documents linked to projects. It was not possible to use the `pre_dump` decorator, because `add_permission` need this property and we cannot be sure that this hook will be executed first. """ obj['documents'] = DocumentRecord.get_documents_by_project(obj['pid']) return super(ProjectMetadataSchemaV1, self).dump(obj, *args, **kwargs)
def delete(cls, user, record): """Delete permission check. :param user: Current user record. :param record: Record to check. :returns: True if action can be done. """ documents = DocumentRecord.get_documents_by_project(record['pid']) if documents: return False return cls.update(user, record)
def test_get_documents_by_project(db, project, document): """"Test getting documents by a project.""" document['projects'] = [{ '$ref': f'https://sonar.ch/api/projects/{project.id}' }] document.commit() document.reindex() db.session.commit() documents = DocumentRecord.get_documents_by_project(project.id) assert documents[0]['pid'] == document['pid'] assert documents[0][ 'permalink'] == f'http://localhost/global/documents/{document["pid"]}'