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

feat: limit custom feed view from date #2557

Merged
merged 3 commits into from
Dec 20, 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
22 changes: 22 additions & 0 deletions __tests__/boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import { DEFAULT_TIMEZONE, submitArticleThreshold } from '../src/common';
import { saveReturnAlerts } from '../src/schema/alerts';
import { UserVote } from '../src/types';
import { BootAlerts, excludeProperties } from '../src/routes/boot';
import { SubscriptionCycles } from '../src/paddle';

let app: FastifyInstance;
let con: DataSource;
Expand Down Expand Up @@ -511,6 +512,9 @@ describe('logged in boot', () => {
});
await con.getRepository(User).save({
...usersFixture[0],
subscriptionFlags: {
cycle: SubscriptionCycles.Yearly,
},
defaultFeedId: '1',
});
mockLoggedIn();
Expand All @@ -520,6 +524,24 @@ describe('logged in boot', () => {
.expect(200);
expect(res.body.user.defaultFeedId).toEqual('1');
});

it('should not return default feed id if not plus', async () => {
await con.getRepository(Feed).save({
id: '1',
name: 'My Feed',
userId: '1',
});
await con.getRepository(User).save({
...usersFixture[0],
defaultFeedId: '1',
});
mockLoggedIn();
const res = await request(app.server)
.get(BASE_PATH)
.set('Cookie', 'ory_kratos_session=value;')
.expect(200);
expect(res.body.user.defaultFeedId).toBeNull();
});
});

describe('boot marketing cta', () => {
Expand Down
23 changes: 23 additions & 0 deletions __tests__/feeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4339,6 +4339,8 @@ describe('query customFeed', () => {

it('should return the feed by slug', async () => {
loggedUser = '1';
isPlus = true;

const res = await client.query(QUERY, {
variables: {
ranking: Ranking.POPULARITY,
Expand Down Expand Up @@ -4379,6 +4381,7 @@ describe('query customFeed', () => {

it('should return feed with preconfigured filters', async () => {
loggedUser = '1';
isPlus = true;

const res = await client.query(QUERY, {
variables: {
Expand All @@ -4396,6 +4399,8 @@ describe('query customFeed', () => {

it('should not return posts with blocked tags', async () => {
loggedUser = '1';
isPlus = true;

await con.getRepository(ContentPreferenceKeyword).save([
{
feedId: 'cf1',
Expand Down Expand Up @@ -4423,6 +4428,7 @@ describe('query customFeed', () => {

it('should return v2 feed', async () => {
loggedUser = '1';
isPlus = true;

nock('http://localhost:6000')
.post('/feed.json', {
Expand Down Expand Up @@ -4452,4 +4458,21 @@ describe('query customFeed', () => {
['p1', 'p4'],
);
});

it('should not return the feed by slug if not plus', async () => {
loggedUser = '1';

await testQueryErrorCode(
client,
{
query: QUERY,
variables: {
ranking: Ranking.POPULARITY,
first: 10,
feedId: 'cool-feed-cf1',
},
},
'FORBIDDEN',
);
});
});
2 changes: 2 additions & 0 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export const ONE_DAY_IN_SECONDS = ONE_HOUR_IN_SECONDS * 24;
export const ONE_WEEK_IN_SECONDS = ONE_DAY_IN_SECONDS * 7;

export const MAX_FOLLOWERS_LIMIT = 5_000;

export const customFeedsPlusDate = new Date('2024-12-11');
1 change: 1 addition & 0 deletions src/routes/boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ const loggedInBoot = async ({
language: user.language || undefined,
image: mapCloudinaryUrl(user.image),
cover: mapCloudinaryUrl(user.cover),
defaultFeedId: isPlus ? user.defaultFeedId : null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we return the my-feed id (userId) or basically wouldn't really matter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null is default when you don't have anything set, frontend expects it as well

},
visit,
alerts: {
Expand Down
7 changes: 7 additions & 0 deletions src/schema/feeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
applyFeedWhere,
base64,
configuredFeedBuilder,
customFeedsPlusDate,
FeedArgs,
feedResolver,
feedToFilters,
Expand Down Expand Up @@ -1492,6 +1493,12 @@ export const resolvers: IResolvers<unknown, BaseContext> = traceResolvers<
});
const feedId = feed.id;

if (feed.createdAt > customFeedsPlusDate && !ctx.isPlus) {
throw new ForbiddenError(
'Access denied! You need to be authorized to perform this action!',
);
}

if (
args.version >= 2 &&
args.ranking === Ranking.POPULARITY &&
Expand Down
Loading