Skip to content

Commit

Permalink
Settings: Add checkbox for data removal upon uninstall (#11925)
Browse files Browse the repository at this point in the history
Co-authored-by: Pascal Birchler <pascalb@google.com>
Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 27, 2022
1 parent 3f9e79f commit aa324c0
Show file tree
Hide file tree
Showing 12 changed files with 285 additions and 1 deletion.
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
5 changes: 5 additions & 0 deletions includes/uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ function delete_posts(): void {
[
'fields' => 'ids',
'suppress_filters' => false,
'post_status' => 'any',
'post_type' => [
Story_Post_Type::POST_TYPE_SLUG,
Page_Template_Post_Type::POST_TYPE_SLUG,
Expand Down Expand Up @@ -184,6 +185,10 @@ function delete_terms(): void {
$taxonomies[] = $injector->make( Category_Taxonomy::class )->get_taxonomy_slug();
$taxonomies[] = $injector->make( Tag_Taxonomy::class )->get_taxonomy_slug();

foreach ( $taxonomies as $taxonomy ) {
clean_taxonomy_cache( $taxonomy );
}

$term_query = new WP_Term_Query();
$terms = $term_query->query(
[
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 );
}
}
Loading

0 comments on commit aa324c0

Please sign in to comment.