Skip to content
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

Conversation

michalkowalczyk-box
Copy link
Contributor

@michalkowalczyk-box michalkowalczyk-box commented Sep 6, 2024

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.

@michalkowalczyk-box michalkowalczyk-box requested a review from a team as a code owner September 6, 2024 08:29
const showDownload = can_download && !isDeleted && isDownloadable;
const showPromote = can_upload && !isDeleted && !isCurrent;
const showPromote = can_upload && !isDeleted && !shouldDisablePromoteAndDelete && !isCurrent;
const showRestore = can_delete && isDeleted;
Copy link
Contributor

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?

Copy link
Contributor Author

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

Comment on lines 245 to 253
${{ 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 }}
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

@psatala-box psatala-box left a 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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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",

Comment on lines 274 to 279
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();
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Comment on lines 346 to 351
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();
Copy link
Contributor

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", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
Copy link
Contributor

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.

@michalkowalczyk-box michalkowalczyk-box force-pushed the disable-version-modifications-for-content-sidebar branch from 8cc1644 to 1dcc7c6 Compare October 2, 2024 18:31
@michalkowalczyk-box michalkowalczyk-box requested a review from a team as a code owner October 2, 2024 18:31
@michalkowalczyk-box michalkowalczyk-box changed the title feat(content-sidebar): disable version modifications for content sidebar feat(content-sidebar): disable version modifications for archive file Oct 2, 2024
@@ -238,5 +238,111 @@ describe('elements/content-sidebar/versions/VersionsItem', () => {
expect(wrapper.exists(VersionsItemRetention)).toBe(true);
expect(wrapper.find(VersionsItemActions).prop('isRetained')).toBe(true);
});

Copy link
Contributor

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.

Copy link
Contributor Author

@michalkowalczyk-box michalkowalczyk-box Oct 9, 2024

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', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

Copy link
Contributor Author

@michalkowalczyk-box michalkowalczyk-box Oct 9, 2024

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

Copy link
Contributor Author

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

jstoffan
jstoffan previously approved these changes Oct 9, 2024
@@ -43,6 +47,7 @@ type Props = {
type State = {
error?: MessageDescriptor,
isLoading: boolean,
isArchiveFile: boolean,
Copy link
Contributor

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.

Copy link
Contributor Author

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,
Copy link
Contributor

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.

Copy link
Contributor Author

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();
Copy link
Contributor

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.

Copy link
Contributor Author

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

@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

@michalkowalczyk-box michalkowalczyk-box Oct 9, 2024

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

jstoffan
jstoffan previously approved these changes Oct 9, 2024
Copy link
Contributor

@psatala-box psatala-box left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!

@mergify mergify bot merged commit e735c4c into box:master Oct 11, 2024
6 checks passed
@michalkowalczyk-box michalkowalczyk-box deleted the disable-version-modifications-for-content-sidebar branch October 11, 2024 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants