-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
fix(data-secrecy): update fe state & address a couple bugs #82756
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -26,8 +26,13 @@ export default function DataSecrecy() { | |
const api = useApi(); | ||
const organization = useOrganization(); | ||
|
||
// state for the allowSuperuserAccess bit field | ||
const [allowAccess, setAllowAccess] = useState(organization.allowSuperuserAccess); | ||
const [allowDate, setAllowDate] = useState<WaiverData>(); | ||
|
||
// state of the data secrecy waiver | ||
const [waiver, setWaiver] = useState<WaiverData>(); | ||
|
||
// state for the allowDateFormData field | ||
const [allowDateFormData, setAllowDateFormData] = useState<string>(''); | ||
|
||
const {data, refetch} = useApiQuery<WaiverData>( | ||
|
@@ -38,12 +43,9 @@ export default function DataSecrecy() { | |
} | ||
); | ||
|
||
const hasValidTempAccess = | ||
allowDate?.accessEnd && moment().toISOString() < allowDate.accessEnd; | ||
|
||
useEffect(() => { | ||
if (data?.accessEnd) { | ||
setAllowDate(data); | ||
setWaiver(data); | ||
// slice it to yyyy-MM-ddThh:mm format (be aware of the timezone) | ||
const localDate = moment(data.accessEnd).local(); | ||
setAllowDateFormData(localDate.format('YYYY-MM-DDTHH:mm')); | ||
|
@@ -57,10 +59,31 @@ export default function DataSecrecy() { | |
data: {allowSuperuserAccess: value}, | ||
}); | ||
setAllowAccess(value); | ||
addSuccessMessage(t('Successfully updated access.')); | ||
|
||
// if the user has allowed access, we need to remove the temporary access window | ||
// only if there is an existing waiver | ||
if (value && waiver) { | ||
await api.requestPromise(`/organizations/${organization.slug}/data-secrecy/`, { | ||
method: 'DELETE', | ||
}); | ||
setAllowDateFormData(''); | ||
setWaiver(undefined); | ||
} | ||
addSuccessMessage( | ||
value | ||
? waiver | ||
? t( | ||
'Successfully removed temporary access window and allowed support access.' | ||
) | ||
: t('Successfully allowed support access.') | ||
: t('Successfully removed support access.') | ||
); | ||
} catch (error) { | ||
addErrorMessage(t('Unable to save changes.')); | ||
} | ||
|
||
// refetch to get the latest waiver data | ||
refetch(); | ||
}; | ||
|
||
const updateTempAccessDate = async () => { | ||
|
@@ -69,7 +92,7 @@ export default function DataSecrecy() { | |
await api.requestPromise(`/organizations/${organization.slug}/data-secrecy/`, { | ||
method: 'DELETE', | ||
}); | ||
setAllowDate({accessStart: '', accessEnd: ''}); | ||
setWaiver({accessStart: '', accessEnd: ''}); | ||
addSuccessMessage(t('Successfully removed temporary access window.')); | ||
} catch (error) { | ||
addErrorMessage(t('Unable to remove temporary access window.')); | ||
|
@@ -86,14 +109,11 @@ export default function DataSecrecy() { | |
}; | ||
|
||
try { | ||
await await api.requestPromise( | ||
`/organizations/${organization.slug}/data-secrecy/`, | ||
{ | ||
method: 'PUT', | ||
data: nextData, | ||
} | ||
); | ||
setAllowDate(nextData); | ||
await api.requestPromise(`/organizations/${organization.slug}/data-secrecy/`, { | ||
method: 'PUT', | ||
data: nextData, | ||
}); | ||
setWaiver(nextData); | ||
addSuccessMessage(t('Successfully updated temporary access window.')); | ||
} catch (error) { | ||
addErrorMessage(t('Unable to save changes.')); | ||
|
@@ -123,10 +143,20 @@ export default function DataSecrecy() { | |
help: t( | ||
'Open a temporary time window for Sentry employees to access your organization' | ||
), | ||
disabled: allowAccess && !organization.access.includes('org:write'), | ||
value: allowAccess ? '' : allowDateFormData, | ||
// disable the field if the user has allowed access or if the user does not have org:write access | ||
disabled: allowAccess || !organization.access.includes('org:write'), | ||
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. this was a bug, we should disable the date input if data secrecy is disabled OR if the user doesn't have enough permissions |
||
disabledReason: allowAccess | ||
? t('Disable permanent access first to set temporary access') | ||
: !organization.access.includes('org:write') | ||
? t('You do not have permission to modify access settings') | ||
: undefined, | ||
value: allowDateFormData, | ||
onBlur: updateTempAccessDate, | ||
onChange: v => { | ||
// Don't allow the user to set the date if they have allowed access | ||
if (allowAccess) { | ||
return; | ||
} | ||
// the picker doesn't like having a datetime string with seconds+ and a timezone, | ||
// so we remove it -- we will add it back when we save the date | ||
const formattedDate = v ? moment(v).format('YYYY-MM-DDTHH:mm') : ''; | ||
|
@@ -140,9 +170,9 @@ export default function DataSecrecy() { | |
<PanelBody> | ||
{!allowAccess && ( | ||
<PanelAlert> | ||
{hasValidTempAccess | ||
{waiver?.accessEnd && moment().isBefore(moment(waiver.accessEnd)) | ||
? tct(`Sentry employees has access to your organization until [date]`, { | ||
date: formatDateTime(allowDate?.accessEnd as string), | ||
date: formatDateTime(waiver?.accessEnd as string), | ||
}) | ||
: t('Sentry employees do not have access to your organization')} | ||
</PanelAlert> | ||
|
Oops, something went wrong.
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.
i added 2 awaits 😵