Skip to content

Commit abb76a7

Browse files
authored
Merge pull request #13862 from guardian/ph20250429-0719-deny
deny /tips from being gated
2 parents dc1c7ec + cae2d9e commit abb76a7

13 files changed

+216
-132
lines changed

dotcom-rendering/README.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,44 @@ Frontend rendering framework for theguardian.com. It uses [React](https://reactj
66

77
This guide will help you get the `dotcom-rendering` application running on your development machine.
88

9+
To download the repository
10+
11+
```
12+
$ git clone [email protected]:guardian/dotcom-rendering.git
13+
$ cd dotcom-rendering
14+
```
15+
916
### Install Node.js
1017

11-
The only thing you need to make sure you have installed before you get going is [Node.js](https://nodejs.org).
18+
Make sure you have [Node.js](https://nodejs.org) installed.
1219

13-
We recommend using [fnm](https://github.com/Schniz/fnm) to help manage multiple versions of Node.js on on machine.
20+
We recommend using [fnm](https://github.com/Schniz/fnm) to help manage multiple versions of Node.js on one machine.
1421

1522
Once Node is installed, make sure you're using the correct package manager by [enabling corepack](https://github.com/nodejs/corepack?tab=readme-ov-file#utility-commands):
1623

1724
```sh
1825
$ corepack enable
1926
```
2027

21-
> [!NOTE]
22-
>
23-
> If you're using `asdf`, you'll need to run `asdf reshim nodejs` after running `corepack enable`.
28+
If you're using `asdf`, you'll need to run `asdf reshim nodejs` after running `corepack enable`.
29+
30+
### Install Dependencies
2431

25-
### Running instructions
32+
run
33+
34+
```
35+
$ make install
36+
```
37+
38+
If it complains that you do not have the right version of node, then run (or replace with the correct version manager or the correct version):
39+
40+
```
41+
$ fnm install 22.14.0
42+
```
43+
44+
### Running on local
2645

2746
```sh
28-
$ git clone [email protected]:guardian/dotcom-rendering.git
29-
$ cd dotcom-rendering
3047
$ make dev
3148
```
3249

@@ -44,7 +61,7 @@ http://localhost:3030/ArticleJson?url=https://www.theguardian.com/sport/2019/jul
4461

4562
If you're new to TypeScript projects, if you're trying to integrate with other applications or if you prefer to take things slow, we also have a more [detailed setup guide](docs/contributing/detailed-setup-guide.md).
4663

47-
### Technologies
64+
## Technologies
4865

4966
| Technology | Description |
5067
| -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

dotcom-rendering/docs/contributing/detailed-setup-guide.md

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,44 @@ This high level diagram shows the difference between the data flow when DCR is u
88

99
## Developing
1010

11-
### Setup
11+
## Getting started
1212

13-
The only thing you need to make sure you have installed before you get going is Node.
13+
To download the repository
1414

15-
#### Node.js
15+
```
16+
$ git clone [email protected]:guardian/dotcom-rendering.git
17+
$ cd dotcom-rendering
18+
```
19+
20+
### Node.js
21+
22+
Make sure you have [Node.js](https://nodejs.org) installed.
1623

1724
We recommend using [fnm](https://github.com/Schniz/fnm) to help manage multiple versions of Node.js on on machine.
1825

19-
### Start
26+
### Install Dependencies
27+
28+
run
29+
30+
```
31+
$ make install
32+
```
33+
34+
If it complains that you do not have the right version of node, then run (or replace with the correct version manager or the correct version):
35+
36+
```
37+
$ fnm install 22.14.0
38+
```
2039

21-
Start the development server:
40+
### Running on local
2241

2342
```sh
24-
make dev
43+
$ make dev
2544
```
2645

2746
This will start the development server on port 3030: [http://localhost:3030](http://localhost:3030).
2847

29-
> Note: To run the development server with support for legacy browsers, use `make dev-legacy`
48+
Note: To run the development server with support for legacy browsers, use `make dev-legacy`
3049

3150
### Previewing article on local
3251

dotcom-rendering/src/components/SignInGate/displayRule.test.ts

Lines changed: 0 additions & 108 deletions
This file was deleted.
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import { incrementDailyArticleCount } from '../../lib/dailyArticleCount';
2+
import {
3+
isNPageOrHigherPageView,
4+
isValidContentType,
5+
isValidSection,
6+
isValidTag,
7+
pageIdIsAllowedForGating,
8+
} from './displayRules';
9+
10+
describe('isNPageOrHigherPageView', () => {
11+
beforeEach(() => {
12+
localStorage.clear();
13+
});
14+
15+
test('default - checks for is 2 article views returns true', () => {
16+
incrementDailyArticleCount();
17+
incrementDailyArticleCount();
18+
19+
const output = isNPageOrHigherPageView();
20+
21+
expect(output).toBe(true);
22+
});
23+
24+
test('default - checks for higher 2 article views returns true', () => {
25+
incrementDailyArticleCount();
26+
incrementDailyArticleCount();
27+
incrementDailyArticleCount();
28+
29+
const output = isNPageOrHigherPageView();
30+
31+
expect(output).toBe(true);
32+
});
33+
34+
test('default - checks for lower than 2 article views returns false', () => {
35+
incrementDailyArticleCount();
36+
37+
const output = isNPageOrHigherPageView();
38+
39+
expect(output).toBe(false);
40+
});
41+
42+
test('default - checks for is n = 3 article views returns true', () => {
43+
incrementDailyArticleCount();
44+
incrementDailyArticleCount();
45+
incrementDailyArticleCount();
46+
47+
const output = isNPageOrHigherPageView(3);
48+
49+
expect(output).toBe(true);
50+
});
51+
52+
test('default - checks for is n = 5 article views returns false', () => {
53+
incrementDailyArticleCount();
54+
incrementDailyArticleCount();
55+
incrementDailyArticleCount();
56+
57+
const output = isNPageOrHigherPageView(5);
58+
59+
expect(output).toBe(false);
60+
});
61+
});
62+
63+
describe('isValidContentType', () => {
64+
test('is a valid type - article', () => {
65+
expect(isValidContentType('Article')).toBe(true);
66+
});
67+
68+
test('is not a valid type - LiveBlog', () => {
69+
expect(isValidContentType('LiveBlog')).toBe(false);
70+
});
71+
});
72+
73+
describe('isValidSection', () => {
74+
test('is valid section - politics - returns true', () => {
75+
expect(isValidSection('politics')).toBe(true);
76+
});
77+
78+
test('is valid section - membership - return false', () => {
79+
expect(isValidSection('membership')).toBe(false);
80+
});
81+
});
82+
83+
describe('isValidTag', () => {
84+
test('is valid tag - us-news/us-news - returns true', () => {
85+
expect(
86+
isValidTag([
87+
{
88+
id: 'us-news/us-news',
89+
type: 'Keyword',
90+
title: 'US news',
91+
},
92+
]),
93+
).toBe(true);
94+
});
95+
96+
test('is valid tag - info/newsletter-sign-up - return false', () => {
97+
expect(
98+
isValidTag([
99+
{
100+
id: 'info/newsletter-sign-up',
101+
type: 'Keyword',
102+
title: 'Newsletters',
103+
},
104+
]),
105+
).toBe(false);
106+
});
107+
});
108+
109+
describe('articleIdentifierIsAllowed', () => {
110+
expect(
111+
pageIdIsAllowedForGating(
112+
'money/2017/mar/10/ministers-to-criminalise-use-of-ticket-tout-harvesting-software',
113+
),
114+
).toBe(true);
115+
expect(pageIdIsAllowedForGating('tips')).toBe(false);
116+
expect(pageIdIsAllowedForGating('tips#test')).toBe(false);
117+
expect(pageIdIsAllowedForGating('tips/test')).toBe(false);
118+
});

dotcom-rendering/src/components/SignInGate/displayRule.ts renamed to dotcom-rendering/src/components/SignInGate/displayRules.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,35 @@ export const canShowSignInGateWithOffers = ({
153153
// hide the sign in gate for AU and US readers
154154
!['AU', ...US_REGION_CODES].includes(currentLocaleCode),
155155
);
156+
157+
/*
158+
Date: 29th April 2025
159+
160+
We have a request to prevent sign-in gate for a specific URL. This feels like an
161+
adhoc request and not a new general feature to implement.
162+
163+
We have a check in SDC: https://github.com/guardian/support-dotcom-components/pull/1345 ,
164+
to prevent the Auxia gate from showing, but we also need to prevent the legacy gate from
165+
showing. For a cleaner implementation. we are simply going to prevent any of the two
166+
gates components from rendering.
167+
168+
To keep things simple, we are going to add a check in SignInGateSelector, which seems
169+
like a good place.
170+
*/
171+
172+
export const pageIdIsAllowedForGating = (pageId: string): boolean => {
173+
// This function was introduced to handle the specific request of not showing a gate for
174+
// this url: https://www.theguardian.com/tips
175+
176+
// pageId is the path without the starting slash
177+
// example:
178+
// - full url: https://www.theguardian.com/world/2025/apr/29/canada-election-result-liberal-win-mark-carney-anti-trump
179+
// - pageId: world/2025/apr/29/canada-election-result-liberal-win-mark-carney-anti-trump
180+
181+
const denyPaths = [
182+
'tips',
183+
'help/ng-interactive/2017/mar/17/contact-the-guardian-securely',
184+
];
185+
186+
return !denyPaths.some((denyPath) => pageId.startsWith(denyPath));
187+
};

dotcom-rendering/src/components/SignInGate/gates/alternative-wording-control.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { startPerformanceMeasure } from '@guardian/libs';
22
import React, { Suspense } from 'react';
33
import { Lazy } from '../../Lazy';
4-
import { canShowSignInGateWithOffers } from '../displayRule';
4+
import { canShowSignInGateWithOffers } from '../displayRules';
55
import type { SignInGateComponent } from '../types';
66

77
const SignInGateMain = React.lazy(() => {

dotcom-rendering/src/components/SignInGate/gates/alternative-wording-guardian-live.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { startPerformanceMeasure } from '@guardian/libs';
22
import React, { Suspense } from 'react';
33
import { Lazy } from '../../Lazy';
4-
import { canShowSignInGateWithOffers } from '../displayRule';
4+
import { canShowSignInGateWithOffers } from '../displayRules';
55
import type { SignInGateComponent } from '../types';
66

77
const SignInGateCustomizableText = React.lazy(() => {

0 commit comments

Comments
 (0)