Skip to content

Commit b580331

Browse files
authored
chore: remove premium notation (#2529)
1 parent e1439e7 commit b580331

17 files changed

+23
-80
lines changed

__tests__/bookmarks.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ let con: DataSource;
3232
let state: GraphQLTestingState;
3333
let client: GraphQLTestClient;
3434
let loggedUser: string;
35-
let premiumUser: boolean;
3635
let isPlus: boolean;
3736

3837
const now = new Date();
@@ -57,8 +56,7 @@ const bookmarksFixture = [
5756
beforeAll(async () => {
5857
con = await createOrGetConnection();
5958
state = await initializeGraphQLTesting(
60-
(req) =>
61-
new MockContext(con, loggedUser, premiumUser, [], req, false, isPlus),
59+
(req) => new MockContext(con, loggedUser, [], req, false, isPlus),
6260
);
6361
client = state.client;
6462
});
@@ -532,7 +530,6 @@ describe('mutation moveBookmark', () => {
532530

533531
it('should update existing bookmark', async () => {
534532
loggedUser = '1';
535-
premiumUser = true;
536533
const list = await con
537534
.getRepository(BookmarkList)
538535
.save({ userId: loggedUser, name: 'list' });
@@ -552,7 +549,6 @@ describe('mutation moveBookmark', () => {
552549

553550
it('should set list id to null', async () => {
554551
loggedUser = '1';
555-
premiumUser = true;
556552
const list = await con
557553
.getRepository(BookmarkList)
558554
.save({ userId: loggedUser, name: 'list' });
@@ -809,7 +805,6 @@ describe('query bookmarks', () => {
809805

810806
it('should return bookmarks from list', async () => {
811807
loggedUser = '1';
812-
premiumUser = true;
813808
const list = await con
814809
.getRepository(BookmarkList)
815810
.save({ userId: loggedUser, name: 'list' });

__tests__/feeds.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ describe('query feedByIds', () => {
11071107
it('should return feed by ids for team member', async () => {
11081108
loggedUser = '1';
11091109
state = await initializeGraphQLTesting(
1110-
(req) => new MockContext(con, loggedUser, false, [], req, true),
1110+
(req) => new MockContext(con, loggedUser, [], req, true),
11111111
);
11121112

11131113
const res = await state.client.query(QUERY, {

__tests__/helpers.ts

-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import { logger } from '../src/logger';
3535
export class MockContext extends Context {
3636
mockSpan: MockProxy<opentelemetry.Span> & opentelemetry.Span;
3737
mockUserId: string | null;
38-
mockPremium: boolean;
3938
mockRoles: Roles[];
4039
mockIsTeamMember: boolean;
4140
mockIsPlus: boolean;
@@ -45,7 +44,6 @@ export class MockContext extends Context {
4544
constructor(
4645
con: DataSource,
4746
userId: string | null = null,
48-
premium = false,
4947
roles = [],
5048
req?: FastifyRequest,
5149
isTeamMember = false,
@@ -57,7 +55,6 @@ export class MockContext extends Context {
5755
mock<opentelemetry.Span>(),
5856
);
5957
this.mockUserId = userId;
60-
this.mockPremium = premium;
6158
this.mockRoles = roles;
6259
this.mockIsTeamMember = isTeamMember;
6360
this.mockIsPlus = isPlus;
@@ -80,10 +77,6 @@ export class MockContext extends Context {
8077
return this.mockUserId;
8178
}
8279

83-
get premium(): boolean | null {
84-
return this.mockPremium;
85-
}
86-
8780
get isTeamMember(): boolean {
8881
return this.mockIsTeamMember;
8982
}

__tests__/keywords.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let roles: Roles[] = [];
2727
beforeAll(async () => {
2828
con = await createOrGetConnection();
2929
state = await initializeGraphQLTesting(
30-
() => new MockContext(con, loggedUser, false, roles),
30+
() => new MockContext(con, loggedUser, roles),
3131
);
3232
client = state.client;
3333
});

__tests__/leaderboard.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let loggedUser: string | null = null;
3030
beforeAll(async () => {
3131
con = await createOrGetConnection();
3232
state = await initializeGraphQLTesting(
33-
() => new MockContext(con, loggedUser, false, []),
33+
() => new MockContext(con, loggedUser, []),
3434
);
3535
client = state.client;
3636
});

__tests__/posts.ts

+1-13
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,14 @@ let con: DataSource;
9797
let state: GraphQLTestingState;
9898
let client: GraphQLTestClient;
9999
let loggedUser: string = null;
100-
let premiumUser = false;
101100
let isTeamMember = false;
102101
let isPlus = false;
103102
let roles: Roles[] = [];
104103

105104
beforeAll(async () => {
106105
con = await createOrGetConnection();
107106
state = await initializeGraphQLTesting(
108-
(req) =>
109-
new MockContext(
110-
con,
111-
loggedUser,
112-
premiumUser,
113-
roles,
114-
req,
115-
isTeamMember,
116-
isPlus,
117-
),
107+
(req) => new MockContext(con, loggedUser, roles, req, isTeamMember, isPlus),
118108
);
119109
client = state.client;
120110
});
@@ -123,7 +113,6 @@ beforeEach(async () => {
123113
loggedUser = null;
124114
isTeamMember = false;
125115
isPlus = false;
126-
premiumUser = false;
127116
roles = [];
128117
jest.clearAllMocks();
129118
await ioRedisPool.execute((client) => client.flushall());
@@ -524,7 +513,6 @@ describe('bookmarkList field', () => {
524513

525514
it('should return null when bookmark does not belong to a list', async () => {
526515
loggedUser = '1';
527-
premiumUser = true;
528516
await con.getRepository(Bookmark).save({
529517
postId: 'p1',
530518
userId: loggedUser,

__tests__/publicSquadRequests.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const testModeratorAuthorization = (mutation: Mutation): Promise<void> => {
4242
beforeAll(async () => {
4343
con = await createOrGetConnection();
4444
state = await initializeGraphQLTesting(
45-
() => new MockContext(con, loggedUser, false, roles),
45+
() => new MockContext(con, loggedUser, roles),
4646
);
4747
client = state.client;
4848
});

__tests__/rss.ts

-8
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,6 @@ describe('GET /rss/b/:slug', () => {
154154
// return request(app.server).get(path(list.id)).expect(403);
155155
// });
156156
//
157-
// it('should fail when user is not premium', () => {
158-
// mockUser(false);
159-
// return request(app.server).get(path(list.id)).expect(403);
160-
// });
161157
//
162158
// it('should fail when list does not exist', () => {
163159
// mockUser();
@@ -189,10 +185,6 @@ describe('GET /rss/b/:slug', () => {
189185
// return request(app.server).get(path).expect(403);
190186
// });
191187
//
192-
// it('should fail when user is not premium', () => {
193-
// mockUser(false);
194-
// return request(app.server).get(path).expect(403);
195-
// });
196188
//
197189
// it('should fail when feed does not exist', () => {
198190
// mockUser();

__tests__/sourceRequests.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const testNotFound = (mutation: Mutation): Promise<void> => {
5555
beforeAll(async () => {
5656
con = await createOrGetConnection();
5757
state = await initializeGraphQLTesting(
58-
() => new MockContext(con, loggedUser, false, roles),
58+
() => new MockContext(con, loggedUser, roles),
5959
);
6060
client = state.client;
6161
app = state.app;

__tests__/sources.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ let con: DataSource;
5454
let state: GraphQLTestingState;
5555
let client: GraphQLTestClient;
5656
let loggedUser: string = null;
57-
let premiumUser: boolean;
5857

5958
beforeAll(async () => {
6059
con = await createOrGetConnection();
6160
state = await initializeGraphQLTesting(
62-
() => new MockContext(con, loggedUser, premiumUser),
61+
() => new MockContext(con, loggedUser),
6362
);
6463
client = state.client;
6564
});
@@ -113,7 +112,6 @@ const getSourceCategories = () => [
113112

114113
beforeEach(async () => {
115114
loggedUser = null;
116-
premiumUser = false;
117115
await saveFixtures(con, SourceCategory, getSourceCategories());
118116
await saveFixtures(con, Source, [
119117
sourcesFixture[0],

__tests__/submissions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ describe('mutation submitArticle', () => {
226226
it('should not invalidate if the user has reached limit but is team member', async () => {
227227
loggedUser = '1';
228228
state = await initializeGraphQLTesting(
229-
(req) => new MockContext(con, loggedUser, false, [], req, true),
229+
(req) => new MockContext(con, loggedUser, [], req, true),
230230
);
231231
const request = 'https://abc.com/article';
232232
const repo = con.getRepository(Submission);

__tests__/workers/completedUserActions.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,18 @@
3131
// let state: GraphQLTestingState;
3232
// let client: GraphQLTestClient;
3333
// let loggedUser: string | null = null;
34-
// let premiumUser = false;
3534
// let roles: Roles[] = [];
3635
//
3736
// beforeAll(async () => {
3837
// con = await createOrGetConnection();
3938
// state = await initializeGraphQLTesting(
40-
// () => new MockContext(con, loggedUser, premiumUser, roles),
39+
// () => new MockContext(con, loggedUser, roles),
4140
// );
4241
// client = state.client;
4342
// });
4443
//
4544
// beforeEach(async () => {
4645
// loggedUser = null;
47-
// premiumUser = false;
4846
// roles = [];
4947
// jest.clearAllMocks();
5048
//

src/Context.ts

-4
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ export class Context {
5050
return !!this.req.isTeamMember;
5151
}
5252

53-
get premium(): boolean {
54-
return !!this.req.premium;
55-
}
56-
5753
get roles(): Roles[] {
5854
return this.req.roles ?? [];
5955
}

src/auth.ts

-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ interface Options {
1616

1717
interface AuthPayload {
1818
userId: string;
19-
premium: boolean;
2019
roles?: Roles[];
2120
isTeamMember?: boolean;
2221
isPlus?: boolean;
@@ -89,7 +88,6 @@ const plugin = async (
8988
}
9089

9190
fastify.decorateRequest('userId');
92-
fastify.decorateRequest('premium');
9391
fastify.decorateRequest('roles');
9492
fastify.decorateRequest('accessToken');
9593
fastify.decorateRequest('isTeamMember');
@@ -104,7 +102,6 @@ const plugin = async (
104102
req.service = true;
105103
if (req.headers['user-id'] && req.headers['logged-in'] === 'true') {
106104
req.userId = req.headers['user-id'] as string;
107-
req.premium = req.headers.premium === 'true';
108105
req.isPlus = req.headers['is-plus'] === 'true';
109106
req.roles =
110107
((req.headers['roles'] as string)?.split(',') as Roles[]) ?? [];
@@ -123,7 +120,6 @@ const plugin = async (
123120
const payload = await verifyJwt(validValue);
124121
if (payload) {
125122
req.userId = payload.userId;
126-
req.premium = payload.premium;
127123
req.roles = payload.roles;
128124
req.isTeamMember = payload.isTeamMember;
129125
req.isPlus = !!payload.isPlus;

src/common/users.ts

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export interface User {
2727
name: string;
2828
image?: string | null;
2929
infoConfirmed: boolean;
30-
premium?: boolean;
3130
reputation: number;
3231
permalink: string;
3332
username?: string;

src/directive/auth.ts

+13-24
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,19 @@ import { Context } from '../Context';
77
const directiveName = 'auth';
88

99
export const typeDefs = /* GraphQL */ `
10-
directive @${directiveName}(
10+
directive @${directiveName}(
1111
"""
1212
Roles required for the operation (at least one)
1313
"""
1414
requires: [Role] = []
15+
) on OBJECT | FIELD_DEFINITION
1516
16-
"""
17-
Whether premium subscription is required
18-
"""
19-
premium: Boolean = false
20-
) on OBJECT | FIELD_DEFINITION
21-
22-
enum Role {
17+
enum Role {
2318
MODERATOR
24-
}
19+
}
2520
`;
2621

27-
const typeDirectiveArgumentMaps: { requires?: string[]; premium?: boolean } =
28-
{};
22+
const typeDirectiveArgumentMaps: { requires?: string[] } = {};
2923

3024
export const transformer = (schema: GraphQLSchema): GraphQLSchema =>
3125
mapSchema(schema, {
@@ -43,11 +37,11 @@ export const transformer = (schema: GraphQLSchema): GraphQLSchema =>
4337
// @ts-expect-error - internal mapping
4438
typeDirectiveArgumentMaps[typeName];
4539
if (args) {
46-
const { requires, premium } = args;
40+
const { requires } = args;
4741
if (requires) {
4842
const { resolve = defaultFieldResolver } = fieldConfig;
4943
fieldConfig.resolve = function (source, args, ctx: Context, info) {
50-
if (!requires && !premium) {
44+
if (!requires) {
5145
return resolve(source, args, ctx, info);
5246
}
5347
if (!ctx.userId) {
@@ -60,17 +54,12 @@ export const transformer = (schema: GraphQLSchema): GraphQLSchema =>
6054
resolve(source, args, ctx, info);
6155
return null;
6256
}
63-
if (requires.length > 0 || premium) {
64-
let authorized: boolean;
65-
if (premium) {
66-
authorized = ctx.premium;
67-
} else {
68-
const roles = ctx.roles;
69-
authorized =
70-
roles.findIndex(
71-
(r) => requires.indexOf(r.toUpperCase()) > -1,
72-
) > -1;
73-
}
57+
if (requires.length > 0) {
58+
const roles = ctx.roles;
59+
const authorized =
60+
roles.findIndex((r) => requires.indexOf(r.toUpperCase()) > -1) >
61+
-1;
62+
7463
if (!authorized) {
7564
if (['Query', 'Mutation'].includes(typeName)) {
7665
throw new ForbiddenError(

src/types.ts

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ declare module 'fastify' {
7474
interface FastifyRequest {
7575
// Used for auth
7676
userId?: string;
77-
premium?: boolean;
7877
roles?: Roles[];
7978
service?: boolean;
8079
accessToken?: AccessToken;

0 commit comments

Comments
 (0)