From 7006969fbf71e22b18ac8615de1fce890f325e6c Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 27 Mar 2021 18:58:19 -0400 Subject: [PATCH] Censor fixes for URLs. We cannot censor the contents of KI mail in the vault. This would cause URLs containing naughty words to be irrevocably broken, linking to somewhere other than the original link. As a side effect, we now lock the editing of KI mail to its creator (or sender) to prevent naughty words escaping the censor. --- Scripts/Python/ki/__init__.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/Scripts/Python/ki/__init__.py b/Scripts/Python/ki/__init__.py index 80933be6fe..512bfd822e 100644 --- a/Scripts/Python/ki/__init__.py +++ b/Scripts/Python/ki/__init__.py @@ -3656,9 +3656,18 @@ def IsContentMutable(self, nodeRef): # Get its parent folder. if isinstance(nodeRef, ptVaultNodeRef): folder = self.BKCurrentContent.getParent() - if folder: - folder = folder.upcastToFolderNode() - if folder: + item = self.BKCurrentContent.getChild() + if folder and item: + # Observed: sometimes, the creator ID is zero. This can mean either a DRC item or + # a poorly initialized node. Better check against the saver ID as well, which is + # used to display the From field. + creatorID = item.getCreatorNodeID() + if creatorID == 0: + creatorID = self.BKCurrentContent.getSaverID() + + if creatorID != PtGetLocalClientID(): + return False + if folder := folder.upcastToFolderNode(): if folder.folderGetType() == PtVaultStandardNodes.kGlobalInboxFolder: return False return True @@ -5122,11 +5131,11 @@ def BigKIEnterEditMode(self, whichField): # Set the edit box and display it. if self.BKEditField == kGUI.BKEditFieldJRNTitle: edElement = edElement.upcastToTextNoteNode() - editBox.setString(xCensor.xCensor(edElement.noteGetTitle(), self.censorLevel)) + editBox.setStringW(edElement.getTitleW()) KIJournalExpanded.dialog.setFocus(editBox.getKey()) elif self.BKEditField == kGUI.BKEditFieldPICTitle: edElement = edElement.upcastToImageNode() - editBox.setString(xCensor.xCensor(edElement.imageGetTitle(), self.censorLevel)) + editBox.setStringW(edElement.getTitleW()) KIPictureExpanded.dialog.setFocus(editBox.getKey()) else: editBox.setString("") @@ -5138,7 +5147,7 @@ def BigKIEnterEditMode(self, whichField): elif whichField == kGUI.BKEditFieldPICTitle: KIPictureExpanded.dialog.refreshAllControls() else: - PtDebugPrint("xKI.BigKIEnterEditMode(): Content has no element to edit.", level=kErrorLevel) + PtDebugPrint("xKI.BigKIEnterEditMode(): Content has no element to edit.") else: # Is it for the journal edit? if whichField == kGUI.BKEditFieldJRNNote: @@ -5147,6 +5156,11 @@ def BigKIEnterEditMode(self, whichField): self.BKEditContent = self.BKCurrentContent self.BKEditField = whichField + # But we need to change the content over to the non-censored version without + # active hyperlinks. Otherwise we get interesting results where the URLs become + # censored and offset. + self.journalNoteArea.setStringW(self.BKEditContent.getChild().upcastToTextNoteNode().getTextW(), urlDetection=False) + ## Save what the player was editing to the right place. def BigKISaveEdit(self, noExitEditMode=False): @@ -5175,7 +5189,7 @@ def BigKISaveEdit(self, noExitEditMode=False): if edElement is not None: if editBox is not None: if not editBox.wasEscaped(): - textBox.setString(editBox.getString()) + textBox.setStringW(xCensor.xCensor(editBox.getStringW(), self.censorLevel)) if self.BKEditField == kGUI.BKEditFieldJRNTitle: edElement = edElement.upcastToTextNoteNode() jTitle = editBox.getStringW()