Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…4-gitfit into 348-feat-add-projects-select-to-analytics-page
  • Loading branch information
AnutkaGn committed Sep 23, 2024
2 parents f591dff + e80154e commit 710a066
Show file tree
Hide file tree
Showing 48 changed files with 507 additions and 29 deletions.
10 changes: 5 additions & 5 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
".": "1.47.0",
"apps/backend": "1.29.0",
"apps/frontend": "1.43.0",
"packages/shared": "1.27.0",
"scripts/analytics": "1.6.0"
".": "1.48.0",
"apps/backend": "1.30.0",
"apps/frontend": "1.44.0",
"packages/shared": "1.28.0",
"scripts/analytics": "1.7.0"
}
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## [1.48.0](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/compare/v1.47.0...v1.48.0) (2024-09-23)


### Features

* add ability to merge contributors gf-344 ([#435](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/issues/435)) ([a52d648](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/commit/a52d6486d6753a73d228b3149eb5984ba32f4e81))
* authorize the request before starting background job for analytics gf-464 ([#467](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/issues/467)) ([fb682c3](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/commit/fb682c36b7159031475896e12169738756928d6e))


### Bug Fixes

* adjust column sizes so table fits 1440 screen resolution gf-448 ([#461](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/issues/461)) ([bf7e7a6](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/commit/bf7e7a6596dc55a8d910bb48ed82f92040731227))
* adjust root permissions gf-350 ([#466](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/issues/466)) ([6e42ada](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/commit/6e42ada9f78adcd84fd348a76f7518f0d1b03819))
* useSearch change to handle modal search gf-455 ([#459](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/issues/459)) ([7b99a6d](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/commit/7b99a6d573eb67aa6d5517daff0c06ebb1fda8a4))

## [1.47.0](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/compare/v1.46.0...v1.47.0) (2024-09-20)


Expand Down
13 changes: 13 additions & 0 deletions apps/backend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## [1.30.0](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/compare/backend-v1.29.0...backend-v1.30.0) (2024-09-23)


### Features

* add ability to merge contributors gf-344 ([#435](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/issues/435)) ([a52d648](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/commit/a52d6486d6753a73d228b3149eb5984ba32f4e81))
* authorize the request before starting background job for analytics gf-464 ([#467](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/issues/467)) ([fb682c3](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/commit/fb682c36b7159031475896e12169738756928d6e))


### Bug Fixes

* adjust root permissions gf-350 ([#466](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/issues/466)) ([6e42ada](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/commit/6e42ada9f78adcd84fd348a76f7518f0d1b03819))

## [1.29.0](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/compare/backend-v1.28.1...backend-v1.29.0) (2024-09-20)


Expand Down
2 changes: 1 addition & 1 deletion apps/backend/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@git-fit/backend",
"type": "module",
"version": "1.29.0",
"version": "1.30.0",
"engines": {
"node": "20.x.x",
"npm": "10.x.x"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ActivityLogsApiPath, APIPath, AuthApiPath } from "@git-fit/shared";
import {
ActivityLogsApiPath,
APIPath,
AuthAnalyticsApiPath,
AuthApiPath,
} from "@git-fit/shared";

import { type WhiteRoute } from "~/libs/types/types.js";

Expand All @@ -9,6 +14,10 @@ const WHITE_ROUTES: WhiteRoute[] = [
methods: ["POST"],
path: `${APIPath.ACTIVITY_LOGS}${ActivityLogsApiPath.ROOT}`,
},
{
methods: ["POST"],
path: `${APIPath.AUTH_ANALYTICS}${AuthAnalyticsApiPath.ROOT}`,
},
];

export { WHITE_ROUTES };
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { database } from "~/libs/modules/database/database.js";
import { logger } from "~/libs/modules/logger/logger.js";
import { activityLogController } from "~/modules/activity-logs/activity-logs.js";
import { authController } from "~/modules/auth/auth.js";
import { authAnalyticsController } from "~/modules/auth-analytics/auth-analytics.js";
import { contributorController } from "~/modules/contributors/contributors.js";
import { groupController } from "~/modules/groups/groups.js";
import { notificationController } from "~/modules/notifications/notifications.js";
Expand All @@ -26,6 +27,7 @@ const apiV1 = new BaseServerApplicationApi(
"v1",
config,
...activityLogController.routes,
...authAnalyticsController.routes,
...authController.routes,
...notificationController.routes,
...permissionController.routes,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { APIPath } from "~/libs/enums/enums.js";
import {
type APIHandlerOptions,
type APIHandlerResponse,
BaseController,
} from "~/libs/modules/controller/controller.js";
import { HTTPCode } from "~/libs/modules/http/http.js";
import { type Logger } from "~/libs/modules/logger/logger.js";

import { type AuthAnalyticsService } from "./auth-analytics.service.js";
import { AuthAnalyticsApiPath } from "./libs/enums/enums.js";
import { type AuthAnalyticsValidateCredentialsRequestDto } from "./libs/types/types.js";
import { authAnalyticsValidateCredentialsValidationSchema } from "./libs/validation-schemas/validation-schemas.js";

class AuthAnalyticsController extends BaseController {
private authAnalyticsService: AuthAnalyticsService;

public constructor(
logger: Logger,
authAnalyticsService: AuthAnalyticsService,
) {
super(logger, APIPath.AUTH_ANALYTICS);

this.authAnalyticsService = authAnalyticsService;

this.addRoute({
handler: (options) =>
this.validateCredentials(
options as APIHandlerOptions<{
body: AuthAnalyticsValidateCredentialsRequestDto;
headers: Record<string, string | undefined>;
}>,
),
method: "POST",
path: AuthAnalyticsApiPath.ROOT,
validation: {
body: authAnalyticsValidateCredentialsValidationSchema,
},
});
}

/**
* @swagger
* /auth-analytics:
* post:
* description: Validate credentials for collecting statistics script
* requestBody:
* description: Collecting statistics script credentials
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* userId:
* type: number
* minimum: 1
* responses:
* 200:
* description: Successful operation
* content:
* application/json:
* schema:
* type: object
* properties:
* projectId:
* type: number
* projectName:
* type: string
*/

private async validateCredentials(
options: APIHandlerOptions<{
body: AuthAnalyticsValidateCredentialsRequestDto;
headers: Record<string, string | undefined>;
}>,
): Promise<APIHandlerResponse> {
const authorizationHeader = options.headers["authorization"];
const apiKey = authorizationHeader?.replace("Bearer ", "") ?? "";

const payload = {
apiKey,
...options.body,
};

return {
payload: await this.authAnalyticsService.validateCredentials(payload),
status: HTTPCode.OK,
};
}
}

export { AuthAnalyticsController };
44 changes: 44 additions & 0 deletions apps/backend/src/modules/auth-analytics/auth-analytics.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { type UserService } from "~/modules/users/user.service.js";

import { type ProjectApiKeyService } from "../project-api-keys/project-api-keys.js";
import { type ProjectService } from "../projects/projects.js";
import {
type AuthAnalyticsValidateCredentialsRequestDto,
type AuthAnalyticsValidateCredentialsResponseDto,
} from "./libs/types/types.js";

class AuthAnalyticsService {
private projectApiKeyService: ProjectApiKeyService;

private projectService: ProjectService;

private userService: UserService;

public constructor(
projectApiKeyService: ProjectApiKeyService,
projectService: ProjectService,
userService: UserService,
) {
this.projectService = projectService;
this.projectApiKeyService = projectApiKeyService;
this.userService = userService;
}

public async validateCredentials(
payload: { apiKey: string } & AuthAnalyticsValidateCredentialsRequestDto,
): Promise<AuthAnalyticsValidateCredentialsResponseDto> {
await this.userService.find(payload.userId);

const projectApiKeyEntity = await this.projectApiKeyService.findByApiKey(
payload.apiKey,
);

const project = await this.projectService.find(
projectApiKeyEntity.projectId,
);

return { projectId: project.id, projectName: project.name };
}
}

export { AuthAnalyticsService };
19 changes: 19 additions & 0 deletions apps/backend/src/modules/auth-analytics/auth-analytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { logger } from "~/libs/modules/logger/logger.js";
import { projectApiKeyService } from "~/modules/project-api-keys/project-api-keys.js";
import { projectService } from "~/modules/projects/projects.js";
import { userService } from "~/modules/users/users.js";

import { AuthAnalyticsController } from "./auth-analytics.controller.js";
import { AuthAnalyticsService } from "./auth-analytics.service.js";

const authAnalyticsService = new AuthAnalyticsService(
projectApiKeyService,
projectService,
userService,
);
const authAnalyticsController = new AuthAnalyticsController(
logger,
authAnalyticsService,
);

export { authAnalyticsController };
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AuthAnalyticsApiPath } from "@git-fit/shared";
4 changes: 4 additions & 0 deletions apps/backend/src/modules/auth-analytics/libs/types/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export {
type AuthAnalyticsValidateCredentialsRequestDto,
type AuthAnalyticsValidateCredentialsResponseDto,
} from "@git-fit/shared";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { authAnalyticsValidateCredentialsValidationSchema } from "@git-fit/shared";
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class ContributorController extends BaseController {
),
method: "PATCH",
path: ContributorsApiPath.MERGE_$ID,
preHandlers: [checkUserPermissions([PermissionKey.MANAGE_ALL_PROJECTS])],
validation: {
body: contributorMergeValidationSchema,
},
Expand All @@ -102,6 +103,7 @@ class ContributorController extends BaseController {
),
method: "PATCH",
path: ContributorsApiPath.$ID,
preHandlers: [checkUserPermissions([PermissionKey.MANAGE_ALL_PROJECTS])],
validation: {
body: contributorPatchValidationSchema,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,17 @@ class ProjectApiKeyService implements Service {
): Promise<ProjectApiKeyCreateResponseDto> {
const encryptedKey = this.encryption.encrypt(projectApiKey);

const apiKeyEnitity =
const apiKeyEntity =
await this.projectApiKeyRepository.findByApiKey(encryptedKey);

if (!apiKeyEnitity) {
if (!apiKeyEntity) {
throw new ProjectApiKeyError({
message: ExceptionMessage.PROJECT_API_KEY_NOT_FOUND,
status: HTTPCode.NOT_FOUND,
});
}

const apiKey = apiKeyEnitity.toObject();
const apiKey = apiKeyEntity.toObject();
const decryptedApiKey = this.encryption.decrypt(apiKey.encryptedKey);

return {
Expand Down
14 changes: 14 additions & 0 deletions apps/frontend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## [1.44.0](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/compare/frontend-v1.43.0...frontend-v1.44.0) (2024-09-23)


### Features

* add ability to merge contributors gf-344 ([#435](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/issues/435)) ([a52d648](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/commit/a52d6486d6753a73d228b3149eb5984ba32f4e81))


### Bug Fixes

* adjust column sizes so table fits 1440 screen resolution gf-448 ([#461](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/issues/461)) ([bf7e7a6](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/commit/bf7e7a6596dc55a8d910bb48ed82f92040731227))
* adjust root permissions gf-350 ([#466](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/issues/466)) ([6e42ada](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/commit/6e42ada9f78adcd84fd348a76f7518f0d1b03819))
* useSearch change to handle modal search gf-455 ([#459](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/issues/459)) ([7b99a6d](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/commit/7b99a6d573eb67aa6d5517daff0c06ebb1fda8a4))

## [1.43.0](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/compare/frontend-v1.42.0...frontend-v1.43.0) (2024-09-20)


Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@git-fit/frontend",
"private": true,
"version": "1.43.0",
"version": "1.44.0",
"type": "module",
"engines": {
"node": "20.x.x",
Expand Down
5 changes: 4 additions & 1 deletion apps/frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ createRoot(document.querySelector("#root") as HTMLElement).render(
PermissionKey.VIEW_ALL_PROJECTS,
PermissionKey.MANAGE_ALL_PROJECTS,
]}
routePermissions={[PermissionKey.MANAGE_USER_ACCESS]}
routePermissions={[
PermissionKey.MANAGE_USER_ACCESS,
PermissionKey.MANAGE_ALL_PROJECTS,
]}
>
<ProjectAccessManagement />
</ProtectedRoute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ import styles from "./styles.module.css";

type Properties = {
contributor: ContributorGetAllItemResponseDto;
hasEditPermission: boolean;
hasMergePermission: boolean;
onEdit: (contributorId: number) => void;
onMerge: (contributorId: number) => void;
};

const ContributorCard = ({
contributor,
hasEditPermission,
hasMergePermission,
onEdit,
onMerge,
}: Properties): JSX.Element => {
Expand Down Expand Up @@ -58,6 +62,8 @@ const ContributorCard = ({
)}
<ContributorMenu
contributorId={contributor.id}
hasEditPermission={hasEditPermission}
hasMergePermission={hasMergePermission}
onEdit={handleEditClick}
onMerge={handleMergeClick}
/>
Expand Down
Loading

0 comments on commit 710a066

Please sign in to comment.