-
Notifications
You must be signed in to change notification settings - Fork 2
S-137651 Include custom text fields and tags to redaction script #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hariharan-digitalai
wants to merge
6
commits into
master
Choose a base branch
from
S-137651
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+183
−75
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bc80219
S-137651 Updated script to redact custom text fields and remove tag v…
hariharan-digitalai aeb532e
S-137651 Renamed redact script
hariharan-digitalai 2baacb2
S-137651 Addressed copilot comments
hariharan-digitalai 1f726d1
S-137651 Move deleting tags to separate script file
hariharan-digitalai 4e74fe3
S-137651: Update script to redact tags instead of deleting them
hariharan-digitalai 1462a8c
S-137651 Addressed review comments
hariharan-digitalai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * Redact the name, description, and selected custom text/long-text fields of a story, | ||
| * and delete any commits or webhook events that include those fields in their payload. | ||
| * | ||
| * INSTRUCTIONS: | ||
| * 1. Set @storyNumber to the Story number to redact | ||
| * 2. Set @customTextDefinition if any custom text field needs to be redacted | ||
| * 3. Set @customLongTextDefinition if any custom long text field needs to be redacted | ||
| * 4. Review the messages printed by the script to verify that it is updating the expected records | ||
| * 5. Set @saveChanges=1 | ||
| * 6. Rerun the script to commit the changes | ||
| * | ||
| * NOTE: This script defaults to rolling back changes. | ||
| * To commit changes, set @saveChanges = 1. | ||
| */ | ||
| declare @storyNumber int=NNNNN | ||
| declare @customTextDefinition varchar(201)=NULL -- e.g. 'AssetType.Custom_text_field' | ||
| declare @customLongTextDefinition varchar(201)=NULL -- e.g. 'AssetType.Custom_long_text_field' | ||
| declare @saveChanges bit; set @saveChanges = 1 | ||
|
|
||
| declare @customTextFieldName varchar(201)=case | ||
| when @customTextDefinition is not null and charindex('.', @customTextDefinition) > 0 | ||
| then right(@customTextDefinition, charindex('.', reverse(@customTextDefinition)) - 1) | ||
| end | ||
| declare @customLongTextFieldName varchar(201)=case | ||
| when @customLongTextDefinition is not null and charindex('.', @customLongTextDefinition) > 0 | ||
| then right(@customLongTextDefinition, charindex('.', reverse(@customLongTextDefinition)) - 1) | ||
| end | ||
|
|
||
| declare @storyId int | ||
| select @storyId=ID from dbo.Workitem_Now where AssetType='Story' and Number=@storyNumber | ||
|
|
||
| if (@storyId is null) begin | ||
| raiserror('S-%d not found', 16, 1, @storyNumber) | ||
| return | ||
| end | ||
| raiserror('Found Story:%d', 0, 1, @storyId) with nowait | ||
|
|
||
| declare @storyOid varchar(max)='Story:'+cast(@storyId as varchar(max))+':%' | ||
| declare @redacted nvarchar(max)=N'redacted' | ||
| declare @hash int=BINARY_CHECKSUM(@redacted) | ||
|
|
||
| set nocount on; begin tran; save tran tx | ||
| declare @error int, @rowcount int | ||
|
|
||
| update dbo.String | ||
| set Value=@redacted, Hash=@hash | ||
| from dbo.BaseAsset | ||
| where String.ID=Name and BaseAsset.ID=@storyId | ||
|
|
||
| select @rowcount=@@ROWCOUNT, @error=@@ERROR | ||
| if @error<>0 goto ERR | ||
| raiserror('%d Names redacted', 0, 1, @rowcount) with nowait | ||
|
|
||
| update dbo.LongString | ||
| set Value=@redacted | ||
| from dbo.BaseAsset | ||
| where LongString.ID=Description and BaseAsset.ID=@storyId | ||
|
|
||
| select @rowcount=@@ROWCOUNT, @error=@@ERROR | ||
| if @error<>0 goto ERR | ||
| raiserror('%d Descriptions redacted', 0, 1, @rowcount) with nowait | ||
|
|
||
| update dbo.String | ||
| set Value=@redacted, Hash=@hash | ||
| from dbo.CustomText | ||
| where @customTextDefinition is not null and String.ID=CustomText.Value and CustomText.ID=@storyId | ||
| and CustomText.Definition = @customTextDefinition | ||
|
|
||
| select @rowcount=@@ROWCOUNT, @error=@@ERROR | ||
| if @error<>0 goto ERR | ||
| raiserror('%d Custom Text redacted', 0, 1, @rowcount) with nowait | ||
|
|
||
| update dbo.LongString | ||
| set Value=@redacted | ||
| from dbo.CustomLongText | ||
| where @customLongTextDefinition is not null and LongString.ID=CustomLongText.Value and CustomLongText.ID=@storyId | ||
| and CustomLongText.Definition = @customLongTextDefinition | ||
|
|
||
| select @rowcount=@@ROWCOUNT, @error=@@ERROR | ||
| if @error<>0 goto ERR | ||
| raiserror('%d Custom Long Text redacted', 0, 1, @rowcount) with nowait | ||
|
|
||
| delete dbo.Commits | ||
| where cast(Payload as varchar(max)) like '%Asset":"'+@storyOid and ( | ||
| cast(Payload as varchar(max)) like '%"Name":"Name"%' or | ||
| cast(Payload as varchar(max)) like '%"Name":"Description"%' or | ||
| cast(Payload as varchar(max)) like '%"Name":"' + @customTextFieldName + '"%' or | ||
| cast(Payload as varchar(max)) like '%"Name":"' + @customLongTextFieldName + '"%' | ||
| ) | ||
|
|
||
| select @rowcount=@@ROWCOUNT, @error=@@ERROR | ||
| if @error<>0 goto ERR | ||
| raiserror('%d Commits deleted', 0, 1, @rowcount) with nowait | ||
|
|
||
| delete dbo.WebhookEvents | ||
| where cast(Payload as varchar(max)) like '%oid":"'+@storyOid and ( | ||
| cast(Payload as varchar(max)) like '%"name":"Name"%' or | ||
| cast(Payload as varchar(max)) like '%"name":"Description"%' or | ||
| cast(Payload as varchar(max)) like '%"name":"' + @customTextFieldName + '"%' or | ||
| cast(Payload as varchar(max)) like '%"name":"' + @customLongTextFieldName + '"%' | ||
| ) | ||
|
|
||
| select @rowcount=@@ROWCOUNT, @error=@@ERROR | ||
| if @error<>0 goto ERR | ||
| raiserror('%d WebhookEvents deleted', 0, 1, @rowcount) with nowait | ||
|
|
||
| if @saveChanges=1 goto OK | ||
| raiserror('Rolling back changes. To commit changes, set @saveChanges=1', 16, 1) | ||
| ERR: rollback tran tx | ||
| OK: commit | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| This script redacts a specific tag associated with a specific workitem. | ||
| Set @workitemNumber to the number of the workitem you want to redact. | ||
| Set @assetType to the type of the workitem (e.g., 'Story'). | ||
| Set @tagValue to the exact tag value to redact. | ||
| Set @replaceWith to the value that will replace the tag. | ||
| Set @saveChanges to 1 to commit changes, or 0 to roll back. | ||
| */ | ||
|
|
||
| declare @workitemNumber int=NNNNN | ||
| declare @assetType varchar(100)=NULL -- e.g. 'Story' | ||
| declare @tagValue nvarchar(440)=NULL -- e.g. 'item for review' (the literal tag value) | ||
| declare @replaceWith nvarchar(440)='redacted' | ||
| declare @saveChanges bit; --set @saveChanges = 1 | ||
|
|
||
| declare @workitemId int | ||
| select @workitemId=ID from dbo.Workitem_Now where AssetType=@assetType and Number=@workitemNumber | ||
|
|
||
| if (@workitemId is null) begin | ||
| raiserror('%d not found', 16, 1, @workitemNumber) | ||
| return | ||
| end | ||
| raiserror('Found %s:%d', 0, 1, @assetType, @workitemId) with nowait | ||
|
|
||
| if exists ( | ||
| select 1 | ||
| from dbo.BaseAssetTaggedWith | ||
| where ID=@workitemId | ||
| and Value=@replaceWith | ||
| and Value<>@tagValue | ||
| ) begin | ||
| raiserror('Replacement tag already exists in this workitem''s history', 16, 1) | ||
| return | ||
| end | ||
|
|
||
| declare @workitemOid varchar(max)=@assetType+':'+cast(@workitemId as varchar(max))+':%' | ||
|
|
||
| set nocount on; begin tran; save tran tx | ||
| declare @error int, @rowcount int | ||
|
|
||
| update dbo.BaseAssetTaggedWith | ||
| set Value=@replaceWith | ||
| where ID=@workitemId and Value=@tagValue | ||
|
spazmodius marked this conversation as resolved.
|
||
|
|
||
| select @rowcount=@@ROWCOUNT, @error=@@ERROR | ||
| if @error<>0 goto ERR | ||
| raiserror('%d Tags deleted', 0, 1, @rowcount) with nowait | ||
|
|
||
| declare @encodedTag as nvarchar (max) = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(@tagValue, N'\', N'\\'), N'"', N'\"'), N'~', N'~~'), N'%', N'~%'), N'_', N'~_'), N'[', N'~['); | ||
|
|
||
| delete dbo.Commits | ||
| where cast(Payload as varchar(max)) like '%Asset":"'+@workitemOid | ||
| and cast(Payload as varchar(max)) like '%"Name":"TaggedWith"%Value":"'+@encodedTag+'"%' ESCAPE N'~'; | ||
|
|
||
|
|
||
| select @rowcount=@@ROWCOUNT, @error=@@ERROR | ||
| if @error<>0 goto ERR | ||
| raiserror('%d Commits deleted', 0, 1, @rowcount) with nowait | ||
|
|
||
| delete dbo.WebhookEvents | ||
| where cast(Payload as varchar(max)) like '%oid":"'+@workitemOid | ||
| and cast(Payload as varchar(max)) like '%"name":"TaggedWith"%"new":"'+@encodedTag+'"%' ESCAPE N'~'; | ||
|
|
||
| select @rowcount=@@ROWCOUNT, @error=@@ERROR | ||
| if @error<>0 goto ERR | ||
| raiserror('%d WebhookEvents deleted', 0, 1, @rowcount) with nowait | ||
|
|
||
| if @saveChanges=1 goto OK | ||
| raiserror('Rolling back changes. To commit changes, set @saveChanges=1', 16, 1) | ||
| ERR: rollback tran tx | ||
| OK: commit | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.