Adds submission_use_recaptcha field to collection form. Captures site captcha key from admin settings. #388

This commit is contained in:
mateuswetah 2020-10-19 12:38:35 -03:00
parent 4413b803de
commit 1fa7962c25
7 changed files with 65 additions and 10 deletions

View File

@ -524,6 +524,24 @@
</div> </div>
</b-field> </b-field>
<!-- Submission process uses ReCAPTCHA ------------------------ -->
<b-field
:addons="false"
:label="$i18n.getHelperTitle('collections', 'submission_use_recaptcha')"
:type="editFormErrors['submission_use_recaptcha'] != undefined ? 'is-danger' : ''"
:message="editFormErrors['submission_use_recaptcha'] != undefined ? editFormErrors['submission_use_recaptcha'] : ''">
&nbsp;
<b-switch
id="tainacan-checkbox-submission-use-recaptcha"
size="is-small"
true-value="yes"
false-value="no"
v-model="form.submission_use_recaptcha" />
<help-button
:title="$i18n.getHelperTitle('collections', 'submission_use_recaptcha')"
:message="$i18n.getHelperMessage('collections', 'submission_use_recaptcha')"/>
</b-field>
</div> </div>
</transition> </transition>
@ -628,7 +646,8 @@ export default {
allows_submission: 'no', allows_submission: 'no',
submission_default_status: 'draft', submission_default_status: 'draft',
submission_anonymous_user: 'no', submission_anonymous_user: 'no',
hide_items_thumbnail_on_lists: '' hide_items_thumbnail_on_lists: '',
submission_use_recaptcha: 'no'
}, },
thumbnail: {}, thumbnail: {},
cover: {}, cover: {},
@ -725,6 +744,7 @@ export default {
this.form.allows_submission = this.collection.allows_submission; this.form.allows_submission = this.collection.allows_submission;
this.form.submission_anonymous_user = this.collection.submission_anonymous_user; this.form.submission_anonymous_user = this.collection.submission_anonymous_user;
this.form.submission_default_status = this.collection.submission_default_status; this.form.submission_default_status = this.collection.submission_default_status;
this.form.submission_use_recaptcha = this.collection.submission_use_recaptcha;
this.form.hide_items_thumbnail_on_lists = this.collection.hide_items_thumbnail_on_lists; this.form.hide_items_thumbnail_on_lists = this.collection.hide_items_thumbnail_on_lists;
// Generates CoverPage from current cover_page_id info // Generates CoverPage from current cover_page_id info
@ -825,6 +845,7 @@ export default {
allows_submission: this.form.allows_submission, allows_submission: this.form.allows_submission,
submission_anonymous_user: this.form.submission_anonymous_user, submission_anonymous_user: this.form.submission_anonymous_user,
submission_default_status: this.form.submission_default_status, submission_default_status: this.form.submission_default_status,
submission_use_recaptcha: this.form.submission_use_recaptcha,
allow_comments: this.form.allow_comments, allow_comments: this.form.allow_comments,
hide_items_thumbnail_on_lists: this.form.hide_items_thumbnail_on_lists hide_items_thumbnail_on_lists: this.form.hide_items_thumbnail_on_lists
}; };
@ -851,6 +872,7 @@ export default {
this.form.allows_submission = this.collection.allows_submission; this.form.allows_submission = this.collection.allows_submission;
this.form.submission_anonymous_user = this.collection.submission_anonymous_user; this.form.submission_anonymous_user = this.collection.submission_anonymous_user;
this.form.submission_default_status = this.collection.submission_default_status; this.form.submission_default_status = this.collection.submission_default_status;
this.form.submission_use_recaptcha = this.collection.submission_use_recaptcha;
this.form.hide_items_thumbnail_on_lists = this.collection.hide_items_thumbnail_on_lists; this.form.hide_items_thumbnail_on_lists = this.collection.hide_items_thumbnail_on_lists;
this.isLoading = false; this.isLoading = false;
@ -908,6 +930,7 @@ export default {
this.form.allows_submission = this.collection.allows_submission; this.form.allows_submission = this.collection.allows_submission;
this.form.submission_anonymous_user = this.collection.submission_anonymous_user; this.form.submission_anonymous_user = this.collection.submission_anonymous_user;
this.form.submission_default_status = this.collection.submission_default_status; this.form.submission_default_status = this.collection.submission_default_status;
this.form.submission_use_recaptcha = this.collection.submission_use_recaptcha;
this.form.hide_items_thumbnail_on_lists = this.collection.hide_items_thumbnail_on_lists; this.form.hide_items_thumbnail_on_lists = this.collection.hide_items_thumbnail_on_lists;
// Pre-fill status with publish to incentivate it // Pre-fill status with publish to incentivate it

View File

@ -252,6 +252,7 @@ class Admin {
'repository_name' => get_bloginfo('name'), 'repository_name' => get_bloginfo('name'),
'api_max_items_per_page' => $TAINACAN_API_MAX_ITEMS_PER_PAGE, 'api_max_items_per_page' => $TAINACAN_API_MAX_ITEMS_PER_PAGE,
'wp_elasticpress' => \Tainacan\Elastic_Press::get_instance()->is_active(), 'wp_elasticpress' => \Tainacan\Elastic_Press::get_instance()->is_active(),
'item_submission_captcha_site_key' => get_option("tnc_option_recaptch_site_key")
]; ];
$maps = [ $maps = [

View File

@ -15,11 +15,13 @@ export default class CollectionModal extends React.Component {
collectionViewModes: [], collectionViewModes: [],
collectionsPerPage: 24, collectionsPerPage: 24,
collectionId: undefined, collectionId: undefined,
useCaptcha: 'no',
isLoadingCollections: false, isLoadingCollections: false,
modalCollections: [], modalCollections: [],
totalModalCollections: 0, totalModalCollections: 0,
collectionPage: 1, collectionPage: 1,
collectionOrderBy: 'date-desc', collectionOrderBy: 'date-desc',
temporaryUseCaptcha: 'no',
temporaryCollectionId: '', temporaryCollectionId: '',
temporaryCollectionDefaultViewMode: '', temporaryCollectionDefaultViewMode: '',
temporaryCollectionEnabledViewModes: [], temporaryCollectionEnabledViewModes: [],
@ -38,10 +40,12 @@ export default class CollectionModal extends React.Component {
componentWillMount() { componentWillMount() {
this.setState({ this.setState({
useCaptcha: this.props.existingUseCaptcha,
collectionId: this.props.existingCollectionId, collectionId: this.props.existingCollectionId,
temporaryCollectionId: this.props.existingCollectionId, temporaryCollectionId: this.props.existingCollectionId,
temporaryCollectionDefaultViewMode: this.props.existingCollectionDefaultViewMode, temporaryCollectionDefaultViewMode: this.props.existingCollectionDefaultViewMode,
temporaryCollectionEnabledViewModes: this.props.existingCollectionEnabledViewModes, temporaryCollectionEnabledViewModes: this.props.existingCollectionEnabledViewModes,
temporaryUseCaptcha: this.props.existingUseCaptcha,
collectionPage: 1 collectionPage: 1
}); });
@ -107,7 +111,8 @@ export default class CollectionModal extends React.Component {
name: collection.name, name: collection.name,
id: collection.id, id: collection.id,
default_view_mode: collection.default_view_mode, default_view_mode: collection.default_view_mode,
enabled_view_modes: collection.enabled_view_modes enabled_view_modes: collection.enabled_view_modes ,
submission_use_recaptcha: collection.submission_use_recaptcha
}); });
} }
@ -124,10 +129,11 @@ export default class CollectionModal extends React.Component {
}); });
} }
selectCollection({ collectionId, collectionDefaultViewMode, collectionEnabledViewModes }) { selectCollection({ collectionId, collectionDefaultViewMode, collectionEnabledViewModes, useCaptcha }) {
collectionId = collectionId; collectionId = collectionId;
this.setState({ collectionId: collectionId }); this.setState({ collectionId: collectionId });
this.props.onSelectCollection({ collectionId, collectionDefaultViewMode, collectionEnabledViewModes }); this.setState({ useCaptcha: useCaptcha });
this.props.onSelectCollection({ collectionId, collectionDefaultViewMode, collectionEnabledViewModes, useCaptcha });
} }
fetchCollections(name) { fetchCollections(name) {
@ -180,7 +186,8 @@ export default class CollectionModal extends React.Component {
name: collection.name, name: collection.name,
id: collection.id + '', id: collection.id + '',
default_view_mode: collection.default_view_mode, default_view_mode: collection.default_view_mode,
enabled_view_modes: collection.enabled_view_modes enabled_view_modes: collection.enabled_view_modes,
submission_use_recaptcha: collection.submission_use_recaptcha
})); }));
this.setState({ this.setState({
@ -198,6 +205,7 @@ export default class CollectionModal extends React.Component {
resetCollections() { resetCollections() {
this.setState({ this.setState({
useCaptcha: 'no',
collectionId: null, collectionId: null,
collectionPage: 1, collectionPage: 1,
modalCollections: [] modalCollections: []
@ -266,9 +274,11 @@ export default class CollectionModal extends React.Component {
this.state.temporaryCollectionId = aCollectionId; this.state.temporaryCollectionId = aCollectionId;
this.state.temporaryCollectionDefaultViewMode = selectedCollection.default_view_mode; this.state.temporaryCollectionDefaultViewMode = selectedCollection.default_view_mode;
this.state.temporaryCollectionEnabledViewModes = selectedCollection.enabled_view_modes; this.state.temporaryCollectionEnabledViewModes = selectedCollection.enabled_view_modes;
this.state.temporaryUseCaptcha = selectedCollection.submission_use_recaptcha;
this.setState({ temporaryCollectionId: aCollectionId }); this.setState({ temporaryCollectionId: aCollectionId });
this.setState({ temporaryCollectionDefaultViewMode: selectedCollection.default_view_mode }); this.setState({ temporaryCollectionDefaultViewMode: selectedCollection.default_view_mode });
this.setState({ temporaryCollectionEnabledViewModes: selectedCollection.enabled_view_modes }); this.setState({ temporaryCollectionEnabledViewModes: selectedCollection.enabled_view_modes });
this.setState({ temporaryUseCaptcha: selectedCollection.submission_use_recaptcha });
} } /> } } />
} }
</div> </div>
@ -298,9 +308,11 @@ export default class CollectionModal extends React.Component {
this.state.temporaryCollectionId = aCollectionId; this.state.temporaryCollectionId = aCollectionId;
this.state.temporaryCollectionDefaultViewMode = selectedCollection.default_view_mode; this.state.temporaryCollectionDefaultViewMode = selectedCollection.default_view_mode;
this.state.temporaryCollectionEnabledViewModes = selectedCollection.enabled_view_modes; this.state.temporaryCollectionEnabledViewModes = selectedCollection.enabled_view_modes;
this.state.temporaryUseCaptcha = selectedCollection.submission_use_recaptcha;
this.setState({ temporaryCollectionId: aCollectionId }); this.setState({ temporaryCollectionId: aCollectionId });
this.setState({ temporaryCollectionDefaultViewMode: selectedCollection.default_view_mode }); this.setState({ temporaryCollectionDefaultViewMode: selectedCollection.default_view_mode });
this.setState({ temporaryCollectionEnabledViewModes: selectedCollection.enabled_view_modes }); this.setState({ temporaryCollectionEnabledViewModes: selectedCollection.enabled_view_modes });
this.setState({ temporaryUseCaptcha: selectedCollection.submission_use_recaptcha });
} } /> } } />
} }
</div> </div>
@ -335,7 +347,8 @@ export default class CollectionModal extends React.Component {
onClick={ () => this.selectCollection({ onClick={ () => this.selectCollection({
collectionId: this.state.temporaryCollectionId, collectionId: this.state.temporaryCollectionId,
collectionDefaultViewMode: this.state.temporaryCollectionDefaultViewMode, collectionDefaultViewMode: this.state.temporaryCollectionDefaultViewMode,
collectionEnabledViewModes: this.state.temporaryCollectionEnabledViewModes collectionEnabledViewModes: this.state.temporaryCollectionEnabledViewModes,
useCaptcha: this.state.temporaryUseCaptcha
}) }> }) }>
{__('Use selected Collection', 'tainacan')} {__('Use selected Collection', 'tainacan')}
</Button> </Button>

View File

@ -143,6 +143,10 @@ registerBlockType('tainacan/item-submission-form', {
type: String, type: String,
default: __( 'Metadata', 'tainacan' ) default: __( 'Metadata', 'tainacan' )
}, },
useCaptcha: {
type: String,
default: 'no'
},
captchaSiteKey: { captchaSiteKey: {
type: String, type: String,
default: '' default: ''
@ -184,9 +188,13 @@ registerBlockType('tainacan/item-submission-form', {
attachmentsSectionLabel, attachmentsSectionLabel,
thumbnailSectionLabel, thumbnailSectionLabel,
metadataSectionLabel, metadataSectionLabel,
useCaptcha,
captchaSiteKey captchaSiteKey
} = attributes; } = attributes;
captchaSiteKey = tainacan_plugin['item_submission_captcha_site_key'];
setAttributes({ captchaSiteKey: captchaSiteKey });
const fontSizes = [ const fontSizes = [
{ {
name: __( 'Tiny', 'tainacan' ), name: __( 'Tiny', 'tainacan' ),
@ -765,9 +773,12 @@ registerBlockType('tainacan/item-submission-form', {
<CollectionModal <CollectionModal
filterOptionsBy={ { allows_submission: 'yes' } } filterOptionsBy={ { allows_submission: 'yes' } }
existingCollectionId={ collectionId } existingCollectionId={ collectionId }
onSelectCollection={ ({ collectionId }) => { existingUseCaptcha={ useCaptcha }
onSelectCollection={ ({ collectionId, useCaptcha }) => {
collectionId = collectionId; collectionId = collectionId;
useCaptcha = useCaptcha;
setAttributes({ setAttributes({
useCaptcha: useCaptcha,
collectionId: collectionId, collectionId: collectionId,
isCollectionModalOpen: false isCollectionModalOpen: false
}); });
@ -808,6 +819,7 @@ registerBlockType('tainacan/item-submission-form', {
enabledMetadata, enabledMetadata,
sentFormHeading, sentFormHeading,
sentFormMessage, sentFormMessage,
useCaptcha,
captchaSiteKey captchaSiteKey
} = attributes; } = attributes;
@ -844,7 +856,8 @@ registerBlockType('tainacan/item-submission-form', {
thumbnail-section-label={ thumbnailSectionLabel } thumbnail-section-label={ thumbnailSectionLabel }
attachments-section-label={ attachmentsSectionLabel } attachments-section-label={ attachmentsSectionLabel }
metadata-section-label={ metadataSectionLabel } metadata-section-label={ metadataSectionLabel }
captcha-site-key={ captchaSiteKey } > captcha-site-key={ captchaSiteKey }
use-captcha={ useCaptcha } >
</div> </div>
</div> </div>
} }

View File

@ -18,6 +18,7 @@
:thumbnail-section-label="$root.thumbnailSectionLabel" :thumbnail-section-label="$root.thumbnailSectionLabel"
:attachments-section-label="$root.attachmentsSectionLabel" :attachments-section-label="$root.attachmentsSectionLabel"
:metadata-section-label="$root.metadataSectionLabel" :metadata-section-label="$root.metadataSectionLabel"
:use-captcha="$root.useCaptcha"
:captcha-site-key="$root.captchaSiteKey" /> :captcha-site-key="$root.captchaSiteKey" />
</template> </template>

View File

@ -115,6 +115,7 @@ document.addEventListener("DOMContentLoaded", () => {
thumbnailSectionLabel: '', thumbnailSectionLabel: '',
attachmentsSectionLabel: '', attachmentsSectionLabel: '',
metadataSectionLabel: '', metadataSectionLabel: '',
useCaptcha: 'no',
captchaSiteKey: '' captchaSiteKey: ''
}, },
beforeMount () { beforeMount () {
@ -163,6 +164,8 @@ document.addEventListener("DOMContentLoaded", () => {
this.enabledMetadata = this.$el.attributes['enabled-metadata'].value.split(','); this.enabledMetadata = this.$el.attributes['enabled-metadata'].value.split(',');
// Captcha // Captcha
if (this.$el.attributes['use-captcha'] != undefined)
this.useCaptcha = this.$el.attributes['use-captcha'].value;
if (this.$el.attributes['captcha-site-key'] != undefined) if (this.$el.attributes['captcha-site-key'] != undefined)
this.captchaSiteKey = this.$el.attributes['captcha-site-key'].value; this.captchaSiteKey = this.$el.attributes['captcha-site-key'].value;

View File

@ -321,7 +321,7 @@
</template> </template>
<!-- Google ReCAPTCHA --> <!-- Google ReCAPTCHA -->
<template v-if="captchaSiteKey"> <template v-if="useCaptcha == 'yes'">
<div <div
class="g-recaptcha" class="g-recaptcha"
:data-sitekey="captchaSiteKey" /> :data-sitekey="captchaSiteKey" />
@ -422,6 +422,7 @@ export default {
thumbnailSectionLabel: String, thumbnailSectionLabel: String,
attachmentsSectionLabel: String, attachmentsSectionLabel: String,
metadataSectionLabel: String, metadataSectionLabel: String,
useCaptcha: String,
captchaSiteKey: String captchaSiteKey: String
}, },
data(){ data(){