Skip to content

Commit 7d41eea

Browse files
author
FrancescoMauto
committed
[DSC-1786] [DSC-1786] fix captcha cookie old ref to klaro, fix missing subscribe + minor refactor
Porting of [CST-26767]
1 parent 7290e0b commit 7d41eea

6 files changed

Lines changed: 24 additions & 12 deletions

File tree

src/app/core/google-recaptcha/google-recaptcha-base.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { CookieService } from '../services/cookie.service';
1515
import { isNotEmpty } from './../../shared/empty.util';
1616
import { NotificationsService } from './../../shared/notifications/notifications.service';
1717
import {
18-
CAPTCHA_NAME,
18+
CAPTCHA_FEEDBACK_NAME,
1919
GoogleRecaptchaService,
2020
} from './google-recaptcha.service';
2121

@@ -81,7 +81,7 @@ export abstract class GoogleRecaptchaBaseComponent {
8181
isRecaptchaCookieAccepted(): boolean {
8282
const orejimeAnonymousCookie = this.cookieService.get('orejime-anonymous');
8383
return isNotEmpty(orejimeAnonymousCookie)
84-
? orejimeAnonymousCookie[CAPTCHA_NAME]
84+
? orejimeAnonymousCookie[CAPTCHA_FEEDBACK_NAME]
8585
: false;
8686
}
8787

src/app/core/google-recaptcha/google-recaptcha.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { getFirstCompletedRemoteData } from '../shared/operators';
3333
export const CAPTCHA_COOKIE = '_GRECAPTCHA';
3434
export const CAPTCHA_REGISTRATION_NAME = 'google-recaptcha-registration';
3535

36-
export const CAPTCHA_NAME = 'google-recaptcha';
36+
export const CAPTCHA_FEEDBACK_NAME = 'google-recaptcha';
3737

3838
/**
3939
* A GoogleRecaptchaService used to send action and get a token from REST
@@ -109,7 +109,7 @@ export class GoogleRecaptchaService {
109109
if (
110110
this.cookieService.get('klaro-anonymous') && (
111111
this.cookieService.get('klaro-anonymous')[CAPTCHA_REGISTRATION_NAME] ||
112-
this.cookieService.get('klaro-anonymous')[CAPTCHA_NAME]
112+
this.cookieService.get('klaro-anonymous')[CAPTCHA_FEEDBACK_NAME]
113113
) &&
114114
recaptchaKeyRD.hasSucceeded && recaptchaVersionRD.hasSucceeded &&
115115
isNotEmpty(recaptchaVersionRD.payload?.values) && isNotEmpty(recaptchaKeyRD.payload?.values)

src/app/info/feedback/feedback-form/feedback-form.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ <h1>{{ 'info.feedback.head' | translate }}</h1>
5959
}
6060
</fieldset>
6161

62-
@if (submissionVerification && !isRecaptchaCookieAccepted()) {
62+
@let captchaCookieAccepted = isRecaptchaCookieAccepted();
63+
@if (submissionVerification && !captchaCookieAccepted) {
6364
<ds-alert [type]="AlertTypeEnum.Warning">
6465
<p class="m-0" [innerHTML]="MESSAGE_PREFIX + '.google-recaptcha.must-accept-cookies' | translate"></p>
6566
<p class="m-0"><a href="javascript:void(0);" (click)="openCookieSettings()">{{ MESSAGE_PREFIX + '.google-recaptcha.open-cookie-settings' | translate }}</a></p>
6667
</ds-alert>
6768
}
68-
69-
@if (isRecaptchaCookieAccepted() && (captchaVersion() | async) === 'v2') {
69+
@if (captchaCookieAccepted && (googleRecaptchaService.captchaVersion() | async) === 'v2') {
7070
<div class="my-3">
7171
<ds-google-recaptcha [captchaMode]="(captchaMode() | async)"
7272
(executeRecaptcha)="submitFeedback($event)" (checkboxChecked)="onCheckboxChecked($event)"
@@ -79,7 +79,7 @@ <h1>{{ 'info.feedback.head' | translate }}</h1>
7979
<div class="control-group col-sm-12 text-end">
8080
@if (!((captchaVersion() | async) === 'v2' && (captchaMode() | async) === 'invisible')) {
8181
<button class="btn btn-primary"
82-
[dsBtnDisabled]="feedbackForm.invalid || submissionVerification && !isRecaptchaCookieAccepted() || disableUntilChecked"
82+
[dsBtnDisabled]="feedbackForm.invalid || submissionVerification && !captchaCookieAccepted || disableUntilChecked"
8383
(click)="submitFeedback()">
8484
{{ 'info.feedback.send' | translate }}
8585
</button>

src/app/info/feedback/feedback-form/feedback-form.component.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import { ConfigurationDataService } from '../../../core/data/configuration-data.
5757
import { CookieService } from '../../../core/services/cookie.service';
5858
import { isNotEmpty } from '../../../shared/empty.util';
5959
import { KlaroService } from 'src/app/shared/cookies/klaro.service';
60+
import { ConfigurationProperty } from 'src/app/core/shared/configuration-property.model';
6061

6162
@Component({
6263
selector: 'ds-base-feedback-form',
@@ -113,6 +114,17 @@ export class FeedbackFormComponent extends GoogleRecaptchaBaseComponent implemen
113114
@Optional() public klaroService: KlaroService,
114115
) {
115116
super(googleRecaptchaService, cookieService, notificationsService, translate);
117+
118+
this.subscriptions.push(
119+
this.configService.findByPropertyName('feedback.verification.enabled').pipe(
120+
getFirstSucceededRemoteDataPayload(),
121+
map((res: ConfigurationProperty) => res?.values[0].toLowerCase() === 'true'),
122+
).subscribe((res: boolean) => {
123+
this.submissionVerification = res;
124+
if (res) {
125+
this.googleRecaptchaService.loadRecaptchaProperties().subscribe();
126+
}
127+
}));
116128
}
117129

118130
/**

src/app/register-email-form/register-email-form.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { ConfigurationDataService } from '../core/data/configuration-data.servic
4242
import { EpersonRegistrationService } from '../core/data/eperson-registration.service';
4343
import { RemoteData } from '../core/data/remote-data';
4444
import {
45-
CAPTCHA_NAME,
45+
CAPTCHA_FEEDBACK_NAME,
4646
GoogleRecaptchaService,
4747
} from '../core/google-recaptcha/google-recaptcha.service';
4848
import { CookieService } from '../core/services/cookie.service';
@@ -247,7 +247,7 @@ export class RegisterEmailFormComponent implements OnDestroy, OnInit {
247247
*/
248248
isRecaptchaCookieAccepted(): boolean {
249249
const klaroAnonymousCookie = this.cookieService.get('klaro-anonymous');
250-
return isNotEmpty(klaroAnonymousCookie) ? klaroAnonymousCookie[CAPTCHA_NAME] : false;
250+
return isNotEmpty(klaroAnonymousCookie) ? klaroAnonymousCookie[CAPTCHA_FEEDBACK_NAME] : false;
251251
}
252252

253253
/**

src/app/shared/cookies/browser-klaro.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { AuthService } from '../../core/auth/auth.service';
2929
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
3030
import { EPersonDataService } from '../../core/eperson/eperson-data.service';
3131
import { EPerson } from '../../core/eperson/models/eperson.model';
32-
import { CAPTCHA_NAME } from '../../core/google-recaptcha/google-recaptcha.service';
32+
import { CAPTCHA_FEEDBACK_NAME } from '../../core/google-recaptcha/google-recaptcha.service';
3333
import { CookieService } from '../../core/services/cookie.service';
3434
import {
3535
NativeWindowRef,
@@ -210,7 +210,7 @@ export class BrowserKlaroService extends KlaroService {
210210
servicesToHideArray.push(this.GOOGLE_ANALYTICS_SERVICE_NAME);
211211
}
212212
if (hideRegistrationVerification && hideFeedbackVerification) {
213-
servicesToHideArray.push(CAPTCHA_NAME);
213+
servicesToHideArray.push(CAPTCHA_FEEDBACK_NAME);
214214
}
215215
if (hideMatomo) {
216216
servicesToHideArray.push(MATOMO_KLARO_KEY);

0 commit comments

Comments
 (0)