Skip to content

Commit

Permalink
Censor fixes for URLs.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Hoikas committed Jun 16, 2021
1 parent f786443 commit 7006969
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions Scripts/Python/ki/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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("")
Expand All @@ -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:
Expand All @@ -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):

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 7006969

Please sign in to comment.