-
-
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
feat(data-secrecy): Data Secrecy Settings UI #75791
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
974c6f7
build data secrecy fe
iamrajjoshi 54320a3
fix test failure
iamrajjoshi a9343d1
update settings order
iamrajjoshi 1f7f0eb
fix(pr): Updated with better UIUX. Still a bit buggy
leedongwei 5a417b1
fix timezone issue
iamrajjoshi a564a5a
fix tests
iamrajjoshi 34bb23b
fix tests
iamrajjoshi 4f667b3
fix test
iamrajjoshi cf02a03
more tests
iamrajjoshi d7d64f0
add disabled check
iamrajjoshi 326d564
add comment
iamrajjoshi 5bd93c0
precommit hook complain fix
iamrajjoshi 4620624
fixing linting
iamrajjoshi aee7da6
nits
iamrajjoshi 6568bed
fix to use camelcase & tiny bug
iamrajjoshi b8752bf
fix when to show ds
iamrajjoshi 5441d06
remove old code
iamrajjoshi 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
106 changes: 106 additions & 0 deletions
106
static/app/views/settings/components/dataSecrecy/index.spec.tsx
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,106 @@ | ||
import {initializeOrg} from 'sentry-test/initializeOrg'; | ||
import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary'; | ||
|
||
import DataSecrecy from 'sentry/views/settings/components/dataSecrecy'; | ||
|
||
jest.mock('sentry/actionCreators/indicator'); | ||
|
||
describe('DataSecrecy', function () { | ||
const {organization} = initializeOrg({ | ||
organization: {features: ['data-secrecy']}, | ||
}); | ||
|
||
beforeEach(function () { | ||
MockApiClient.clearMockResponses(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('renders default state with no waiver', async function () { | ||
MockApiClient.addMockResponse({ | ||
url: `/organizations/${organization.slug}/data-secrecy/`, | ||
body: null, | ||
}); | ||
|
||
render(<DataSecrecy />, {organization: organization}); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText('Support Access')).toBeInTheDocument(); | ||
}); | ||
|
||
organization.allowSuperuserAccess = false; | ||
|
||
await waitFor(() => { | ||
expect( | ||
screen.getByText(/sentry employees do not have access to your organization/i) | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('renders default state with waiver', async function () { | ||
MockApiClient.addMockResponse({ | ||
url: `/organizations/${organization.slug}/data-secrecy/`, | ||
body: null, | ||
}); | ||
|
||
render(<DataSecrecy />, {organization: organization}); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText('Support Access')).toBeInTheDocument(); | ||
}); | ||
|
||
organization.allowSuperuserAccess = true; | ||
|
||
await waitFor(() => { | ||
expect( | ||
screen.getByText(/sentry employees do not have access to your organization/i) | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('renders no access state with waiver present', async function () { | ||
MockApiClient.addMockResponse({ | ||
url: `/organizations/${organization.slug}/data-secrecy/`, | ||
body: { | ||
accessStart: '2022-08-29T01:05:00+00:00', | ||
accessEnd: '2023-08-29T01:05:00+00:00', | ||
}, | ||
}); | ||
|
||
render(<DataSecrecy />, {organization: organization}); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText('Support Access')).toBeInTheDocument(); | ||
}); | ||
|
||
organization.allowSuperuserAccess = false; | ||
|
||
// we should see no access message | ||
await waitFor(() => { | ||
expect( | ||
screen.getByText( | ||
/sentry employees will not have access to your organization unless granted permission/i | ||
) | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('renders current waiver state', async function () { | ||
MockApiClient.addMockResponse({ | ||
url: `/organizations/${organization.slug}/data-secrecy/`, | ||
body: { | ||
accessStart: '2023-08-29T01:05:00+00:00', | ||
accessEnd: '2024-08-29T01:05:00+00:00', | ||
}, | ||
}); | ||
|
||
organization.allowSuperuserAccess = false; | ||
render(<DataSecrecy />, {organization: organization}); | ||
|
||
await waitFor(() => { | ||
const accessMessage = screen.getByText( | ||
/Sentry employees has access to your organization until/i | ||
); | ||
expect(accessMessage).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
170 changes: 170 additions & 0 deletions
170
static/app/views/settings/components/dataSecrecy/index.tsx
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,170 @@ | ||
import {useEffect, useState} from 'react'; | ||
import moment from 'moment-timezone'; | ||
|
||
import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator'; | ||
import BooleanField, { | ||
type BooleanFieldProps, | ||
} from 'sentry/components/forms/fields/booleanField'; | ||
import DateTimeField, { | ||
type DateTimeFieldProps, | ||
} from 'sentry/components/forms/fields/dateTimeField'; | ||
import Panel from 'sentry/components/panels/panel'; | ||
import PanelAlert from 'sentry/components/panels/panelAlert'; | ||
import PanelBody from 'sentry/components/panels/panelBody'; | ||
import PanelHeader from 'sentry/components/panels/panelHeader'; | ||
import {t, tct} from 'sentry/locale'; | ||
import {useApiQuery} from 'sentry/utils/queryClient'; | ||
import useApi from 'sentry/utils/useApi'; | ||
import useOrganization from 'sentry/utils/useOrganization'; | ||
|
||
type WaiverData = { | ||
accessEnd: string | null; | ||
accessStart: string | null; | ||
}; | ||
|
||
export default function DataSecrecy() { | ||
const api = useApi(); | ||
const organization = useOrganization(); | ||
|
||
const [allowAccess, setAllowAccess] = useState(organization.allowSuperuserAccess); | ||
const [allowDate, setAllowDate] = useState<WaiverData>(); | ||
const [allowDateFormData, setAllowDateFormData] = useState<string>(''); | ||
|
||
const {data, refetch} = useApiQuery<WaiverData>( | ||
[`/organizations/${organization.slug}/data-secrecy/`], | ||
{ | ||
staleTime: 3000, | ||
retry: (failureCount, error) => failureCount < 3 && error.status !== 404, | ||
} | ||
); | ||
|
||
const hasValidTempAccess = | ||
allowDate?.accessEnd && moment().toISOString() < allowDate.accessEnd; | ||
|
||
useEffect(() => { | ||
if (data?.accessEnd) { | ||
setAllowDate(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')); | ||
} | ||
}, [data]); | ||
|
||
const updateAllowedAccess = async (value: boolean) => { | ||
try { | ||
await api.requestPromise(`/organizations/${organization.slug}/`, { | ||
method: 'PUT', | ||
data: {allowSuperuserAccess: value}, | ||
}); | ||
setAllowAccess(value); | ||
addSuccessMessage(t('Successfully updated access.')); | ||
} catch (error) { | ||
addErrorMessage(t('Unable to save changes.')); | ||
} | ||
}; | ||
|
||
const updateTempAccessDate = async () => { | ||
if (!allowDateFormData) { | ||
try { | ||
await api.requestPromise(`/organizations/${organization.slug}/data-secrecy/`, { | ||
method: 'DELETE', | ||
}); | ||
setAllowDate({accessStart: '', accessEnd: ''}); | ||
addSuccessMessage(t('Successfully removed temporary access window.')); | ||
} catch (error) { | ||
addErrorMessage(t('Unable to remove temporary access window.')); | ||
} | ||
|
||
return; | ||
} | ||
|
||
// maintain the standard format of storing the date in UTC | ||
// even though the api should be able to handle the local time | ||
const nextData: WaiverData = { | ||
accessStart: moment().utc().toISOString(), | ||
accessEnd: moment.tz(allowDateFormData, moment.tz.guess()).utc().toISOString(), | ||
}; | ||
|
||
try { | ||
await await api.requestPromise( | ||
`/organizations/${organization.slug}/data-secrecy/`, | ||
{ | ||
method: 'PUT', | ||
data: nextData, | ||
iamrajjoshi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
); | ||
setAllowDate(nextData); | ||
addSuccessMessage(t('Successfully updated temporary access window.')); | ||
} catch (error) { | ||
addErrorMessage(t('Unable to save changes.')); | ||
setAllowDateFormData(''); | ||
} | ||
// refetch to get the latest waiver data | ||
refetch(); | ||
}; | ||
|
||
const allowAccessProps: BooleanFieldProps = { | ||
name: 'allowSuperuserAccess', | ||
label: t('Allow access to Sentry employees'), | ||
help: t( | ||
'Sentry employees will not have access to your organization unless granted permission' | ||
), | ||
'aria-label': t( | ||
'Sentry employees will not have access to your data unless granted permission' | ||
), | ||
value: allowAccess, | ||
disabled: !organization.access.includes('org:write'), | ||
onBlur: updateAllowedAccess, | ||
}; | ||
|
||
const allowTempAccessProps: DateTimeFieldProps = { | ||
name: 'allowTemporarySuperuserAccess', | ||
label: t('Allow temporary access to Sentry employees'), | ||
help: t( | ||
'Open a temporary time window for Sentry employees to access your organization' | ||
), | ||
disabled: allowAccess && !organization.access.includes('org:write'), | ||
value: allowAccess ? '' : allowDateFormData, | ||
onBlur: updateTempAccessDate, | ||
onChange: v => { | ||
// 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') : ''; | ||
setAllowDateFormData(formattedDate); | ||
}, | ||
}; | ||
|
||
return ( | ||
<Panel> | ||
<PanelHeader>{t('Support Access')}</PanelHeader> | ||
<PanelBody> | ||
{!allowAccess && ( | ||
<PanelAlert> | ||
{hasValidTempAccess | ||
? tct(`Sentry employees has access to your organization until [date]`, { | ||
date: formatDateTime(allowDate?.accessEnd as string), | ||
}) | ||
: t('Sentry employees do not have access to your organization')} | ||
</PanelAlert> | ||
)} | ||
|
||
<BooleanField {...(allowAccessProps as BooleanFieldProps)} /> | ||
<DateTimeField {...(allowTempAccessProps as DateTimeFieldProps)} /> | ||
</PanelBody> | ||
</Panel> | ||
); | ||
} | ||
|
||
const formatDateTime = (dateString: string) => { | ||
const date = new Date(dateString); | ||
const options: Intl.DateTimeFormatOptions = { | ||
month: 'short', | ||
day: 'numeric', | ||
year: 'numeric', | ||
hour: 'numeric', | ||
minute: 'numeric', | ||
hour12: true, | ||
timeZoneName: 'short', | ||
}; | ||
return new Intl.DateTimeFormat('en-US', options).format(date); | ||
}; |
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
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
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.
Why do we retry? I just don't see this often in our frontend code so wondering how this endpoint is different from others that needs retrying.
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.
most endpoints are able to use the default retry, but since the api will return a 404 if an org doesn't have a waiver currently, the default behavior of the api would be to keep refreshing then render a failure state. here we prevent this by not refreshing on 404s.