Skip to content

Commit

Permalink
feat: rename service type to service provider type and add new fields…
Browse files Browse the repository at this point in the history
… for user and project IDs in service provider
  • Loading branch information
simlarsen committed Feb 5, 2025
1 parent 5310087 commit 5410157
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 10 deletions.
28 changes: 25 additions & 3 deletions Common/Models/DatabaseModels/ProjectAuthToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface SlackMiscData extends MiscData {
organizationId: string;
}

export enum ProjectAuthtokenServiceType {
export enum ProjectAuthtokenServiceProviderType {
Slack = "Slack",
MicrosoftTeams = "MicrosoftTeams",
}
Expand Down Expand Up @@ -120,7 +120,8 @@ class ProjectAuthToken extends BaseModel {
update: [],
})
@TableColumn({
title: "Service Type",
title: "Service Provider Type",
description: "Type of Service Provider - slack, microsoft teams etc.",
required: true,
unique: false,
type: TableColumnType.LongText,
Expand All @@ -132,7 +133,28 @@ class ProjectAuthToken extends BaseModel {
unique: false,
nullable: false,
})
public serviceType?: ProjectAuthtokenServiceType = undefined;
public serviceProviderType?: ProjectAuthtokenServiceProviderType = undefined;


@ColumnAccessControl({
create: [],
read: [],
update: [],
})
@TableColumn({
title: "Project ID in Service Provider",
required: true,
unique: false,
type: TableColumnType.LongText,
canReadOnRelationQuery: true,
})
@Column({
type: ColumnType.LongText,
length: ColumnLength.LongText,
unique: false,
nullable: false,
})
public serviceProviderProjectId?: string = undefined;

@ColumnAccessControl({
create: [],
Expand Down
29 changes: 26 additions & 3 deletions Common/Models/DatabaseModels/UserAuthToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface SlackMiscData extends MiscData {
userId: string;
}

export enum UserAuthtokenServiceType {
export enum UserAuthtokenServiceProviderType {
Slack = "Slack",
MicrosoftTeams = "MicrosoftTeams",
}
Expand Down Expand Up @@ -117,13 +117,36 @@ class UserAuthToken extends BaseModel {
})
public authToken?: string = undefined;


@ColumnAccessControl({
create: [Permission.CurrentUser],
read: [Permission.CurrentUser],
update: [],
})
@TableColumn({
title: "User ID in Service",
description: "User ID in the Service Provider",
required: true,
unique: false,
type: TableColumnType.LongText,
canReadOnRelationQuery: true,
})
@Column({
type: ColumnType.LongText,
length: ColumnLength.LongText,
unique: false,
nullable: false,
})
public serviceProviderUserId?: string = undefined;

@ColumnAccessControl({
create: [Permission.CurrentUser],
read: [Permission.CurrentUser],
update: [],
})
@TableColumn({
title: "Service Type",
title: "Service Provider Type",
description: "Type of Service Provider - slack, microsoft teams etc.",
required: true,
unique: false,
type: TableColumnType.LongText,
Expand All @@ -135,7 +158,7 @@ class UserAuthToken extends BaseModel {
unique: false,
nullable: false,
})
public serviceType?: UserAuthtokenServiceType = undefined;
public serviceProviderType?: UserAuthtokenServiceProviderType = undefined;

@ColumnAccessControl({
create: [Permission.CurrentUser],
Expand Down
6 changes: 3 additions & 3 deletions Common/Server/API/SlackAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class SlackAPI {
return Response.sendJsonObjectResponse(req, res, SlackAppManifest);
});

router.get("/slack/auth", (req: ExpressRequest, res: ExpressResponse) => {
router.get("/slack/auth/:projectId/:userId", (req: ExpressRequest, res: ExpressResponse) => {


// if there's an error query param.
Expand All @@ -37,8 +37,8 @@ export default class SlackAPI {
return Response.redirect(req, res, slackIntegrationPageUrl.addQueryParam("error", error));
}

const projectId: string | undefined = req.query["projectId"]?.toString();
const userId: string | undefined = req.query["userId"]?.toString();
const projectId: string | undefined = req.params["projectId"]?.toString();
const userId: string | undefined = req.params["userId"]?.toString();

if(!projectId){
return Response.sendErrorResponse(req, res, new BadDataException("Invalid ProjectID in request"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class MigrationName1738756463613 implements MigrationInterface {
public name = 'MigrationName1738756463613'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "UserAuthToken" DROP COLUMN "serviceType"`);
await queryRunner.query(`ALTER TABLE "ProjectAuthToken" DROP COLUMN "serviceType"`);
await queryRunner.query(`ALTER TABLE "UserAuthToken" ADD "serviceProviderUserId" character varying(500) NOT NULL`);
await queryRunner.query(`ALTER TABLE "UserAuthToken" ADD "serviceProviderType" character varying(500) NOT NULL`);
await queryRunner.query(`ALTER TABLE "ProjectAuthToken" ADD "serviceProviderType" character varying(500) NOT NULL`);
await queryRunner.query(`ALTER TABLE "ProjectAuthToken" ADD "serviceProviderProjectId" character varying(500) NOT NULL`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "ProjectAuthToken" DROP COLUMN "serviceProviderProjectId"`);
await queryRunner.query(`ALTER TABLE "ProjectAuthToken" DROP COLUMN "serviceProviderType"`);
await queryRunner.query(`ALTER TABLE "UserAuthToken" DROP COLUMN "serviceProviderType"`);
await queryRunner.query(`ALTER TABLE "UserAuthToken" DROP COLUMN "serviceProviderUserId"`);
await queryRunner.query(`ALTER TABLE "ProjectAuthToken" ADD "serviceType" character varying(500) NOT NULL`);
await queryRunner.query(`ALTER TABLE "UserAuthToken" ADD "serviceType" character varying(500) NOT NULL`);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import { MigrationName1737715240684 } from "./1737715240684-MigrationName";
import { MigrationName1737997557974 } from "./1737997557974-MigrationName";
import { MigrationName1738675385487 } from "./1738675385487-MigrationName";
import { MigrationName1738676335575 } from "./1738676335575-MigrationName";
import { MigrationName1738756463613 } from "./1738756463613-MigrationName";

export default [
InitialMigration,
Expand Down Expand Up @@ -206,4 +207,5 @@ export default [
MigrationName1737997557974,
MigrationName1738675385487,
MigrationName1738676335575,
MigrationName1738756463613
];
2 changes: 1 addition & 1 deletion Dashboard/src/Pages/UserSettings/SlackIntegration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const Settings: FunctionComponent<PageComponentProps> = (): ReactElement => {
return;
}

const redirect_uri: string = `${APP_API_URL}/slack/auth?projectId=${projectId.toString()}&userId=${userId.toString()}`;
const redirect_uri: string = `${APP_API_URL}/slack/auth/${projectId.toString()}/${userId.toString()}`;

Navigation.navigate(URL.fromString(`https://slack.com/oauth/v2/authorize?scope=${
botScopes.join(",")
Expand Down

0 comments on commit 5410157

Please sign in to comment.