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

Settings: Add checkbox for data removal upon uninstall #11925

Merged
merged 21 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions includes/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ class Settings extends Service_Base {
*/
public const SETTING_NAME_VIDEO_CACHE = 'web_stories_video_cache';

/**
* Data removal setting name.
*/
public const SETTING_NAME_DATA_REMOVAL = 'web_stories_data_removal';

/**
* Web Stories archive setting name.
*/
Expand Down Expand Up @@ -253,6 +258,17 @@ public function register(): void {
]
);

register_setting(
self::SETTING_GROUP,
self::SETTING_NAME_DATA_REMOVAL,
[
'description' => __( 'Data Removal', 'web-stories' ),
'type' => 'boolean',
'default' => false,
'show_in_rest' => true,
]
);

register_setting(
self::SETTING_GROUP,
self::SETTING_NAME_ARCHIVE,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* External dependencies
*/
import {
disableCheckbox,
enableCheckbox,
visitSettings,
} from '@web-stories-wp/e2e-test-utils';

/**
* Internal dependencies
*/
import { dataRemovalCheckboxSelector } from '../../../../utils';

describe('Admin User', () => {
beforeEach(async () => {
await visitSettings();
await enableCheckbox(dataRemovalCheckboxSelector);
});

it('should let me see and update data removal settings', async () => {
// verify that the data removal checkbox can be changed
await expect(page).toMatchElement(`${dataRemovalCheckboxSelector}:checked`);

await disableCheckbox(dataRemovalCheckboxSelector);

// verify that the data removal checkbox can be changed
await expect(page).toMatchElement(`${dataRemovalCheckboxSelector}:checked`);
await disableCheckbox(dataRemovalCheckboxSelector);
});
});
3 changes: 3 additions & 0 deletions packages/e2e-tests/src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ export const videoOptimizationCheckboxSelector =

export const videoCacheCheckboxSelector =
'input[data-testid="video-cache-settings-checkbox"]';

export const dataRemovalCheckboxSelector =
'input[data-testid="data-removal-settings-checkbox"]';
2 changes: 2 additions & 0 deletions packages/wp-dashboard/src/api/reducers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const defaultSettingsState = {
archive: ARCHIVE_TYPE.DEFAULT,
archivePageId: 0,
videoCache: false,
dataRemoval: false,
settingSaved: false,
shoppingProvider: SHOPPING_PROVIDER_TYPE.NONE,
shopifyHost: '',
Expand Down Expand Up @@ -76,6 +77,7 @@ function settingsReducer(state, action) {
adManagerSlotId: action.payload.adManagerSlotId,
adNetwork: action.payload.adNetwork,
videoCache: action.payload.videoCache,
dataRemoval: action.payload.dataRemoval,
archive: action.payload.archive,
archivePageId: action.payload.archivePageId,
shoppingProvider: action.payload.shoppingProvider,
Expand Down
6 changes: 6 additions & 0 deletions packages/wp-dashboard/src/api/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const transformSettingResponse = (response) => ({
adManagerSlotId: response.web_stories_ad_manager_slot_id,
adNetwork: response.web_stories_ad_network,
videoCache: response.web_stories_video_cache,
dataRemoval: response.web_stories_data_removal,
archive: response.web_stories_archive,
archivePageId: response.web_stories_archive_page_id,
shoppingProvider: response.web_stories_shopping_provider,
Expand Down Expand Up @@ -73,6 +74,7 @@ export function updateSettings(apiPath, queryParams) {
adManagerSlotId,
adNetwork,
videoCache,
dataRemoval,
archive,
archivePageId,
shoppingProvider,
Expand Down Expand Up @@ -110,6 +112,10 @@ export function updateSettings(apiPath, queryParams) {
query.web_stories_video_cache = Boolean(videoCache);
}

if (dataRemoval !== undefined) {
query.web_stories_data_removal = Boolean(dataRemoval);
}

if (archive !== undefined) {
query.web_stories_archive = archive;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* External dependencies
*/
import PropTypes from 'prop-types';
import { useCallback } from '@googleforcreators/react';
import { __ } from '@googleforcreators/i18n';
import { Checkbox, THEME_CONSTANTS } from '@googleforcreators/design-system';

/**
* Internal dependencies
*/
import {
SettingForm,
SettingHeading,
CheckboxLabel,
CheckboxLabelText,
} from '../components';

export default function DataRemovalSettings({
isEnabled = false,
updateSettings,
}) {
const onChange = useCallback(
() => updateSettings({ dataRemoval: !isEnabled }),
[updateSettings, isEnabled]
);

return (
<SettingForm>
<div>
<SettingHeading>{__('Plugin Uninstall', 'web-stories')}</SettingHeading>
</div>
<div>
<CheckboxLabel forwardedAs="label" htmlFor="data-removal-settings">
<Checkbox
id="data-removal-settings"
data-testid="data-removal-settings-checkbox"
onChange={onChange}
checked={Boolean(isEnabled)}
/>
<CheckboxLabelText
size={THEME_CONSTANTS.TYPOGRAPHY.PRESET_SIZES.SMALL}
aria-checked={Boolean(isEnabled)}
forwardedAs="span"
>
{__(
'Remove all data including stories and saved templates when uninstalling the Web Stories plugin.',
'web-stories'
)}
</CheckboxLabelText>
</CheckboxLabel>
</div>
</SettingForm>
);
}

DataRemovalSettings.propTypes = {
isEnabled: PropTypes.bool,
updateSettings: PropTypes.func.isRequired,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Internal dependencies
*/
import DataRemovalSettings from '..';

export default {
title: 'Dashboard/Views/EditorSettings/DataRemovalSettings',
component: DataRemovalSettings,
args: {
isEnabled: true,
},
argTypes: {
updateSettings: { action: 'updateSettings fired' },
},
};

export const _default = (args) => {
return <DataRemovalSettings {...args} />;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* External dependencies
*/
import { fireEvent, screen } from '@testing-library/react';

/**
* Internal dependencies
*/
import DataRemovalSettings from '..';
import { renderWithProviders } from '../../../../testUtils';

describe('Editor Settings: <DataRemovalSettings />', function () {
it('should render the data removal setting as checked when isEnabled', function () {
renderWithProviders(
<DataRemovalSettings updateSettings={jest.fn()} isEnabled />
);

expect(screen.getByRole('checkbox')).toBeChecked();
});

it('should not render the data removal setting as checked when not isEnabled', function () {
renderWithProviders(<DataRemovalSettings updateSettings={jest.fn()} />);

expect(screen.getByRole('checkbox')).not.toBeChecked();
});

it('should update settings when the checkbox is clicked.', function () {
const onChange = jest.fn();
renderWithProviders(<DataRemovalSettings updateSettings={onChange} />);

const checkbox = screen.getByRole('checkbox');
fireEvent.click(checkbox);

expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledWith({ dataRemoval: true });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import PublisherLogoSettings from './publisherLogo';
import TelemetrySettings from './telemetry';
import MediaOptimizationSettings from './mediaOptimization';
import VideoCacheSettings from './videoCache';
import DataRemovalSettings from './dataRemoval';
import ArchiveSettings from './archive';
import GoogleAnalyticsSettings from './googleAnalytics';
import { Wrapper, Main } from './components';
Expand All @@ -58,6 +59,7 @@ function EditorSettings() {
newlyCreatedMediaIds,
isMediaLoading,
videoCache,
dataRemoval,
archive,
archivePageId,
searchPages,
Expand Down Expand Up @@ -97,6 +99,7 @@ function EditorSettings() {
adManagerSlotId,
adNetwork,
videoCache,
dataRemoval,
archive,
archivePageId,
shoppingProvider,
Expand All @@ -120,6 +123,7 @@ function EditorSettings() {
isMediaLoading,
newlyCreatedMediaIds,
videoCache,
dataRemoval,
archive,
archivePageId,
searchPages,
Expand Down Expand Up @@ -368,6 +372,10 @@ function EditorSettings() {
isEnabled={videoCache}
updateSettings={updateSettings}
/>
<DataRemovalSettings
isEnabled={dataRemoval}
updateSettings={updateSettings}
/>
<ArchiveSettings
archive={archive}
archiveURL={archiveURL}
Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/integration/tests/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function test_register(): void {
$this->assertArrayHasKey( $settings::SETTING_NAME_ACTIVE_PUBLISHER_LOGO, $options );
$this->assertArrayHasKey( $settings::SETTING_NAME_PUBLISHER_LOGOS, $options );
$this->assertArrayHasKey( $settings::SETTING_NAME_VIDEO_CACHE, $options );
$this->assertArrayHasKey( $settings::SETTING_NAME_DATA_REMOVAL, $options );
$this->assertArrayHasKey( $settings::SETTING_NAME_ARCHIVE, $options );
}
}
5 changes: 4 additions & 1 deletion uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@
return;
}


timarney marked this conversation as resolved.
Show resolved Hide resolved
$erase = (bool) get_option( \Google\Web_Stories\Settings::SETTING_NAME_DATA_REMOVAL );

/**
* Filters whether data should be erased when uninstalling the plugin.
*
* @since 1.0.0
*
* @param bool $erase Whether to erase data. Default false.
*/
$erase = (bool) apply_filters( 'web_stories_erase_data_on_uninstall', false );
$erase = (bool) apply_filters( 'web_stories_erase_data_on_uninstall', $erase );

if ( false === $erase ) {
return;
Expand Down