Skip to content

Commit a2b6341

Browse files
committed
feat: lemmy
2 parents ad90d8d + 7bb6c46 commit a2b6341

File tree

133 files changed

+11526
-7799
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+11526
-7799
lines changed

apps/backend/src/api/api.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { SettingsController } from '@gitroom/backend/api/routes/settings.control
1414
import { PostsController } from '@gitroom/backend/api/routes/posts.controller';
1515
import { MediaController } from '@gitroom/backend/api/routes/media.controller';
1616
import { UploadModule } from '@gitroom/nestjs-libraries/upload/upload.module';
17-
import { CommentsController } from '@gitroom/backend/api/routes/comments.controller';
1817
import { BillingController } from '@gitroom/backend/api/routes/billing.controller';
1918
import { NotificationsController } from '@gitroom/backend/api/routes/notifications.controller';
2019
import { MarketplaceController } from '@gitroom/backend/api/routes/marketplace.controller';
@@ -26,6 +25,7 @@ import { CopilotController } from '@gitroom/backend/api/routes/copilot.controlle
2625
import { AgenciesController } from '@gitroom/backend/api/routes/agencies.controller';
2726
import { PublicController } from '@gitroom/backend/api/routes/public.controller';
2827
import { RootController } from '@gitroom/backend/api/routes/root.controller';
28+
import { TrackService } from '@gitroom/nestjs-libraries/track/track.service';
2929

3030
const authenticatedController = [
3131
UsersController,
@@ -34,7 +34,6 @@ const authenticatedController = [
3434
SettingsController,
3535
PostsController,
3636
MediaController,
37-
CommentsController,
3837
BillingController,
3938
NotificationsController,
4039
MarketplaceController,
@@ -63,6 +62,7 @@ const authenticatedController = [
6362
PermissionsService,
6463
CodesService,
6564
IntegrationManager,
65+
TrackService,
6666
],
6767
get exports() {
6868
return [...this.imports, ...this.providers];

apps/backend/src/api/routes/analytics.controller.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,13 @@ import { StarsListDto } from '@gitroom/nestjs-libraries/dtos/analytics/stars.lis
1515
import { ApiTags } from '@nestjs/swagger';
1616
import { IntegrationService } from '@gitroom/nestjs-libraries/database/prisma/integrations/integration.service';
1717
import { IntegrationManager } from '@gitroom/nestjs-libraries/integrations/integration.manager';
18-
import { ioRedis } from '@gitroom/nestjs-libraries/redis/redis.service';
19-
import { RefreshToken } from '@gitroom/nestjs-libraries/integrations/social.abstract';
20-
import { timer } from '@gitroom/helpers/utils/timer';
2118

2219
@ApiTags('Analytics')
2320
@Controller('/analytics')
2421
export class AnalyticsController {
2522
constructor(
2623
private _starsService: StarsService,
2724
private _integrationService: IntegrationService,
28-
private _integrationManager: IntegrationManager
2925
) {}
3026
@Get('/')
3127
async getStars(@GetOrgFromRequest() org: Organization) {

apps/backend/src/api/routes/auth.controller.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import { Body, Controller, Get, Param, Post, Req, Res } from '@nestjs/common';
1+
import {
2+
Body,
3+
Controller,
4+
Get,
5+
Ip,
6+
Param,
7+
Post,
8+
Req,
9+
Res,
10+
} from '@nestjs/common';
211
import { Response, Request } from 'express';
312

413
import { CreateOrgUserDto } from '@gitroom/nestjs-libraries/dtos/auth/create.org.user.dto';
@@ -9,6 +18,8 @@ import { ForgotPasswordDto } from '@gitroom/nestjs-libraries/dtos/auth/forgot.pa
918
import { ApiTags } from '@nestjs/swagger';
1019
import { getCookieUrlFromDomain } from '@gitroom/helpers/subdomain/subdomain.management';
1120
import { EmailService } from '@gitroom/nestjs-libraries/services/email.service';
21+
import { RealIP } from 'nestjs-real-ip';
22+
import { UserAgent } from '@gitroom/nestjs-libraries/user/user.agent';
1223

1324
@ApiTags('Auth')
1425
@Controller('/auth')
@@ -21,7 +32,9 @@ export class AuthController {
2132
async register(
2233
@Req() req: Request,
2334
@Body() body: CreateOrgUserDto,
24-
@Res({ passthrough: true }) response: Response
35+
@Res({ passthrough: true }) response: Response,
36+
@RealIP() ip: string,
37+
@UserAgent() userAgent: string
2538
) {
2639
try {
2740
const getOrgFromCookie = this._authService.getOrgFromCookie(
@@ -31,10 +44,13 @@ export class AuthController {
3144
const { jwt, addedOrg } = await this._authService.routeAuth(
3245
body.provider,
3346
body,
47+
ip,
48+
userAgent,
3449
getOrgFromCookie
3550
);
3651

37-
const activationRequired = body.provider === 'LOCAL' && this._emailService.hasProvider();
52+
const activationRequired =
53+
body.provider === 'LOCAL' && this._emailService.hasProvider();
3854

3955
if (activationRequired) {
4056
response.header('activate', 'true');
@@ -73,7 +89,9 @@ export class AuthController {
7389
async login(
7490
@Req() req: Request,
7591
@Body() body: LoginUserDto,
76-
@Res({ passthrough: true }) response: Response
92+
@Res({ passthrough: true }) response: Response,
93+
@RealIP() ip: string,
94+
@UserAgent() userAgent: string
7795
) {
7896
try {
7997
const getOrgFromCookie = this._authService.getOrgFromCookie(
@@ -83,6 +101,8 @@ export class AuthController {
83101
const { jwt, addedOrg } = await this._authService.routeAuth(
84102
body.provider,
85103
body,
104+
ip,
105+
userAgent,
86106
getOrgFromCookie
87107
);
88108

apps/backend/src/api/routes/billing.controller.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
1+
import { Body, Controller, Get, Param, Post, Req } from '@nestjs/common';
22
import { SubscriptionService } from '@gitroom/nestjs-libraries/database/prisma/subscriptions/subscription.service';
33
import { StripeService } from '@gitroom/nestjs-libraries/services/stripe.service';
44
import { GetOrgFromRequest } from '@gitroom/nestjs-libraries/user/org.from.request';
@@ -7,6 +7,7 @@ import { BillingSubscribeDto } from '@gitroom/nestjs-libraries/dtos/billing/bill
77
import { ApiTags } from '@nestjs/swagger';
88
import { GetUserFromRequest } from '@gitroom/nestjs-libraries/user/user.from.request';
99
import { NotificationService } from '@gitroom/nestjs-libraries/database/prisma/notifications/notification.service';
10+
import { Request } from 'express';
1011

1112
@ApiTags('Billing')
1213
@Controller('/billing')
@@ -23,19 +24,22 @@ export class BillingController {
2324
@Param('id') body: string
2425
) {
2526
return {
26-
exists: !!(await this._subscriptionService.checkSubscription(
27+
status: await this._stripeService.checkSubscription(
2728
org.id,
2829
body
29-
)),
30+
),
3031
};
3132
}
3233

3334
@Post('/subscribe')
3435
subscribe(
3536
@GetOrgFromRequest() org: Organization,
36-
@Body() body: BillingSubscribeDto
37+
@GetUserFromRequest() user: User,
38+
@Body() body: BillingSubscribeDto,
39+
@Req() req: Request
3740
) {
38-
return this._stripeService.subscribe(org.id, body);
41+
const uniqueId = req?.cookies?.track;
42+
return this._stripeService.subscribe(uniqueId, org.id, user.id, body, org.allowTrial);
3943
}
4044

4145
@Get('/portal')
@@ -57,12 +61,14 @@ export class BillingController {
5761
@Post('/cancel')
5862
async cancel(
5963
@GetOrgFromRequest() org: Organization,
64+
@GetUserFromRequest() user: User,
6065
@Body() body: { feedback: string }
6166
) {
6267
await this._notificationService.sendEmail(
6368
process.env.EMAIL_FROM_ADDRESS,
6469
'Subscription Cancelled',
65-
`Organization ${org.name} has cancelled their subscription because: ${body.feedback}`
70+
`Organization ${org.name} has cancelled their subscription because: ${body.feedback}`,
71+
user.email
6672
);
6773

6874
return this._stripeService.setToCancel(org.id);

apps/backend/src/api/routes/comments.controller.ts

Lines changed: 0 additions & 82 deletions
This file was deleted.

apps/backend/src/api/routes/integrations.controller.ts

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import {
2-
Body, Controller, Delete, Get, Param, Post, Put, Query, UseFilters
2+
Body,
3+
Controller,
4+
Delete,
5+
Get,
6+
Param,
7+
Post,
8+
Put,
9+
Query,
10+
UseFilters,
311
} from '@nestjs/common';
412
import { ioRedis } from '@gitroom/nestjs-libraries/redis/redis.service';
513
import { ConnectIntegrationDto } from '@gitroom/nestjs-libraries/dtos/integrations/connect.integration.dto';
@@ -42,6 +50,11 @@ export class IntegrationsController {
4250
return this._integrationManager.getAllIntegrations();
4351
}
4452

53+
@Get('/:identifier/internal-plugs')
54+
getInternalPlugs(@Param('identifier') identifier: string) {
55+
return this._integrationManager.getInternalPlugs(identifier);
56+
}
57+
4558
@Get('/customers')
4659
getCustomers(@GetOrgFromRequest() org: Organization) {
4760
return this._integrationService.customers(org.id);
@@ -66,11 +79,7 @@ export class IntegrationsController {
6679
@Param('id') id: string,
6780
@Body() body: { name: string }
6881
) {
69-
return this._integrationService.updateOnCustomerName(
70-
org.id,
71-
id,
72-
body.name
73-
);
82+
return this._integrationService.updateOnCustomerName(org.id, id, body.name);
7483
}
7584

7685
@Get('/list')
@@ -97,11 +106,24 @@ export class IntegrationsController {
97106
changeProfilePicture: !!findIntegration?.changeProfilePicture,
98107
changeNickName: !!findIntegration?.changeNickname,
99108
customer: p.customer,
109+
additionalSettings: p.additionalSettings || '[]',
100110
};
101111
}),
102112
};
103113
}
104114

115+
@Post('/:id/settings')
116+
async updateProviderSettings(
117+
@GetOrgFromRequest() org: Organization,
118+
@Param('id') id: string,
119+
@Body('additionalSettings') body: string
120+
) {
121+
if (typeof body !== 'string') {
122+
throw new Error('Invalid body');
123+
}
124+
125+
await this._integrationService.updateProviderSettings(org.id, id, body);
126+
}
105127
@Post('/:id/nickname')
106128
async setNickname(
107129
@GetOrgFromRequest() org: Organization,
@@ -242,19 +264,22 @@ export class IntegrationsController {
242264
const load = await integrationProvider[body.name](
243265
getIntegration.token,
244266
body.data,
245-
getIntegration.internalId
267+
getIntegration.internalId,
268+
getIntegration
246269
);
247270

248271
return load;
249272
} catch (err) {
250273
if (err instanceof RefreshToken) {
251-
const { accessToken, refreshToken, expiresIn } =
274+
const { accessToken, refreshToken, expiresIn, additionalSettings } =
252275
await integrationProvider.refreshToken(
253276
getIntegration.refreshToken
254277
);
255278

256279
if (accessToken) {
257280
await this._integrationService.createOrUpdateIntegration(
281+
additionalSettings,
282+
!!integrationProvider.oneTimeToken,
258283
getIntegration.organizationId,
259284
getIntegration.name,
260285
getIntegration.picture!,
@@ -336,6 +361,8 @@ export class IntegrationsController {
336361
}
337362

338363
return this._integrationService.createOrUpdateIntegration(
364+
undefined,
365+
true,
339366
org.id,
340367
name,
341368
picture,
@@ -402,6 +429,7 @@ export class IntegrationsController {
402429
name,
403430
picture,
404431
username,
432+
additionalSettings,
405433
// eslint-disable-next-line no-async-promise-executor
406434
} = await new Promise<AuthTokenDetails>(async (res) => {
407435
const auth = await integrationProvider.authenticate(
@@ -421,6 +449,7 @@ export class IntegrationsController {
421449
name: '',
422450
picture: '',
423451
username: '',
452+
additionalSettings: [],
424453
});
425454
}
426455

@@ -444,7 +473,7 @@ export class IntegrationsController {
444473
throw new NotEnoughScopes('Invalid API key');
445474
}
446475

447-
if (refresh && id !== refresh) {
476+
if (refresh && String(id) !== String(refresh)) {
448477
throw new NotEnoughScopes(
449478
'Please refresh the channel that needs to be refreshed'
450479
);
@@ -459,6 +488,8 @@ export class IntegrationsController {
459488
}
460489
}
461490
return this._integrationService.createOrUpdateIntegration(
491+
additionalSettings,
492+
!!integrationProvider.oneTimeToken,
462493
org.id,
463494
validName.trim(),
464495
picture,

0 commit comments

Comments
 (0)