-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: enable filters config and scientific conditions on the backend #1337
Merged
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9bccdae
Enable FiltersConfig and ScientificConditions on the BE
Ingvord 3df2697
Add default value
Ingvord 680317c
Fix cp non existing file
Ingvord 1c428ae
Add test for filters and conditions in user settings
Ingvord b107c70
Add tests
Ingvord 0a0c792
Fix #1347
Ingvord 7bf41f1
Add default endpoints
Ingvord 84a35e7
Merge branch 'refs/heads/master' into UI-604
Ingvord 9a1e643
Rename constant as per Google TypeScript convention
Ingvord a0ea170
Load default filters config from a json file
Ingvord 5acacbe
Remove default user settings POST entry point
Ingvord 6460e64
Merge remote-tracking branch 'origin/UI-604' into UI-604
Ingvord bb9c335
Add test defaults
Ingvord 7d3a298
Revert "Fix cp non existing file"
Ingvord d6f93bd
Merge branch 'master' into UI-604
Ingvord File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { ApiProperty } from "@nestjs/swagger"; | ||
import { UpdateUserSettingsDto } from "./update-user-settings.dto"; | ||
import { IsString } from "class-validator"; | ||
|
||
export class CreateUserSettingsDto extends UpdateUserSettingsDto { | ||
@ApiProperty({ type: String, required: true }) | ||
@IsString() | ||
readonly userId: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/users/interceptors/default-user-settings.interceptor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
CallHandler, | ||
ExecutionContext, | ||
Injectable, | ||
Logger, | ||
NestInterceptor, | ||
} from "@nestjs/common"; | ||
import { map, Observable, tap } from "rxjs"; | ||
import { CreateUserSettingsDto } from "../dto/create-user-settings.dto"; | ||
import { UsersService } from "../users.service"; | ||
import { kDefaultFilters } from "../schemas/user-settings.schema"; | ||
import { UpdateUserSettingsDto } from "../dto/update-user-settings.dto"; | ||
|
||
@Injectable() | ||
export class DefaultUserSettingsInterceptor implements NestInterceptor { | ||
constructor(private usersService: UsersService) {} | ||
async intercept( | ||
context: ExecutionContext, | ||
next: CallHandler, | ||
): Promise<Observable<unknown>> { | ||
return next.handle().pipe( | ||
map(async () => { | ||
Logger.log("DefaultUserSettingsInterceptor"); | ||
const defaultUserSettings: UpdateUserSettingsDto = { | ||
columns: [], | ||
filters: kDefaultFilters, | ||
conditions: [], | ||
}; | ||
console.log(defaultUserSettings); | ||
return defaultUserSettings; | ||
}), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
Body, | ||
ForbiddenException, | ||
HttpCode, | ||
CanActivate, | ||
} from "@nestjs/common"; | ||
import { | ||
ApiBearerAuth, | ||
|
@@ -31,7 +32,10 @@ | |
import { JWTUser } from "../auth/interfaces/jwt-user.interface"; | ||
import { UserSettings } from "./schemas/user-settings.schema"; | ||
import { CreateUserSettingsDto } from "./dto/create-user-settings.dto"; | ||
import { PartialUpdateUserSettingsDto } from "./dto/update-user-settings.dto"; | ||
import { | ||
PartialUpdateUserSettingsDto, | ||
UpdateUserSettingsDto, | ||
} from "./dto/update-user-settings.dto"; | ||
import { User } from "./schemas/user.schema"; | ||
import { CreateUserSettingsInterceptor } from "./interceptors/create-user-settings.interceptor"; | ||
import { AuthService } from "src/auth/auth.service"; | ||
|
@@ -44,6 +48,8 @@ | |
import { AuthenticatedPoliciesGuard } from "../casl/guards/auth-check.guard"; | ||
import { ReturnedUserDto } from "./dto/returned-user.dto"; | ||
import { ReturnedAuthLoginDto } from "src/auth/dto/returnedLogin.dto"; | ||
import { PoliciesGuard } from "src/casl/guards/policies.guard"; | ||
import { DefaultUserSettingsInterceptor } from "./interceptors/default-user-settings.interceptor"; | ||
|
||
@ApiBearerAuth() | ||
@ApiTags("users") | ||
|
@@ -307,6 +313,42 @@ | |
return this.usersService.findOneAndDeleteUserSettings(id); | ||
} | ||
|
||
@UseInterceptors(DefaultUserSettingsInterceptor) | ||
@UseGuards( | ||
class ByPassAuthenticatedPoliciesGuard | ||
extends PoliciesGuard | ||
implements CanActivate | ||
{ | ||
async canActivate(): Promise<boolean> { | ||
return Promise.resolve(true); | ||
} | ||
}, | ||
) | ||
Comment on lines
+317
to
+326
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the endpoint should open to unauthenticated users, we can just use PoliciesGuard or remove UseGuards at all I suppose. Since we are not checking policies here |
||
@Get("/settings/default") | ||
async getDefaultSettings(): Promise<UserSettings> { | ||
return Promise.resolve(new UserSettings()); | ||
} | ||
|
||
@UseGuards(AuthenticatedPoliciesGuard) | ||
@CheckPolicies((ability: AppAbility) => | ||
ability.can(Action.UserCreateAny, User), | ||
) | ||
@Post("/settings/default") | ||
async postDefaultSettings( | ||
@Req() request: Request, | ||
@Body() createUserSettingsDto: CreateUserSettingsDto, | ||
): Promise<UserSettings> { | ||
await this.checkUserAuthorization( | ||
request, | ||
[Action.UserCreateAny], | ||
createUserSettingsDto.userId, | ||
); | ||
return this.usersService.createUserSettings( | ||
"default", | ||
createUserSettingsDto, | ||
); | ||
} | ||
|
||
@UseGuards(AuthenticatedPoliciesGuard) | ||
@CheckPolicies((ability: AppAbility) => { | ||
return ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k stands for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, old habit - roots from my C++ experience to follow Google code styling standards
k
- prefix for a static constI used to maintain JavaScriptMVC (pre-Angular SPA vanilla JS framework), together with the folks we adopted that standard also for JS
If that makes any sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally it would be more appreciated if the naming is consistent with existing naming convention within the application scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#Sure, what is the current convention?
We don't have a strict naming convention in this project yet, but we should have one documented in the future.
Google also has a code styling standard for typescript as well, which, generally speaking is like unspoken standard for most of the typescript applications
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I will check that out!