Skip to content

Commit

Permalink
feat: add new dataset v4 controller (#1541)
Browse files Browse the repository at this point in the history
* start with adding the v4 datasets controller

* start the main cleanup on the dataset v4 controller

* cleanup and fix some linting errors

* use the versioning of datasets controller properly and finalize the initial v4 controller

* do some more cleanup in the new controller

* use improved regex to extract the version from the URI

* refactor how we use config module and make accessGroups easily accessible

* fix failing unit tests

* improve dataset dto types for sdk generation

* add aggregation for findById and findOne on the datasets.v4 controller

* add some notes and todos on whats left

* do some more cleanup and improve include filters for aggregation

* more cleanup and filter refactor and validation

* try to revert some package upgrades

* try to revert some more package changes

* test the new content property

* content property final improvements

* use content variable instead of funciton

* cleanup

* finalize all filters for find dataset endpoints

* fix most of the PR review comments

* fix v3 dataset controller access filters

* some small improvements and leads how to solve the nested relational field access based filters

* try to revert some chages that are making tests fail

* fix api tests as well

* fix: update GitHub Actions workflow to conditionally upload SDK artifacts and add cleanup step for non-push events (#1562)

* add granular access checks for relational fields

* add new environment variable variable description in github actions

* feat: add public endpoints for better separation of concerns

* add sort and skip in the find one complete

* move the public dataset v4 endpoints in own controller

* review feedback improvements

* fix some review comments and add fullfacet to public endpoints as well

* fix default sort value

* feat: add api tests for the new controllers (#1580)

<!--
Follow semantic-release guidelines for the PR title, which is used in
the changelog.

Title should follow the format `<type>(<scope>): <subject>`, where
- Type is one of:
build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test|BREAKING
CHANGE
- Scope (optional) describes the place of the change (eg a particular
milestone) and is usually omitted
- subject should be a non-capitalized one-line description in present
imperative tense and not ending with a period

See
https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines
for more details.
-->

## Description
This is PR that adds unit and api tests for the dataset v4 controllers.

## Motivation
After adding the new controllers we need to test all this refactor and
also the public endpoints and access to the data.

## Fixes

* https://jira.ess.eu/browse/SWAP-4366

## Changes:
<!-- Please provide a list of the changes implemented by this PR -->

* adding tests for dataset v4 controllers

## Tests included

- [x] Included for each change/fix?
- [x] Passing? <!-- Merge will not be approved unless tests pass -->

## Documentation
- [x] swagger documentation updated (required for API changes)
- [ ] official documentation updated

### official documentation info
<!-- If you have updated the official documentation, please provide PR #
and URL of the updated pages -->

* revert some changes in package-lock

* fix final review comments and suggestions

---------

Co-authored-by: Jay <[email protected]>
Co-authored-by: Max Novelli <[email protected]>
  • Loading branch information
3 people authored Jan 23, 2025
1 parent adaacd0 commit b64bafb
Show file tree
Hide file tree
Showing 67 changed files with 4,514 additions and 436 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/release-and-publish-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ jobs:
env:
MONGODB_URI: "mongodb://localhost:27017/scicat"
JWT_SECRET: thisIsTheJwtSecret
# It disables the content property on some of the endpoints as the sdk generator complains about it.
# We want to keep it when the app is running to improve the swagger documentation and usage.
SDK_PACKAGE_SWAGGER_HELPERS_DISABLED: true
run: |
npm install -g wait-on && npm install
npm run start & wait-on http://localhost:3000/api/v3/health --timeout 200000
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/upload-sdk-artifact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
env:
MONGODB_URI: "mongodb://localhost:27017/scicat"
JWT_SECRET: thisIsTheJwtSecret
# It disables the content property on some of the endpoints as the sdk generator complains about it.
# We want to keep it when the app is running to improve the swagger documentation and usage.
SDK_PACKAGE_SWAGGER_HELPERS_DISABLED: true
run: |
npm install -g wait-on && npm install
npm run start & wait-on http://localhost:3000/api/v3/health --timeout 200000
Expand Down
31 changes: 0 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
"chai-http": "^5.1.1",
"concurrently": "^9.0.0",
"eslint": "^9.0.0",
"eslint-config-loopback": "^13.1.0",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-prettier": "^5.0.0",
"globals": "^15.12.0",
Expand Down
2 changes: 0 additions & 2 deletions src/admin/admin.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Module } from "@nestjs/common";
import { AdminService } from "./admin.service";
import { AdminController } from "./admin.controller";
import { ConfigModule } from "@nestjs/config";

@Module({
controllers: [AdminController],
imports: [ConfigModule],
providers: [AdminService],
exports: [AdminService],
})
Expand Down
12 changes: 6 additions & 6 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ import { MetricsModule } from "./metrics/metrics.module";

@Module({
imports: [
AttachmentsModule,
AuthModule,
CaslModule,
CommonModule,
ConfigModule.forRoot({
load: [configuration],
isGlobal: true,
cache: true,
}),
AuthModule,
CaslModule,
AttachmentsModule,
CommonModule,
// NOTE: `ConditionalModule.registerWhen` directly uses `process.env` as it does not support
// dependency injection for `ConfigService`. This approach ensures compatibility while
// leveraging environment variables for conditional module loading.
Expand All @@ -59,7 +61,6 @@ import { MetricsModule } from "./metrics/metrics.module";
LogbooksModule,
EventEmitterModule.forRoot(),
MailerModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => {
const port = configService.get<string>("smtp.port");
return {
Expand Down Expand Up @@ -88,7 +89,6 @@ import { MetricsModule } from "./metrics/metrics.module";
inject: [ConfigService],
}),
MongooseModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
uri: configService.get<string>("mongodbUri"),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import { AccessGroupFromPayloadService } from "./access-group-from-payload.servi
import { HttpService } from "@nestjs/axios";
import { AccessGroupFromMultipleProvidersService } from "./access-group-from-multiple-providers.service";
import { Logger } from "@nestjs/common";
import { ConfigModule } from "@nestjs/config";
/*
* this is the default function which provides an empty array as groups
*/
export const accessGroupServiceFactory = {
imports: [ConfigModule],
provide: AccessGroupService,
useFactory: (configService: ConfigService) => {
Logger.debug("Service factory starting", "accessGroupServiceFactory");
Expand Down
4 changes: 1 addition & 3 deletions src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AuthController } from "./auth.controller";
import { JwtModule } from "@nestjs/jwt";
import { JwtStrategy } from "./strategies/jwt.strategy";
import { LdapStrategy } from "./strategies/ldap.strategy";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { ConfigService } from "@nestjs/config";
import { UsersService } from "src/users/users.service";
import { OidcConfig } from "src/config/configuration";
import { BuildOpenIdClient, OidcStrategy } from "./strategies/oidc.strategy";
Expand Down Expand Up @@ -42,9 +42,7 @@ const OidcStrategyFactory = {

@Module({
imports: [
ConfigModule,
JwtModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
secret: configService.get<string>("jwt.secret"),
signOptions: { expiresIn: configService.get<number>("jwt.expiresIn") },
Expand Down
3 changes: 2 additions & 1 deletion src/casl/casl-ability.factory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ConfigService } from "@nestjs/config";
import { CaslAbilityFactory } from "./casl-ability.factory";

describe("CaslAbilityFactory", () => {
it("should be defined", () => {
expect(new CaslAbilityFactory()).toBeDefined();
expect(new CaslAbilityFactory(new ConfigService())).toBeDefined();
});
});
Loading

0 comments on commit b64bafb

Please sign in to comment.