Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Greffier committed Sep 29, 2022
2 parents d0e76f0 + e65eac1 commit f30cad8
Show file tree
Hide file tree
Showing 80 changed files with 727 additions and 465 deletions.
8 changes: 3 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ To suggest a new feature on suricate, [open a ticket](https://github.com/micheli

#### Pull requests

- Open a new GitHub pull request with the patch.

- Ensure the PR description clearly describes the problem and solution. Include the relevant issue number in the description if applicable.

- Before submitting, please read the [Open Code of Conduct](http://todogroup.org/opencodeofconduct/) guide to know more about coding conventions and benchmarks.
- Open a new GitHub pull request with the patch. Pull requests are displayed in the release notes, be sure to:
- Use the past tense ("Added new feature...", "Fixed bug on...")
- Add tags to the PR ("documentation" for documentation updates, "bug" for bug fixing, ...)

### Styleguides

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ protected void init() throws FileNotFoundException {
proxyConfiguration.setProxy();

// Update widgets
gitService.updateWidgetFromEnabledGitRepositories();
gitService.updateWidgetFromEnabledGitRepositoriesAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@

import static springfox.documentation.builders.PathSelectors.regex;

/**
* The swagger configuration, to see the swagger page go to : "/swagger-ui.html"
*/
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public Page<CategoryResponseDto> getCategories(@ApiParam(name = "search", value
})
@GetMapping(value = "/v1/categories/{categoryId}/widgets")
@PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<List<WidgetResponseDto>> getWidgetByCategory(@ApiParam(name = "categoryId", value = "The category id", required = true)
public ResponseEntity<List<WidgetResponseDto>> getWidgetByCategory(@ApiParam(name = "categoryId", value = "The category id", required = true, example = "1")
@PathVariable("categoryId") Long categoryId) {
Optional<List<Widget>> widgetsOptional = this.widgetService.getWidgetsByCategory(categoryId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,8 @@ public ResponseEntity<Void> imports(@ApiIgnore @AuthenticationPrincipal LocalUse
repositoryOptional.ifPresent(value -> repository.setId(value.getId()));
});

List<Repository> nonExistingEnabledRepositories = repositories
.stream()
.filter(repository -> repository.getId() == null && repository.isEnabled())
.collect(Collectors.toList());

repositoryService.addOrUpdateRepositories(repositories);
for (Repository repository : nonExistingEnabledRepositories) {
gitService.updateWidgetsFromRepository(repository);
}
gitService.updateWidgetFromEnabledGitRepositories();

List<Project> projects = importDto.getProjects()
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public ResponseEntity<Void> addUserToProject(@ApiIgnore @AuthenticationPrincipal
public ResponseEntity<Void> deleteUserFromProject(@ApiIgnore @AuthenticationPrincipal LocalUser connectedUser,
@ApiParam(name = "projectToken", value = "The project token", required = true)
@PathVariable("projectToken") String projectToken,
@ApiParam(name = "userId", value = "The user id", required = true)
@ApiParam(name = "userId", value = "The user id", required = true, example = "1")
@PathVariable("userId") Long userId) {
Optional<Project> projectOptional = projectService.getOneByToken(projectToken);
if (!projectOptional.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public ResponseEntity<Void> updateProjectGrids(@ApiIgnore @AuthenticationPrincip
public ResponseEntity<Void> deleteGridById(@ApiIgnore @AuthenticationPrincipal LocalUser connectedUser,
@ApiParam(name = "projectToken", value = "The project token", required = true)
@PathVariable("projectToken") String projectToken,
@ApiParam(name = "gridId", value = "The grid id", required = true)
@ApiParam(name = "gridId", value = "The grid id", required = true, example = "1")
@PathVariable("gridId") Long gridId) {
Optional<Project> projectOptional = projectService.getOneByToken(projectToken);
if (!projectOptional.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class ProjectWidgetController {
})
@GetMapping(value = "/v1/projectWidgets/{projectWidgetId}")
@PermitAll
public ResponseEntity<ProjectWidgetResponseDto> getById(@ApiParam(name = "projectWidgetId", value = "The project widget id", required = true)
public ResponseEntity<ProjectWidgetResponseDto> getById(@ApiParam(name = "projectWidgetId", value = "The project widget id", required = true, example = "1")
@PathVariable("projectWidgetId") Long projectWidgetId) {
Optional<ProjectWidget> projectWidgetOptional = this.projectWidgetService.getOne(projectWidgetId);
if (!projectWidgetOptional.isPresent()) {
Expand Down Expand Up @@ -152,7 +152,7 @@ public ResponseEntity<List<ProjectWidgetResponseDto>> getByProject(@ApiParam(nam
@PutMapping(value = "/v1/projectWidgets/{projectWidgetId}")
@PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<ProjectWidgetResponseDto> editByProject(@ApiIgnore @AuthenticationPrincipal LocalUser connectedUser,
@ApiParam(name = "projectWidgetId", value = "The project widget id", required = true)
@ApiParam(name = "projectWidgetId", value = "The project widget id", required = true, example = "1")
@PathVariable("projectWidgetId") Long projectWidgetId,
@ApiParam(name = "projectWidgetResponseDto", value = "The project widget informations to update", required = true)
@RequestBody ProjectWidgetRequestDto projectWidgetRequestDto) {
Expand Down Expand Up @@ -194,7 +194,7 @@ public ResponseEntity<ProjectWidgetResponseDto> editByProject(@ApiIgnore @Authen
public ResponseEntity<ProjectWidgetResponseDto> addProjectWidgetToProject(@ApiIgnore @AuthenticationPrincipal LocalUser connectedUser,
@ApiParam(name = "projectToken", value = "The project token", required = true)
@PathVariable("projectToken") String projectToken,
@ApiParam(name = "gridId", value = "The grid id", required = true)
@ApiParam(name = "gridId", value = "The grid id", required = true, example = "1")
@PathVariable("gridId") Long gridId,
@ApiParam(name = "projectWidgetDto", value = "The project widget info's", required = true)
@RequestBody ProjectWidgetRequestDto projectWidgetRequestDto) {
Expand Down Expand Up @@ -243,7 +243,7 @@ public ResponseEntity<ProjectWidgetResponseDto> addProjectWidgetToProject(@ApiIg
@DeleteMapping(value = "/v1/projectWidgets/{projectWidgetId}")
@PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<Void> deleteById(@ApiIgnore @AuthenticationPrincipal LocalUser connectedUser,
@ApiParam(name = "projectWidgetId", value = "The project widget id", required = true)
@ApiParam(name = "projectWidgetId", value = "The project widget id", required = true, example = "1")
@PathVariable("projectWidgetId") Long projectWidgetId) {
Optional<ProjectWidget> projectWidgetOptional = projectWidgetService.getOne(projectWidgetId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public Page<RepositoryResponseDto> getAll(@ApiParam(name = "search", value = "Se
Pageable pageable) {
return repositoryService
.getAll(search, pageable)
.map(this.repositoryMapper::toRepositoryDTONoWidgets);
.map(repositoryMapper::toRepositoryDTONoWidgets);
}

/**
Expand All @@ -116,11 +116,11 @@ public Page<RepositoryResponseDto> getAll(@ApiParam(name = "search", value = "Se
@PreAuthorize("hasRole('ROLE_ADMIN')")
public ResponseEntity<RepositoryResponseDto> createOne(@ApiParam(name = "repositoryResponseDto", value = "The repository to create", required = true)
@RequestBody RepositoryRequestDto repositoryRequestDto) throws GitAPIException, IOException {
Repository repository = this.repositoryMapper.toRepositoryEntity(null, repositoryRequestDto);
Repository repository = repositoryMapper.toRepositoryEntity(null, repositoryRequestDto);
repositoryService.addOrUpdateRepository(repository);

if (repository.isEnabled()) {
gitService.updateWidgetsFromRepository(repository);
gitService.updateWidgetFromEnabledGitRepositories();
}

URI resourceLocation = ServletUriComponentsBuilder
Expand All @@ -137,7 +137,6 @@ public ResponseEntity<RepositoryResponseDto> createOne(@ApiParam(name = "reposit

/**
* Retrieve an existing repository by id
*
* @param repositoryId The repository Id
* @return The repository
*/
Expand All @@ -151,17 +150,17 @@ public ResponseEntity<RepositoryResponseDto> createOne(@ApiParam(name = "reposit
@GetMapping(value = "/v1/repositories/{repositoryId}")
@PreAuthorize("hasRole('ROLE_ADMIN')")
@Transactional
public ResponseEntity<RepositoryResponseDto> getOneById(@ApiParam(name = "repositoryId", value = "The repository id", required = true)
public ResponseEntity<RepositoryResponseDto> getOneById(@ApiParam(name = "repositoryId", value = "The repository id", required = true, example = "1")
@PathVariable Long repositoryId) {
Optional<Repository> optionalRepository = this.repositoryService.getOneById(repositoryId);
Optional<Repository> optionalRepository = repositoryService.getOneById(repositoryId);
if (!optionalRepository.isPresent()) {
throw new ObjectNotFoundException(Repository.class, repositoryId);
}

return ResponseEntity
.ok()
.contentType(MediaType.APPLICATION_JSON)
.body(this.repositoryMapper.toRepositoryDTONoWidgets(optionalRepository.get()));
.body(repositoryMapper.toRepositoryDTONoWidgets(optionalRepository.get()));
}

/**
Expand All @@ -176,47 +175,39 @@ public ResponseEntity<RepositoryResponseDto> getOneById(@ApiParam(name = "reposi
})
@PutMapping(value = "/v1/repositories/{repositoryId}")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public ResponseEntity<Void> updateOneById(@ApiParam(name = "repositoryId", value = "The repository id", required = true)
public ResponseEntity<Void> updateOneById(@ApiParam(name = "repositoryId", value = "The repository id", required = true, example = "1")
@PathVariable Long repositoryId,
@ApiParam(name = "repositoryResponseDto", value = "The repository with the new info's to update", required = true)
@RequestBody RepositoryRequestDto repositoryRequestDto) throws GitAPIException, IOException {
if (!this.repositoryService.existsById(repositoryId)) {
@RequestBody RepositoryRequestDto repositoryRequestDto,
@ApiParam(name = "disableSync", value = "Disable the synchronization of the repository", example = "true")
@RequestParam boolean disableSync) throws GitAPIException, IOException {
if (!repositoryService.existsById(repositoryId)) {
throw new ObjectNotFoundException(Repository.class, repositoryId);
}

Repository repository = this.repositoryMapper.toRepositoryEntity(repositoryId, repositoryRequestDto);
this.repositoryService.addOrUpdateRepository(repository);
Repository repository = repositoryMapper.toRepositoryEntity(repositoryId, repositoryRequestDto);
repositoryService.addOrUpdateRepository(repository);

if (repository.isEnabled()) {
gitService.updateWidgetsFromRepository(repository);
if (!disableSync && repository.isEnabled()) {
gitService.updateWidgetFromEnabledGitRepositories();
}

return ResponseEntity.noContent().build();
}

/**
* Reload a repository by id
* Synchronize all repositories
*/
@ApiOperation(value = "Reload an existing repository by id")
@ApiOperation(value = "RSynchronize all repositories")
@ApiResponses(value = {
@ApiResponse(code = 204, message = "Repository reloaded"),
@ApiResponse(code = 204, message = "Repositories synchronized"),
@ApiResponse(code = 401, message = "Authentication error, token expired or invalid", response = ApiErrorDto.class),
@ApiResponse(code = 403, message = "You don't have permission to access to this resource", response = ApiErrorDto.class),
@ApiResponse(code = 404, message = "Repository not found", response = ApiErrorDto.class)
@ApiResponse(code = 403, message = "You don't have permission to access to this resource", response = ApiErrorDto.class)
})
@PutMapping(value = "/v1/repositories/{repositoryId}/reload")
@PutMapping(value = "/v1/repositories/synchronize")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public ResponseEntity<Void> reload(@ApiParam(name = "repositoryId", value = "The repository id", required = true)
@PathVariable Long repositoryId) throws GitAPIException, IOException {
Optional<Repository> optionalRepository = this.repositoryService.getOneById(repositoryId);
if (!optionalRepository.isPresent()) {
throw new ObjectNotFoundException(Repository.class, repositoryId);
}

Repository repository = optionalRepository.get();
if (repository.isEnabled()) {
gitService.updateWidgetsFromRepository(repository);
}
public ResponseEntity<Void> synchronize() throws GitAPIException, IOException {
gitService.updateWidgetFromEnabledGitRepositories();

return ResponseEntity.noContent().build();
}
Expand All @@ -237,16 +228,16 @@ public ResponseEntity<Void> reload(@ApiParam(name = "repositoryId", value = "The
@GetMapping(value = "/v1/repositories/{repositoryId}/widgets")
@PreAuthorize("hasRole('ROLE_ADMIN')")
@Transactional
public ResponseEntity<List<WidgetResponseDto>> getRepositoryWidget(@ApiParam(name = "repositoryId", value = "The repository id", required = true)
public ResponseEntity<List<WidgetResponseDto>> getRepositoryWidget(@ApiParam(name = "repositoryId", value = "The repository id", required = true, example = "1")
@PathVariable Long repositoryId) {
Optional<Repository> optionalRepository = this.repositoryService.getOneById(repositoryId);
Optional<Repository> optionalRepository = repositoryService.getOneById(repositoryId);
if (!optionalRepository.isPresent()) {
throw new ObjectNotFoundException(Repository.class, repositoryId);
}

return ResponseEntity
.ok()
.contentType(MediaType.APPLICATION_JSON)
.body(this.widgetMapper.toWidgetsDTOs(optionalRepository.get().getWidgets()));
.body(widgetMapper.toWidgetsDTOs(optionalRepository.get().getWidgets()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public Page<RoleResponseDto> getRoles(@ApiParam(name = "search", value = "Search
})
@GetMapping(value = "/v1/roles/{roleId}")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public ResponseEntity<RoleResponseDto> getOne(@ApiParam(name = "roleId", value = "The role id", required = true)
public ResponseEntity<RoleResponseDto> getOne(@ApiParam(name = "roleId", value = "The role id", required = true, example = "1")
@PathVariable("roleId") Long roleId) {
Optional<Role> roleOptional = roleService.getOneById(roleId);
if (!roleOptional.isPresent()) {
Expand All @@ -141,7 +141,7 @@ public ResponseEntity<RoleResponseDto> getOne(@ApiParam(name = "roleId", value =
})
@GetMapping(value = "/v1/roles/{roleId}/users")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public ResponseEntity<List<UserResponseDto>> getUsersByRole(@ApiParam(name = "roleId", value = "The role id", required = true)
public ResponseEntity<List<UserResponseDto>> getUsersByRole(@ApiParam(name = "roleId", value = "The role id", required = true, example = "1")
@PathVariable("roleId") Long roleId) {
Optional<Role> roleOptional = roleService.getOneById(roleId);
if (!roleOptional.isPresent()) {
Expand Down
Loading

0 comments on commit f30cad8

Please sign in to comment.