-
Notifications
You must be signed in to change notification settings - Fork 14
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
Redact pii #297
Open
ce314007
wants to merge
3
commits into
BaritoLog:master
Choose a base branch
from
ce314007:redact-pii
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.
Open
Redact pii #297
Changes from 2 commits
Commits
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 contains 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
This file contains 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,173 @@ | ||
div.modal.fade id="manage-redact-modal" tabindex="-1" role="dialog" aria-labeledby="manage-redact-modal-title" aria-hidden=true | ||
div.modal-dialog role="document" | ||
div.modal-content | ||
= form_with(url: update_labels_app_group_path, method: 'patch', local: true, id: 'update-redacts') | ||
div.modal-header | ||
h5.modal-title#manage-redact-modal-title | ||
= "Manage PII Redact Data #{app_group}" | ||
button.close data-dismiss="modal" aria-label="close" type="button" | ||
span aria-hidden=true | ||
| × | ||
div.modal-body | ||
table.table | ||
thead | ||
tr | ||
th[scope="col"] | ||
| PII | ||
th[scope="col"] | ||
| Value | ||
- if @allow_manage_labels | ||
th[scope="col"] | ||
| Actions | ||
tbody#redact-body | ||
div.modal-footer | ||
- if @allow_manage_labels | ||
button#remove-all-redacts.btn.btn-danger type="button" | ||
| remove all PII | ||
button#add-redact.btn.btn-success type="button" | ||
| add PII | ||
button#submit-redact.btn.btn-primary type="submit" | ||
| update | ||
|
||
javascript: | ||
const redacts = #{labels.to_json.html_safe} | ||
const allow_manage_redacts = #{allow_manage_labels} | ||
|
||
const removeAllRedacts = () => { | ||
const rows = $(`tbody#redact-body tr[data-idx]`) | ||
for (let row of rows) { | ||
row.remove() | ||
} | ||
} | ||
|
||
const removeRedact = idx => { | ||
let row = $(`tbody#redact-body tr[data-idx="${idx}"]`) | ||
if (row.length < 1) { | ||
console.log(`rows with redact ${idx} not found`) | ||
} | ||
|
||
row[0].remove() | ||
} | ||
|
||
const generateRowRedact = (pii, val, idx) => { | ||
let delete_button = "" | ||
if (allow_manage_labels) { | ||
delete_button = ` <td> | ||
<button class="btn btn-sm btn-danger" data-idx="${idx}" id="remove-redact" type="button"> | ||
<i class="far fa-trash-alt"></i> | ||
</button> | ||
</td>` | ||
} | ||
return `<tr data-idx="${idx}"> | ||
<td> | ||
<input class="form-control" name=piis[] value="${pii}" ${allow_manage_labels ? "" : "disabled"}> | ||
</td> | ||
<td> | ||
<input class="form-control" name=values[] value="${val}" ${allow_manage_labels ? "" : "disabled"}> | ||
</td> | ||
${delete_button} | ||
</tr>` | ||
console.log("Generated row:", row); | ||
return row; | ||
} | ||
|
||
const addRedact = (pii, val, idx) => { | ||
console.log("Adding label:", pii, val, idx) | ||
let tbody = $('tbody#redact-body') | ||
let lastIdx = idx || Number($(tbody.children().last()).attr('data-idx'))+1 | ||
let lastPii = pii || "" | ||
let lastVal = val || "" | ||
tbody.append(generateRowRedact(lastPii, lastVal, lastIdx)) | ||
} | ||
|
||
const getIdFromClickedButtonRedact = event => { | ||
return event.currentTarget.id | ||
} | ||
|
||
const getRowNumberFromClickedButtonRedact = event => { | ||
return $(event.currentTarget).attr('data-idx') | ||
} | ||
|
||
const onModalButtonClickedRedact = event => { | ||
console.log("Button clicked:", event.currentTarget.id) | ||
const buttonId = getIdFromClickedButtonRedact(event) | ||
switch(buttonId) { | ||
case "remove-all-redacts": | ||
removeAllRedacts() | ||
break | ||
case "remove-redact": | ||
const idx = getRowNumberFromClickedButtonRedact(event) | ||
removeRedact(idx) | ||
break | ||
case "add-redact": | ||
addRedact() | ||
break | ||
} | ||
} | ||
|
||
const removeAppNameFieldRedact = () => { | ||
$(`input[name="app_name"]`).remove() | ||
} | ||
|
||
const resetModalFieldsRedact = () => { | ||
removeAllRedacts() | ||
removeAppNameFieldRedact() | ||
modifyTitle(`Manage PII redact Data #{app_group}`) | ||
modifyFormAction(`#{update_labels_app_group_path}`) | ||
} | ||
|
||
const getApplicationURLFromClickedButtonRedact = event => { | ||
return $(event.relatedTarget).attr('data-app-path') | ||
} | ||
const getApplicationNameFromClickedButtonRedact = event => { | ||
return $(event.relatedTarget).attr('data-app-name') | ||
} | ||
const isManageAppGroupRedactsEventRedact = event => { | ||
return getApplicationNameFromClickedButtonRedact(event) === undefined | ||
} | ||
|
||
const modifyTitleRedact = text => { | ||
$('#manage-redact-modal-title').text(text) | ||
} | ||
|
||
const modifyFormActionRedact = action => { | ||
$('form#update-redacts').attr('action', action) | ||
} | ||
|
||
const modifyModalForManageApplicationRedacts = event => { | ||
let appName = getApplicationNameFromClickedButtonRedact(event) | ||
modifyFormAction(getApplicationURLFromClickedButtonRedact(event)) | ||
|
||
modifyTitleRedact(`Manage PII Redact Data #{app_group}: ${appName}`) | ||
|
||
$('tbody#redact-body').append(`<input type="hidden" name="app_name" value="${appName}">`) | ||
|
||
return appName | ||
} | ||
|
||
const showCurrentRedacts = redacts => { | ||
Object.piis(redacts).map((pii, idx) => addRedact(pii, redacts[pii], idx+1)) | ||
} | ||
|
||
const onModalOpenRedact = event => { | ||
resetModalFieldsRedact() | ||
|
||
let shownRedact = [] | ||
if (isManageAppGroupRedactsEvent(event)) { | ||
shownRedact = redacts['app-group'] | ||
} else { | ||
let appName = modifyModalForManageApplicationRedacts(event) | ||
shownRedact = redacts[appName] | ||
} | ||
|
||
showCurrentRedacts(shownRedact) | ||
} | ||
|
||
if (typeof $ === 'undefined') { | ||
console.log("jQuery is not loaded!"); | ||
} else { | ||
console.log("jQuery is loaded and ready to use."); | ||
} | ||
|
||
$('body').on('click', '#manage-redact-modal button.btn', onModalButtonClickedRedact) | ||
$('#manage-redact-modal').on('show.bs.modal', onModalOpen) |
This file contains 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 |
---|---|---|
|
@@ -106,6 +106,11 @@ | |
= link_to 'Show Helm Infrastructure', helm_infrastructure_path(@app_group.helm_infrastructure), class: 'text-light', style: 'text-decoration: none' | ||
- else | ||
= link_to 'Create Helm Infrastructure', new_app_group_helm_infrastructure_path(@app_group), class: 'text-light', style: 'text-decoration: none' | ||
|
||
.btn.btn-primary.btn-sm.mr-2 data-toggle="modal" data-target="#manage-redact-modal" | ||
i.fa.fa-user-shield.mr-1 | ||
| Redact PII Data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add |
||
|
||
- if @allow_delete_helm_infrastructure | ||
div class=("btn btn-danger btn-sm text-light #{!@allow_delete_helm_infrastructure ? 'disabled' : ''}") id=("delete_helm_infrastructure_#{@app_group.helm_infrastructure.id}") | ||
i.far.fa-trash-alt.mr-1 | ||
|
@@ -116,3 +121,4 @@ br | |
|
||
= render 'app_groups/applications', new_app: @new_app, app_group: @app_group, apps: @apps, allow_delete: @allow_delete_barito_app, allow_add: @allow_add_barito_app | ||
= render 'app_groups/modal', labels: @labels, app_group: @app_group.name, allow_manage_labels:@allow_manage_labels | ||
= render 'app_groups/redact-modal', labels: @labels, app_group: @app_group.name, allow_manage_labels:@allow_manage_labels |
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.
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.
please add
Rules
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.
where is the backend changes for this one?