-
Notifications
You must be signed in to change notification settings - Fork 305
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(content-sidebar): disable version modifications for archive file #3637
feat(content-sidebar): disable version modifications for archive file #3637
Conversation
const showDownload = can_download && !isDeleted && isDownloadable; | ||
const showPromote = can_upload && !isDeleted && !isCurrent; | ||
const showPromote = can_upload && !isDeleted && !shouldDisablePromoteAndDelete && !isCurrent; | ||
const showRestore = can_delete && isDeleted; |
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.
Should we also not allow restoring deleted versions?
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.
They're restored in archiving process, but maybe this could be disabled just in case too
${{ can_delete: true, can_download: true, can_preview: true, can_upload: true }} | ||
${{ can_delete: true, can_download: true, can_preview: true, can_upload: false }} | ||
${{ can_delete: true, can_download: true, can_preview: false, can_upload: true }} | ||
${{ can_delete: true, can_download: false, can_preview: true, can_upload: true }} | ||
${{ can_delete: false, can_download: true, can_preview: true, can_upload: true }} | ||
${{ can_delete: true, can_download: true, can_preview: false, can_upload: false }} | ||
${{ can_delete: true, can_download: false, can_preview: true, can_upload: false }} | ||
${{ can_delete: false, can_download: true, can_preview: false, can_upload: true }} | ||
${{ can_delete: false, can_download: false, can_preview: true, can_upload: true }} |
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.
Is there any reason you test those 9 combinations instead of all 16? Same for the last test
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.
Here, some of those have to be tested in test below, since none of actions are available and we don't render component. Rest didn't have affected permission, but I'll add them just in case
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.
Looks good, a couple nitpicks about the tests
${'restore'} | ${false} | ${true} | ${true} | ${false} | ${false} | ||
${'upload'} | ${false} | ${true} | ${true} | ${false} | ${false} | ||
`( | ||
"should show actions correctly when the version's action is $action and unchangeableVersions feature is disabled", |
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.
"should show actions correctly when the version's action is $action and unchangeableVersions feature is disabled", | |
"should show actions correctly when the version's action is $action and unchangeableVersions feature is enabled", |
expect(button.prop('isDisabled')).toBe(!permissions.can_preview); | ||
expect(actions.prop('showDelete')).toBe(false); | ||
expect(actions.prop('showDownload')).toBe(permissions.can_download); | ||
expect(actions.prop('showPromote')).toBe(false); | ||
expect(actions.prop('showPreview')).toBe(permissions.can_preview); | ||
expect(wrapper.find(ReadableTime)).toBeTruthy(); |
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.
Could you check showRestore
here as well?
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.
It'll always be false here, regardless of feature, since it needs action to be 'delete'. If I set action to delete it'll be testable, but same will happen to delete. I decided to test it with action tests below.
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'll look if it can be done better after the weekend
expect(button.prop('isDisabled')).toBe(!permissions.can_preview); | ||
expect(actions.prop('showDelete')).toBe(permissions.can_delete); | ||
expect(actions.prop('showDownload')).toBe(permissions.can_download); | ||
expect(actions.prop('showPromote')).toBe(permissions.can_upload); | ||
expect(actions.prop('showPreview')).toBe(permissions.can_preview); | ||
expect(wrapper.find(ReadableTime)).toBeTruthy(); |
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.
Could you check showRestore
here as well?
}, | ||
); | ||
|
||
test("should show actions correctly when the version's action is $action and unchangeableVersions feature is disabled", () => { |
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.
test("should show actions correctly when the version's action is $action and unchangeableVersions feature is disabled", () => { | |
test("should not show actions when the version's action is delete and unchangeableVersions feature is enabled", () => { |
const showPromote = can_upload && !isDeleted && !isCurrent; | ||
const showRestore = can_delete && isDeleted; | ||
const showPromote = can_upload && !shouldDisableVersionChanges && !isDeleted && !isCurrent; | ||
const showRestore = can_delete && !shouldDisableVersionChanges && isDeleted; |
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.
We should use permissions to control whether a user has the ability to do something. That way, our API will enforce the same restrictions.
8cc1644
to
1dcc7c6
Compare
@@ -238,5 +238,111 @@ describe('elements/content-sidebar/versions/VersionsItem', () => { | |||
expect(wrapper.exists(VersionsItemRetention)).toBe(true); | |||
expect(wrapper.find(VersionsItemActions).prop('isRetained')).toBe(true); | |||
}); | |||
|
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.
Can you please rewrite those test to use React Testing Library. Enzyme is a huge problem in EUA and we need to slowly convert existing tests instead of creating new ones.
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.
Updated whole file to RTL
@@ -263,6 +265,17 @@ describe('elements/content-sidebar/versions/VersionsSidebarContainer', () => { | |||
|
|||
expect(wrapper.state('isWatermarked')).toBe(true); | |||
}); | |||
|
|||
test('should set state with isArchiveFile if file is archive file', () => { |
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.
As above.
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 feel this file is too complicated to switch whole of it from enzyme to RTL in scope of this PR. I have RTL implementation for new tests (added to tests this PR code changes), but I'm working on putting it alongside enzyme in this file. I'm having trouble, because some module mocks needed for RTL are breaking enzyme tests and vice versa
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.
Moved this test case to new file using RTL
@@ -43,6 +47,7 @@ type Props = { | |||
type State = { | |||
error?: MessageDescriptor, | |||
isLoading: boolean, | |||
isArchiveFile: boolean, |
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.
Minor, but we should alphabetize props and object properties when possible.
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.
Updated
@@ -66,6 +71,7 @@ class VersionsSidebarContainer extends React.Component<Props, State> { | |||
props: Props; | |||
|
|||
state: State = { | |||
isArchiveFile: false, |
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.
Minor, but consider isArchived
to stay consistent with isWatermarked
.
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.
Updated
expect(actions.prop('showPreview')).toBe(showPreview); | ||
expect(actions.prop('showRestore')).toBe(showRestore); | ||
expect(wrapper.find(ReadableTime)).toBeTruthy(); | ||
expect(wrapper).toMatchSnapshot(); |
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.
We generally want to avoid adding new snapshot tests, especially for larger components. Let's rely on explicit assertions, instead.
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've moved all the tests for this component to react-testing-library, so I removed snapshots completely there
i18n/en-US.properties
Outdated
@@ -938,6 +938,12 @@ boxui.collaboratorAvatars.viewAdditionalPeopleText = View additional people | |||
boxui.collapsiblesidebar.collapseBtnLabel = Collapse | |||
# Aria label for toggle button that expands/collapses sidebar (collapsed state) | |||
boxui.collapsiblesidebar.expandBtnLabel = Expand | |||
# Content Answers submit input button text | |||
boxui.contentAnswers.ask = Ask |
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.
It looks like something went awry during the pre-commit hook.
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.
Yep, it amended last commit for me and said to push with --no-verify, is this okay? Or should I revert changes for this file?
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.
It was pre-push hook
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.
Yeah, I would revert. Maybe @greg-in-a-box can comment on the automation here.
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.
Reverted them, lint_test_build
was failing on them https://github.com/box/box-ui-elements/runs/31305517831
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.
Great job!
Disables changing current version and deleting/restoring previous based on if previewed file is in archive, which is determined by existence of instance of global metadata template
archivedItemTemplate
. We need to use this approach temporarily, because permission settings for files that block this behavior on backend will not be publicly available in near future.This metadata field is used to display date in #3625.