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

42302 Can't remove/delete secrets and keys #680

Merged
merged 15 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
70 changes: 63 additions & 7 deletions css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,6 @@ body #post-head-content p.wp-clearfix:nth-child(1) {
.options-menu li:hover a p{
color:#fff;
}
@media only screen and (max-width: 782px) {
.page-option-action summary{
padding: 10px 15px;
font-size: 14px;
white-space: nowrap;
}
}

/* new style */
.oo-poststuff .custom-input-field {
Expand Down Expand Up @@ -682,6 +675,52 @@ body #post-head-content p.wp-clearfix:nth-child(1) {
cursor: pointer;
}

.delete-google-recaptcha-keys-button.button {
border: 1px solid #ff0000;
color: #ff0000;
margin-top: 20px;
}

.delete-google-recaptcha-keys-button.button:hover,
.delete-google-recaptcha-keys-button.button:focus {
border: 1px solid #ff0000;
color: #ffffff;
background-color: #ff0000;
}

.oo-google-recaptcha-key {
max-width: 380px;
position: relative;
}

.oo-google-recaptcha-key > button.button {
position: absolute;
top: 0;
right: 10px;
background: none;
border: 1px solid transparent;
box-shadow: none;
width: 40px;
height: 30px;
min-width: 40px;
}

.oo-google-recaptcha-key > button.button:hover {
background: none;
border: 1px solid transparent;
transform: scale(1.2);
}

.oo-google-recaptcha-key > button.button:focus {
background: none;
border: 1px solid transparent;
box-shadow: none;
}

.oo-google-recaptcha-key > button > span {
margin-top: 5px;
}

@media only screen and (max-width: 1365px) {
.block-publish .postbox-header {
display: none;
Expand Down Expand Up @@ -743,3 +782,20 @@ body #post-head-content p.wp-clearfix:nth-child(1) {
margin: 0 !important;
}
}

@media only screen and (max-width: 782px) {
.page-option-action summary{
padding: 10px 15px;
font-size: 14px;
white-space: nowrap;
}

.oo-google-recaptcha-key {
max-width: none;
width: 100%;
}

.oo-google-recaptcha-key > button > span {
margin-top: 10px;
}
}
2 changes: 1 addition & 1 deletion dist/onoffice-handle-notification-actions.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions js/onoffice-handle-notification-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,20 @@ jQuery(document).ready(function ($) {

jQuery.post(warning_active_plugin_vars.ajaxurl, data);
});

$(document).on('click', '.delete-google-recaptcha-keys-button', function (event) {
let notification = confirm_dialog_google_recaptcha_keys.notification;
if (confirm(notification)) {
event.preventDefault();
const data = {
'action': 'delete_google_recaptcha_keys'
};

jQuery.post(delete_google_recaptcha_keys.ajaxurl, data);
$('input[name="onoffice-settings-captcha-sitekey"]').val('');
$('input[name="onoffice-settings-captcha-secretkey"]').val('');
} else {
event.preventDefault();
}
});
});
22 changes: 22 additions & 0 deletions js/onoffice-handle-visibility-google-recaptcha-keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
jQuery(document).ready(function ($) {
function showOrHideGoogleRecaptchaKey(inputSelector, toggleSelector) {
const inputElement = $(inputSelector);
const toggleElement = $(toggleSelector);

if (inputElement.attr('type') === 'password') {
inputElement.attr('type', 'text');
toggleElement.removeClass('dashicons-visibility').addClass('dashicons-hidden');
} else if (inputElement.attr('type') === 'text') {
inputElement.attr('type', 'password');
toggleElement.removeClass('dashicons-hidden').addClass('dashicons-visibility');
}
}

$('.oo-icon-eye-secret-key').on('click', function () {
showOrHideGoogleRecaptchaKey('input[name="onoffice-settings-captcha-secretkey"]', '.oo-icon-eye-secret-key');
});

$('.oo-icon-eye-site-key').on('click', function () {
showOrHideGoogleRecaptchaKey('input[name="onoffice-settings-captcha-sitekey"]', '.oo-icon-eye-site-key');
});
});
10 changes: 10 additions & 0 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,18 @@ function update_status_close_action_button_option()
echo true;
wp_die();
}

function delete_google_recaptcha_keys()
{
update_option('onoffice-settings-captcha-sitekey', '');
update_option('onoffice-settings-captcha-secretkey', '');
echo true;
wp_die();
}

add_action('wp_ajax_update_active_plugin_seo_option', 'update_status_close_action_button_option');
add_action('wp_ajax_update_duplicate_check_warning_option', 'update_duplicate_check_warning_option');
add_action('wp_ajax_delete_google_recaptcha_keys', 'delete_google_recaptcha_keys');

add_action('wp', function () {
if (!get_option('add-detail-posts-to-rewrite-rules')) {
Expand Down
11 changes: 11 additions & 0 deletions plugin/Controller/AdminViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,23 @@ public function enqueue_css()

public function enqueueExtraJs($hook)
{
$confirmDialogGoogleRecaptcha = [
'notification' => __('Would you like to permanently delete the site key and the secret key?', 'onoffice-for-wp-websites'),
];
wp_register_script('handle-notification-actions', plugins_url('dist/onoffice-handle-notification-actions.min.js', ONOFFICE_PLUGIN_DIR . '/index.php'),
array('jquery'));
wp_localize_script('handle-notification-actions', 'duplicate_check_option_vars', ['ajaxurl' => admin_url('admin-ajax.php')]);
wp_localize_script('handle-notification-actions', 'warning_active_plugin_vars', ['ajaxurl' => admin_url('admin-ajax.php')]);
wp_enqueue_script('handle-notification-actions');

if (__String::getNew($hook)->contains($this->_pageSlug.'-settings')) {
wp_register_script('handle-visibility-google-recaptcha-keys', plugins_url('dist/onoffice-handle-visibility-google-recaptcha-keys.min.js', ONOFFICE_PLUGIN_DIR . '/index.php'),
array('jquery'));
wp_localize_script('handle-notification-actions', 'delete_google_recaptcha_keys', ['ajaxurl' => admin_url('admin-ajax.php')]);
wp_localize_script('handle-notification-actions', 'confirm_dialog_google_recaptcha_keys', $confirmDialogGoogleRecaptcha);
wp_enqueue_script('handle-visibility-google-recaptcha-keys');
}

if (__String::getNew($hook)->contains('onoffice')) {
$pObject = $this->getObjectByHook($hook);
if ($pObject !== null && method_exists($pObject, 'doExtraEnqueues')) {
Expand Down
2 changes: 2 additions & 0 deletions plugin/Gui/AdminPageApiSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,11 @@ private function addFormModelGoogleCaptcha()
('onoffice-settings', 'captcha-sitekey', $labelSiteKey, 'string');
$optionNameKey = $pInputModelCaptchaSiteKey->getIdentifier();
$pInputModelCaptchaSiteKey->setValue(get_option($optionNameKey));
$pInputModelCaptchaSiteKey->setHtmlType(InputModelOption::HTML_GOOGLE_RECAPTCHA_ACCOUNT);
$pInputModelCaptchaPageSecret = new InputModelOption
('onoffice-settings', 'captcha-secretkey', $labelSecretKey, 'string');
$pInputModelCaptchaPageSecret->setIsPassword(true);
$pInputModelCaptchaPageSecret->setHtmlType(InputModelOption::HTML_GOOGLE_RECAPTCHA_ACCOUNT);
$optionNameSecret = $pInputModelCaptchaPageSecret->getIdentifier();
$pInputModelCaptchaPageSecret->setSanitizeCallback(function($password) use ($optionNameSecret) {
return $this->checkPassword($password, $optionNameSecret);
Expand Down
3 changes: 3 additions & 0 deletions plugin/Model/InputModelBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ abstract class InputModelBase
/** */
const HTML_SEARCH_FIELD_FOR_FIELD_LISTS = 'searchFieldForFieldLists';

/** */
const HTML_GOOGLE_RECAPTCHA_ACCOUNT = 'googleRecaptchaAccount';

/** @var string */
private $_name = null;

Expand Down
78 changes: 78 additions & 0 deletions plugin/Renderer/InputFieldGoogleRecaptchaAccountRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/**
*
* Copyright (C) 2023 onOffice GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace onOffice\WPlugin\Renderer;

use Exception;

/**
*
*/
class InputFieldGoogleRecaptchaAccountRenderer extends InputFieldRenderer
{
/**
*
* @param string $type
* @param string $name
* @param string $value
*
* @throws Exception
*/

public function __construct($type, $name, $value = null)
{
if (!in_array($type, array('googleRecaptchaAccount'))) {
throw new Exception('wrong type!');
}
parent::__construct($type, $name, $value);
}


/**
*
*/

public function render()
{
$iconShowPassword = '';
$showDeleteGoogleRecaptchaKeysButton = false;
if ($this->getName() === 'onoffice-settings-captcha-secretkey') {
$iconShowPassword = '<button type="button" class="button" data-toggle="0">
<span class="dashicons dashicons-visibility oo-icon-eye-secret-key" aria-hidden="true"></span>
</button>';
$showDeleteGoogleRecaptchaKeysButton = true;
} elseif ($this->getName() === 'onoffice-settings-captcha-sitekey') {
$iconShowPassword = '<button type="button" class="button" data-toggle="0">
<span class="dashicons dashicons-visibility oo-icon-eye-site-key" aria-hidden="true"></span>
</button>';
}
echo '<div class="oo-google-recaptcha-key">';
echo '<input type="password" name="' . esc_html($this->getName())
. '" value="' . esc_html($this->getValue()) . '" id="' . esc_html($this->getGuiId()) . '"'
. ' ' . $this->renderAdditionalAttributes()
. '>' . $iconShowPassword;
echo '</div>';

if ($showDeleteGoogleRecaptchaKeysButton) {
echo '<button class="button delete-google-recaptcha-keys-button">'. __('Delete Keys', 'onoffice-for-wp-websites') .'</button>';
}
}
}
6 changes: 6 additions & 0 deletions plugin/Renderer/InputModelRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ private function createInputField(InputModelBase $pInputModel, FormModel $pFormM
$pInstance->setCheckedValues($pInputModel->getValue());
$pInstance->setOoModule($pFormModel->getOoModule());
break;

case InputModelOption::HTML_GOOGLE_RECAPTCHA_ACCOUNT:
$pInstance = new InputFieldGoogleRecaptchaAccountRenderer('googleRecaptchaAccount', $elementName);
$pInstance->addAdditionalAttribute('size', '50');
$pInstance->setValue($pInputModel->getValue());
break;
}

if ($pInstance !== null) {
Expand Down
19 changes: 19 additions & 0 deletions tests/TestClassAdminViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use onOffice\WPlugin\Controller\AdminViewController;
use onOffice\WPlugin\Fieldnames;
use onOffice\WPlugin\Gui\AdminPageAjax;
use onOffice\WPlugin\Gui\AdminPageApiSettings;
use onOffice\WPlugin\Gui\AdminPageEstate;
use onOffice\WPlugin\Gui\AdminPageEstateDetail;
use onOffice\WPlugin\Record\RecordManagerReadForm;
Expand Down Expand Up @@ -335,4 +336,22 @@ public function testDisplayEmptyResultException()
$pAdminViewController->displayAPIError();
$this->expectOutputString('<div class="notice notice-error"><p>The onOffice plugin has an unexpected problem when trying to reach the onOffice API.</p><p>Please check the <a href="https://status.onoffice.de/">onOffice server status</a> to see if there are known problems. Otherwise, report the problem using the <a href="https://wp-plugin.onoffice.com/en/support/">support form</a>.</p></div>');
}

/**
* @depends testOnInit
* @param AdminViewController $pAdminViewController
* @throws Exception
* @global array $wp_filter
*/
public function testEnqueueExtraJsWithHandleRecaptcha(AdminViewController $pAdminViewController)
{
global $wp_filter;
$wp_filter['admin_page_onoffice-settings'] = new \WP_Hook;
/* @var $pWpHook WP_Hook */
$pWpHook = $wp_filter['admin_page_onoffice-settings'];
$adminPage = new AdminPageApiSettings('admin_page_onoffice-settings');
$pWpHook->callbacks = [[['function' => [$adminPage]]]];
$pAdminViewController->enqueueExtraJs("admin_page_onoffice-settings");
$this->assertEquals(['handle-notification-actions', 'handle-visibility-google-recaptcha-keys'], wp_scripts()->queue);
}
}
66 changes: 66 additions & 0 deletions tests/TestClassInputFieldGoogleRecaptchaAccountRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

/**
*
* Copyright (C) 2023 onOffice GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

declare (strict_types=1);

namespace onOffice\tests;

use onOffice\WPlugin\Renderer\InputFieldGoogleRecaptchaAccountRenderer;
use WP_UnitTestCase;

/**
*
* @url http://www.onoffice.de
* @copyright 2003-2023, onOffice(R) GmbH
*
*/

class TestClassInputFieldGoogleRecaptchaAccountRenderer
extends WP_UnitTestCase
{
/**
*
*/
public function testRenderInputSecretKey()
{
$pSubject = new InputFieldGoogleRecaptchaAccountRenderer('googleRecaptchaAccount', 'onoffice-settings-captcha-secretkey', '');
ob_start();
$pSubject->render();
$output = ob_get_clean();
$this->assertEquals('<div class="oo-google-recaptcha-key"><input type="password" name="onoffice-settings-captcha-secretkey" value="" id="googleRecaptchaAccount_4" ><button type="button" class="button" data-toggle="0">
<span class="dashicons dashicons-visibility oo-icon-eye-secret-key" aria-hidden="true"></span>
</button></div><button class="button delete-google-recaptcha-keys-button">Delete Keys</button>', $output);
}

/**
*
*/
public function testRenderInputSiteKey()
{
$pSubject = new InputFieldGoogleRecaptchaAccountRenderer('googleRecaptchaAccount', 'onoffice-settings-captcha-sitekey', '');
ob_start();
$pSubject->render();
$output = ob_get_clean();
$this->assertEquals('<div class="oo-google-recaptcha-key"><input type="password" name="onoffice-settings-captcha-sitekey" value="" id="googleRecaptchaAccount_5" ><button type="button" class="button" data-toggle="0">
<span class="dashicons dashicons-visibility oo-icon-eye-site-key" aria-hidden="true"></span>
</button></div>', $output);
}
}
Loading