From 9f0a93978c4438c53f4c54b3695e1192d2ab1566 Mon Sep 17 00:00:00 2001 From: Florian Scholdei Date: Wed, 18 Nov 2020 02:30:26 +0100 Subject: [PATCH 1/6] Add examples to core resources and create DTO adapted to schemata --- .../scm/api/v2/resources/ApiKeyResource.java | 19 +++++- .../api/v2/resources/BranchRootResource.java | 19 +++++- .../scm/api/v2/resources/ConfigResource.java | 20 +++++- .../scm/api/v2/resources/CreateApiKeyDto.java | 44 +++++++++++++ .../api/v2/resources/CreateRepositoryDto.java | 57 ++++++++++++++++ .../v2/resources/CreateRepositoryRoleDto.java | 47 ++++++++++++++ .../scm/api/v2/resources/CreateUserDto.java | 54 +++++++++++++++ .../scm/api/v2/resources/MeResource.java | 19 +++++- .../NamespacePermissionResource.java | 42 ++++++++++-- .../RepositoryCollectionResource.java | 19 +++++- .../RepositoryPermissionRootResource.java | 35 +++++++++- .../api/v2/resources/RepositoryResource.java | 19 +++++- .../RepositoryRoleCollectionResource.java | 19 +++++- .../v2/resources/RepositoryRoleResource.java | 19 +++++- .../scm/api/v2/resources/UpdateConfigDto.java | 65 +++++++++++++++++++ .../api/v2/resources/UpdateRepositoryDto.java | 57 ++++++++++++++++ .../v2/resources/UpdateRepositoryRoleDto.java | 49 ++++++++++++++ .../scm/api/v2/resources/UpdateUserDto.java | 57 ++++++++++++++++ .../v2/resources/UserCollectionResource.java | 19 +++++- .../v2/resources/UserPermissionResource.java | 19 +++++- .../scm/api/v2/resources/UserResource.java | 53 ++++++++++++++- 21 files changed, 731 insertions(+), 20 deletions(-) create mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateApiKeyDto.java create mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryDto.java create mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryRoleDto.java create mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateUserDto.java create mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateConfigDto.java create mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryDto.java create mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryRoleDto.java create mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateUserDto.java diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyResource.java index e2faac3e37..2f971a435d 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyResource.java @@ -28,7 +28,9 @@ import de.otto.edison.hal.HalRepresentation; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.headers.Header; import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import sonia.scm.ContextEntry; import sonia.scm.security.ApiKey; @@ -131,7 +133,22 @@ public class ApiKeyResource { @Path("") @Consumes(VndMediaType.API_KEY) @Produces(MediaType.TEXT_PLAIN) - @Operation(summary = "Create new api key for the current user", description = "Creates a new api key for the given user with the role specified in the given key.", tags = "User") + @Operation( + summary = "Create new api key for the current user", + description = "Creates a new api key for the given user with the role specified in the given key.", + tags = "User", + requestBody = @RequestBody( + content = @Content( + mediaType = VndMediaType.API_KEY, + schema = @Schema(implementation = CreateApiKeyDto.class), + examples = @ExampleObject( + name = "Create a new api key named readKey with READ permission role", + value = "{\n \"displayName\":\"readKey\",\n \"permissionRole\":\"READ\"\n}", + summary = "Create new api key" + ) + ) + ) + ) @ApiResponse( responseCode = "201", description = "create success", diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/BranchRootResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/BranchRootResource.java index a5ce4d951e..2988ef3697 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/BranchRootResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/BranchRootResource.java @@ -28,7 +28,9 @@ import com.google.common.base.Strings; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.headers.Header; import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import sonia.scm.PageResult; import sonia.scm.repository.Branch; @@ -209,7 +211,22 @@ public class BranchRootResource { @POST @Path("") @Consumes(VndMediaType.BRANCH_REQUEST) - @Operation(summary = "Create branch", description = "Creates a new branch.", tags = "Repository") + @Operation( + summary = "Create branch", + description = "Creates a new branch.", + tags = "Repository", + requestBody = @RequestBody( + content = @Content( + mediaType = VndMediaType.BRANCH_REQUEST, + schema = @Schema(implementation = BranchRequestDto.class), + examples = @ExampleObject( + name = "Branch a new develop branch from main", + value = "{\n \"parent\":\"main\",\n \"name\":\"develop\"\n}", + summary = "Create a branch" + ) + ) + ) + ) @ApiResponse( responseCode = "201", description = "create success", diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigResource.java index 5575af06fb..35c363619b 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigResource.java @@ -29,7 +29,9 @@ import io.swagger.v3.oas.annotations.OpenAPIDefinition; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; import sonia.scm.config.ConfigurationPermissions; @@ -45,6 +47,7 @@ import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.function.Consumer; @@ -122,7 +125,22 @@ public class ConfigResource { @PUT @Path("") @Consumes(VndMediaType.CONFIG) - @Operation(summary = "Update instance configuration", description = "Modifies the instance configuration.", tags = "Instance configuration") + @Operation( + summary = "Update instance configuration", + description = "Modifies the instance configuration.", + tags = "Instance configuration", + requestBody = @RequestBody( + content = @Content( + mediaType = VndMediaType.CONFIG, + schema = @Schema(implementation = UpdateConfigDto.class), + examples = @ExampleObject( + name = "Overwrites current configuration with this one", + value = "{\n \"realmDescription\":\"SONIA :: SCM-Manager\",\n \"dateFormat\":\"YYYY-MM-DD HH:mm:ss\",\n \"baseUrl\":\"http://localhost:8081/scm\",\n \"loginAttemptLimit\":-1,\n \"pluginUrl\":\"https://plugin-center-api.scm-manager.org/api/v1/plugins/{version}?os={os}&arch={arch}\",\n \"loginAttemptLimitTimeout\":500,\n \"namespaceStrategy\":\"CustomNamespaceStrategy\",\n \"loginInfoUrl\":\"https://login-info.scm-manager.org/api/v1/login-info\",\n \"releaseFeedUrl\":\"https://scm-manager.org/download/rss.xml\",\n \"mailDomainName\":\"scm-manager.local\"\n}", + summary = "Simple update configuration" + ) + ) + ) + ) @ApiResponse(responseCode = "204", description = "update success") @ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials") @ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"configuration:write\" privilege") diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateApiKeyDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateApiKeyDto.java new file mode 100644 index 0000000000..a78719d081 --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateApiKeyDto.java @@ -0,0 +1,44 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import javax.validation.constraints.NotEmpty; + +/** + * This class is currently only used in the openapi scheme + */ +@Getter +@Setter +@NoArgsConstructor +public class CreateApiKeyDto { + @NotEmpty + private String displayName; + @NotEmpty + private String permissionRole; +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryDto.java new file mode 100644 index 0000000000..420785449c --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryDto.java @@ -0,0 +1,57 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import sonia.scm.util.ValidationUtil; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Pattern; +import java.time.Instant; +import java.util.List; + +/** + * This class is currently only used in the openapi scheme + */ +@Getter +@Setter +@NoArgsConstructor +public class CreateRepositoryDto { + private String namespace; + @Pattern(regexp = ValidationUtil.REGEX_REPOSITORYNAME) + private String name; + @NotEmpty + private String type; + @Email + private String contact; + private String description; + private List healthCheckFailures; + @JsonInclude(JsonInclude.Include.NON_NULL) + private Instant lastModified; +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryRoleDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryRoleDto.java new file mode 100644 index 0000000000..6b70fb3f22 --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryRoleDto.java @@ -0,0 +1,47 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import javax.validation.constraints.NotEmpty; +import java.util.Collection; + +/** + * This class is currently only used in the openapi scheme + */ +@Getter +@Setter +@NoArgsConstructor +public class CreateRepositoryRoleDto { + @NotEmpty + private String name; + private boolean system; + @NoBlankStrings @NotEmpty + private Collection verbs; + private String type; +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateUserDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateUserDto.java new file mode 100644 index 0000000000..54af7edb99 --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateUserDto.java @@ -0,0 +1,54 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import sonia.scm.util.ValidationUtil; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Pattern; + +/** + * This class is currently only used in the openapi scheme + */ +@NoArgsConstructor @Getter @Setter +public class CreateUserDto { + @Pattern(regexp = ValidationUtil.REGEX_NAME) + private String name; + @NotEmpty + private String displayName; + @JsonInclude(JsonInclude.Include.NON_NULL) + @Email + private String mail; + private boolean external; + @JsonInclude(JsonInclude.Include.NON_NULL) + private String password; + private boolean active; + private String type; +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/MeResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/MeResource.java index d93acf0159..966a9c719f 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/MeResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/MeResource.java @@ -27,7 +27,9 @@ package sonia.scm.api.v2.resources; import io.swagger.v3.oas.annotations.OpenAPIDefinition; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; import org.apache.shiro.authc.credential.PasswordService; @@ -105,7 +107,22 @@ public class MeResource { @PUT @Path("password") @Consumes(VndMediaType.PASSWORD_CHANGE) - @Operation(summary = "Change password", description = "Change password of the current user.", tags = "Current user") + @Operation( + summary = "Change password", + description = "Change password of the current user.", + tags = "Current user", + requestBody = @RequestBody( + content = @Content( + mediaType = VndMediaType.PASSWORD_CHANGE, + schema = @Schema(implementation = PasswordChangeDto.class), + examples = @ExampleObject( + name = "Change password to a more difficult one", + value = "{ \"oldPassword\":\"scmadmin\",\n \"newPassword\":\"5cm4dm1n\"\n}", + summary = "Simple change password" + ) + ) + ) + ) @ApiResponse(responseCode = "204", description = "update success") @ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials") @ApiResponse( diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/NamespacePermissionResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/NamespacePermissionResource.java index 3fbb2a6a13..0d43f72484 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/NamespacePermissionResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/NamespacePermissionResource.java @@ -28,7 +28,9 @@ import de.otto.edison.hal.HalRepresentation; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.headers.Header; import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import lombok.extern.slf4j.Slf4j; import sonia.scm.NotFoundException; @@ -89,7 +91,22 @@ public class NamespacePermissionResource { @POST @Path("") @Consumes(VndMediaType.REPOSITORY_PERMISSION) - @Operation(summary = "Create namespace-specific permission", description = "Adds a new permission to the namespace for the user or group.", tags = {"Namespace", "Permissions"}) + @Operation( + summary = "Create namespace-specific permission", + description = "Adds a new permission to the namespace for the user or group.", + tags = {"Namespace", "Permissions"}, + requestBody = @RequestBody( + content = @Content( + mediaType = VndMediaType.REPOSITORY_PERMISSION, + schema = @Schema(implementation = PermissionListDto.class), + examples = @ExampleObject( + name = "Add read permissions for repositories and pull requests to manager group", + value = "{\n \"name\":\"manager\",\n \"verbs\":[\"read\",\"readPullRequest\"],\n \"groupPermission\":true\n}", + summary = "Add a permission" + ) + ) + ) + ) @ApiResponse( responseCode = "201", description = "creates", @@ -135,7 +152,7 @@ public class NamespacePermissionResource { @GET @Path("{permission-name}") @Produces(VndMediaType.REPOSITORY_PERMISSION) - @Operation(summary = "Get single repository-specific permission", description = "Get the searched permission with permission name related to a repository.", tags = {"Repository", "Permissions"}) + @Operation(summary = "Get single namespace-specific permission", description = "Get the searched permission with permission name related to a repository.", tags = {"Namespace", "Permissions"}) @ApiResponse( responseCode = "200", description = "success", @@ -180,7 +197,7 @@ public class NamespacePermissionResource { @GET @Path("") @Produces(VndMediaType.REPOSITORY_PERMISSION) - @Operation(summary = "List of namespace-specific permissions", description = "Get all permissions related to a namespace.", tags = {"Repository", "Permissions"}) + @Operation(summary = "List of namespace-specific permissions", description = "Get all permissions related to a namespace.", tags = {"Namespace", "Permissions"}) @ApiResponse( responseCode = "200", description = "success", @@ -220,7 +237,22 @@ public class NamespacePermissionResource { @PUT @Path("{permission-name}") @Consumes(VndMediaType.REPOSITORY_PERMISSION) - @Operation(summary = "Update repository-specific permission", description = "Update a permission to the user or group managed by the repository.", tags = {"Repository", "Permissions"}) + @Operation( + summary = "Update namespace-specific permission", + description = "Update a permission to the user or group managed by the repository.", + tags = {"Namespace", "Permissions"}, + requestBody = @RequestBody( + content = @Content( + mediaType = VndMediaType.REPOSITORY_PERMISSION, + schema = @Schema(implementation = PermissionListDto.class), + examples = @ExampleObject( + name = "Update permissions of manager group", + value = "{\n \"name\":\"manager\",\n \"verbs\":[\"read\",\"permissionRead\",\"readPullRequest\"],\n \"groupPermission\":true\n}", + summary = "Update a permission" + ) + ) + ) + ) @ApiResponse(responseCode = "204", description = "update success") @ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials") @ApiResponse( @@ -266,7 +298,7 @@ public class NamespacePermissionResource { */ @DELETE @Path("{permission-name}") - @Operation(summary = "Delete repository-specific permission", description = "Delete a permission with the given name.", tags = {"Repository", "Permissions"}) + @Operation(summary = "Delete namespace-specific permission", description = "Delete a permission with the given name.", tags = {"Namespace", "Permissions"}) @ApiResponse(responseCode = "204", description = "delete success or nothing to delete") @ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials") @ApiResponse(responseCode = "403", description = "not authorized") diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryCollectionResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryCollectionResource.java index 72330587ee..f60fa6d6ff 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryCollectionResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryCollectionResource.java @@ -27,7 +27,9 @@ package sonia.scm.api.v2.resources; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.headers.Header; import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.apache.shiro.SecurityUtils; import sonia.scm.repository.Repository; @@ -160,7 +162,22 @@ public class RepositoryCollectionResource { @POST @Path("") @Consumes(VndMediaType.REPOSITORY) - @Operation(summary = "Create repository", description = "Creates a new repository.", tags = "Repository") + @Operation( + summary = "Create repository", + description = "Creates a new repository.", + tags = "Repository", + requestBody = @RequestBody( + content = @Content( + mediaType = VndMediaType.REPOSITORY, + schema = @Schema(implementation = CreateRepositoryDto.class), + examples = @ExampleObject( + name = "Create a new git repository named scm-manager in scmadmin namespace", + value = "{\n \"namespace\":\"scmadmin\",\n \"name\":\"scm-manager\",\n \"type\":\"git\"\n}", + summary = "Create a simple git repository" + ) + ) + ) + ) @ApiResponse( responseCode = "201", description = "create success", diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryPermissionRootResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryPermissionRootResource.java index 185ed8df07..48d17279e3 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryPermissionRootResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryPermissionRootResource.java @@ -27,7 +27,9 @@ package sonia.scm.api.v2.resources; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.headers.Header; import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import lombok.extern.slf4j.Slf4j; import sonia.scm.AlreadyExistsException; @@ -91,7 +93,22 @@ public class RepositoryPermissionRootResource { @POST @Path("") @Consumes(VndMediaType.REPOSITORY_PERMISSION) - @Operation(summary = "Create repository-specific permission", description = "Adds a new permission to the user or group managed by the repository.", tags = {"Repository", "Permissions"}) + @Operation( + summary = "Create repository-specific permission", + description = "Adds a new permission to the user or group managed by the repository.", + tags = {"Repository", "Permissions"}, + requestBody = @RequestBody( + content = @Content( + mediaType = VndMediaType.REPOSITORY_PERMISSION, + schema = @Schema(implementation = PermissionListDto.class), + examples = @ExampleObject( + name = "Add read permissions for repository and pull requests to manager group", + value = "{\n \"name\":\"manager\",\n \"verbs\":[\"read\",\"readPullRequest\"],\n \"groupPermission\":true\n}", + summary = "Add a permission" + ) + ) + ) + ) @ApiResponse( responseCode = "201", description = "creates", @@ -228,7 +245,21 @@ public class RepositoryPermissionRootResource { @PUT @Path("{permission-name}") @Consumes(VndMediaType.REPOSITORY_PERMISSION) - @Operation(summary = "Update repository-specific permission", description = "Update a permission to the user or group managed by the repository.", tags = {"Repository", "Permissions"}) + @Operation( + summary = "Update repository-specific permission", + description = "Update a permission to the user or group managed by the repository.", + tags = {"Repository", "Permissions"}, + requestBody = @RequestBody( + content = @Content( + mediaType = VndMediaType.REPOSITORY_PERMISSION, + schema = @Schema(implementation = PermissionListDto.class), + examples = @ExampleObject( + name = "Update permissions of manager group", + value = "{\n \"name\":\"manager\",\n \"verbs\":[\"read\",\"permissionRead\",\"readPullRequest\"],\n \"groupPermission\":true\n}", + summary = "Update a permission" + ) + ) + )) @ApiResponse(responseCode = "204", description = "update success") @ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials") @ApiResponse( diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryResource.java index 12cc362517..50bb7764ca 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryResource.java @@ -26,7 +26,9 @@ package sonia.scm.api.v2.resources; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import sonia.scm.repository.NamespaceAndName; import sonia.scm.repository.Repository; @@ -151,7 +153,22 @@ public class RepositoryResource { @PUT @Path("") @Consumes(VndMediaType.REPOSITORY) - @Operation(summary = "Update repository", description = "Modifies the repository for the given namespace and name.", tags = "Repository") + @Operation( + summary = "Update repository", + description = "Modifies the repository for the given namespace and name.", + tags = "Repository", + requestBody = @RequestBody( + content = @Content( + mediaType = VndMediaType.REPOSITORY, + schema = @Schema(implementation = UpdateRepositoryDto.class), + examples = @ExampleObject( + name = "Update repository description", + value = "{\n \"namespace\":\"scmadmin\",\n \"name\":\"scm-manager\",\n \"description\":\"The easiest way to share and manage your Git, Mercurial and Subversion repositories.\",\n \"type\":\"git\",\n \"lastModified\":\"2020-06-05T14:42:49.000Z\"\n}", + summary = "Update a repository" + ) + ) + ) + ) @ApiResponse(responseCode = "204", description = "update success") @ApiResponse(responseCode = "400", description = "invalid body, e.g. illegal change of namespace or name") @ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials") diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleCollectionResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleCollectionResource.java index 2d65720ca2..50c4c0ede7 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleCollectionResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleCollectionResource.java @@ -27,7 +27,9 @@ package sonia.scm.api.v2.resources; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.headers.Header; import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import sonia.scm.repository.RepositoryRole; import sonia.scm.repository.RepositoryRoleManager; @@ -114,7 +116,22 @@ public class RepositoryRoleCollectionResource { @POST @Path("") @Consumes(VndMediaType.REPOSITORY_ROLE) - @Operation(summary = "Create repository role", description = "Creates a new repository role.", tags = "Repository role") + @Operation( + summary = "Create repository role", + description = "Creates a new repository role.", + tags = "Repository role", + requestBody = @RequestBody( + content = @Content( + mediaType = VndMediaType.REPOSITORY_ROLE, + schema = @Schema(implementation = CreateRepositoryRoleDto.class), + examples = @ExampleObject( + name = "Create repository role named hero with read and delete repository permission", + value = "{\n \"name\":\"hero\",\n \"system\":false,\n \"verbs\":[\"read\",\"delete\"]\n}", + summary = "Add a repository role" + ) + ) + ) + ) @ApiResponse( responseCode = "201", description = "create success", diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleResource.java index c76e8b4aa6..31179f0c2d 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleResource.java @@ -26,7 +26,9 @@ package sonia.scm.api.v2.resources; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import sonia.scm.repository.RepositoryRole; import sonia.scm.repository.RepositoryRoleManager; @@ -128,7 +130,22 @@ public class RepositoryRoleResource { @PUT @Path("") @Consumes(VndMediaType.REPOSITORY_ROLE) - @Operation(summary = "Update repository role", description = "Modifies the repository role for the given name.", tags = "Repository role") + @Operation( + summary = "Update repository role", + description = "Modifies the repository role for the given name.", + tags = "Repository role", + requestBody = @RequestBody( + content = @Content( + mediaType = VndMediaType.REPOSITORY_ROLE, + schema = @Schema(implementation = UpdateRepositoryRoleDto.class), + examples = @ExampleObject( + name = "Update repository role named hero with this verbs", + value = "{\n \"name\":\"hero\",\n \"system\":false,\n \"verbs\":[\"read\",\"pull\",\"write\",\"push\",\"delete\"],\n \"lastModified\":\"2020-06-05T14:42:49.000Z\"\n}", + summary = "Update a repository role" + ) + ) + ) + ) @ApiResponse(responseCode = "204", description = "update success") @ApiResponse(responseCode = "400", description = "invalid body, e.g. illegal change of repository role name") @ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials") diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateConfigDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateConfigDto.java new file mode 100644 index 0000000000..7574210e3f --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateConfigDto.java @@ -0,0 +1,65 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import sonia.scm.security.AnonymousMode; + +import java.util.Set; + +/** + * This class is currently only used in the openapi scheme + */ +@NoArgsConstructor +@Getter +@Setter +public class UpdateConfigDto { + + private String proxyPassword; + private int proxyPort; + private String proxyServer; + private String proxyUser; + private boolean enableProxy; + private String realmDescription; + private boolean disableGroupingGrid; + private String dateFormat; + private boolean anonymousAccessEnabled; + private AnonymousMode anonymousMode; + private String baseUrl; + private boolean forceBaseUrl; + private int loginAttemptLimit; + private Set proxyExcludes; + private boolean skipFailedAuthenticators; + private String pluginUrl; + private long loginAttemptLimitTimeout; + private boolean enabledXsrfProtection; + private boolean enabledUserConverter; + private String namespaceStrategy; + private String loginInfoUrl; + private String releaseFeedUrl; + private String mailDomainName; +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryDto.java new file mode 100644 index 0000000000..2dc2d89a1c --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryDto.java @@ -0,0 +1,57 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import sonia.scm.util.ValidationUtil; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Pattern; +import java.time.Instant; +import java.util.List; + +/** + * This class is currently only used in the openapi scheme + */ +@Getter +@Setter +@NoArgsConstructor +public class UpdateRepositoryDto { + private String namespace; + @Pattern(regexp = ValidationUtil.REGEX_REPOSITORYNAME) + private String name; + @NotEmpty + private String type; + @Email + private String contact; + private String description; + private List healthCheckFailures; + @JsonInclude(JsonInclude.Include.NON_NULL) + private Instant lastModified; +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryRoleDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryRoleDto.java new file mode 100644 index 0000000000..81193195fe --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryRoleDto.java @@ -0,0 +1,49 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import javax.validation.constraints.NotEmpty; +import java.time.Instant; +import java.util.Collection; + +/** + * This class is currently only used in the openapi scheme + */ +@Getter +@Setter +@NoArgsConstructor +public class UpdateRepositoryRoleDto { + @NotEmpty + private String name; + private boolean system; + @NoBlankStrings @NotEmpty + private Collection verbs; + private String type; + private Instant lastModified; +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateUserDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateUserDto.java new file mode 100644 index 0000000000..28e011f4cd --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateUserDto.java @@ -0,0 +1,57 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import sonia.scm.util.ValidationUtil; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Pattern; +import java.time.Instant; + +/** + * This class is currently only used in the openapi scheme + */ +@NoArgsConstructor @Getter @Setter +public class UpdateUserDto { + @Pattern(regexp = ValidationUtil.REGEX_NAME) + private String name; + @NotEmpty + private String displayName; + @JsonInclude(JsonInclude.Include.NON_NULL) + @Email + private String mail; + private boolean external; + @JsonInclude(JsonInclude.Include.NON_NULL) + private String password; + private boolean active; + private String type; + @JsonInclude(JsonInclude.Include.NON_NULL) + private Instant lastModified; +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserCollectionResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserCollectionResource.java index 1b604a11f2..a81aa3fc7a 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserCollectionResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserCollectionResource.java @@ -27,7 +27,9 @@ package sonia.scm.api.v2.resources; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.headers.Header; import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.apache.shiro.authc.credential.PasswordService; import sonia.scm.search.SearchRequest; @@ -125,7 +127,22 @@ public class UserCollectionResource { @POST @Path("") @Consumes(VndMediaType.USER) - @Operation(summary = "Create user", description = "Creates a new user.", tags = "User") + @Operation( + summary = "Create user", + description = "Creates a new user.", + tags = "User", + requestBody = @RequestBody( + content = @Content( + mediaType = VndMediaType.USER, + schema = @Schema(implementation = CreateUserDto.class), + examples = @ExampleObject( + name = "Create an internal user.", + value = "{\n \"name\":\"mustermann\",\n \"displayName\":\"Max Mustermann\",\n \"mail\":\"m.mustermann@scm-manager.org\",\n \"external\":false,\n \"password\":\"muster42*\",\n \"active\":true\n}", + summary = "Create a simple user" + ) + ) + ) + ) @ApiResponse( responseCode = "201", description = "create success", diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserPermissionResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserPermissionResource.java index fe2b5d3596..ee27b26e0d 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserPermissionResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserPermissionResource.java @@ -26,7 +26,9 @@ package sonia.scm.api.v2.resources; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import sonia.scm.security.PermissionAssigner; import sonia.scm.security.PermissionDescriptor; @@ -106,7 +108,22 @@ public class UserPermissionResource { @PUT @Path("") @Consumes(VndMediaType.PERMISSION_COLLECTION) - @Operation(summary = "Update user permissions", description = "Sets permissions for a user. Overwrites all existing permissions.", tags = {"User", "Permissions"}) + @Operation( + summary = "Update user permissions", + description = "Sets permissions for a user. Overwrites all existing permissions.", + tags = {"User", "Permissions"}, + requestBody = @RequestBody( + content = @Content( + mediaType = VndMediaType.PERMISSION_COLLECTION, + schema = @Schema(implementation = PermissionListDto.class), + examples = @ExampleObject( + name = "Add read permissions for all repositories and pull requests", + value = "{\n \"permissions\":[\"repository:read,pull:*\",\"repository:readPullRequest:*\"]\n}", + summary = "Simple update user permissions" + ) + ) + ) + ) @ApiResponse(responseCode = "204", description = "update success") @ApiResponse(responseCode = "400", description = "invalid body") @ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials") diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserResource.java index 679224cde8..c4a6d08a28 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserResource.java @@ -26,7 +26,9 @@ package sonia.scm.api.v2.resources; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.apache.shiro.authc.credential.PasswordService; import sonia.scm.user.User; @@ -137,7 +139,22 @@ public class UserResource { @PUT @Path("") @Consumes(VndMediaType.USER) - @Operation(summary = "Update user", description = "Modifies the user for the given id.", tags = "User") + @Operation( + summary = "Update user", + description = "Modifies the user for the given id.", + tags = "User", + requestBody = @RequestBody( + content = @Content( + mediaType = VndMediaType.USER, + schema = @Schema(implementation = UpdateUserDto.class), + examples = @ExampleObject( + name = "Update the email address of user mustermann.", + value = "{\n \"name\":\"mustermann\",\n \"displayName\":\"Max Mustermann\",\n \"mail\":\"maxmustermann@scm-manager.org\",\n \"external\":false,\n \"active\":true,\n \"lastModified\":\"2020-06-05T14:42:49.000Z\"\n}", + summary = "Update a user" + ) + ) + ) + ) @ApiResponse(responseCode = "204", description = "update success") @ApiResponse(responseCode = "400", description = "invalid body, e.g. illegal change of id/user name") @ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials") @@ -168,7 +185,22 @@ public class UserResource { @PUT @Path("password") @Consumes(VndMediaType.PASSWORD_OVERWRITE) - @Operation(summary = "Modifies a user password", description = "Lets admins modifies the user password for the given id.", tags = "User") + @Operation( + summary = "Modifies a user password", + description = "Lets admins modifies the user password for the given id.", + tags = "User", + requestBody = @RequestBody( + content = @Content( + mediaType = VndMediaType.PASSWORD_OVERWRITE, + schema = @Schema(implementation = PasswordOverwriteDto.class), + examples = @ExampleObject( + name = "Overwrites current password with a more difficult one", + value = "{ \"newPassword\":\"5cm4dm1n\"\n}", + summary = "Set new password" + ) + ) + ) + ) @ApiResponse(responseCode = "204", description = "update success") @ApiResponse(responseCode = "400", description = "invalid body, e.g. the user type is not xml or the given oldPassword do not match the stored one") @ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials") @@ -199,7 +231,22 @@ public class UserResource { @PUT @Path("convert-to-internal") @Consumes(VndMediaType.USER) - @Operation(summary = "Converts an external user to internal", description = "Converts an external user to an internal one and set the new password.", tags = "User") + @Operation( + summary = "Converts an external user to internal", + description = "Converts an external user to an internal one and set the new password.", + tags = "User", + requestBody = @RequestBody( + content = @Content( + mediaType = VndMediaType.USER, + schema = @Schema(implementation = PasswordOverwriteDto.class), + examples = @ExampleObject( + name = "Converts an external user to an internal one and set the new password.", + value = "{ \"newPassword\":\"5cm4dm1n\"\n}", + summary = "Simple converts an user" + ) + ) + ) + ) @ApiResponse(responseCode = "204", description = "update success") @ApiResponse(responseCode = "400", description = "invalid body, e.g. the new password is missing") @ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials") From 3384707517e2d611ee8e54fb6a25b77f68c2bc88 Mon Sep 17 00:00:00 2001 From: Florian Scholdei Date: Wed, 18 Nov 2020 11:34:39 +0100 Subject: [PATCH 2/6] Add examples to scm-plugins resources and create DTO adapted to schemata --- .../api/v2/resources/GitConfigResource.java | 20 +++++++- .../GitRepositoryConfigResource.java | 19 ++++++- .../api/v2/resources/UpdateGitConfigDto.java | 51 +++++++++++++++++++ .../UpdateGitRepositoryConfigDto.java | 39 ++++++++++++++ .../HgConfigAutoConfigurationResource.java | 19 ++++++- .../api/v2/resources/HgConfigResource.java | 20 +++++++- .../api/v2/resources/UpdateHgConfigDto.java | 47 +++++++++++++++++ .../api/v2/resources/SvnConfigResource.java | 20 +++++++- .../api/v2/resources/UpdateSvnConfigDto.java | 42 +++++++++++++++ 9 files changed, 272 insertions(+), 5 deletions(-) create mode 100644 scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitConfigDto.java create mode 100644 scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitRepositoryConfigDto.java create mode 100644 scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateHgConfigDto.java create mode 100644 scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateSvnConfigDto.java diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigResource.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigResource.java index 71d97f27be..e366a35abb 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigResource.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigResource.java @@ -27,7 +27,9 @@ package sonia.scm.api.v2.resources; import io.swagger.v3.oas.annotations.OpenAPIDefinition; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; import sonia.scm.config.ConfigurationPermissions; @@ -116,7 +118,23 @@ public class GitConfigResource { @PUT @Path("") @Consumes(GitVndMediaType.GIT_CONFIG) - @Operation(summary = "Modify git configuration", description = "Modifies the global git configuration.", tags = "Git", operationId = "git_put_config") + @Operation( + summary = "Modify git configuration", + description = "Modifies the global git configuration.", + tags = "Git", + operationId = "git_put_config", + requestBody = @RequestBody( + content = @Content( + mediaType = GitVndMediaType.GIT_CONFIG, + schema = @Schema(implementation = UpdateGitConfigDto.class), + examples = @ExampleObject( + name = "Overwrites current configuration with this one.", + value = "{\n \"disabled\":false,\n \"gcExpression\":null,\n \"nonFastForwardDisallowed\":false,\n \"defaultBranch\":\"main\"\n}", + summary = "Simple update configuration" + ) + ) + ) + ) @ApiResponse(responseCode = "204", description = "update success") @ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials") @ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"configuration:write:git\" privilege") diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitRepositoryConfigResource.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitRepositoryConfigResource.java index 3aa348d13a..81e8b79d60 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitRepositoryConfigResource.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitRepositoryConfigResource.java @@ -26,7 +26,9 @@ package sonia.scm.api.v2.resources; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -106,7 +108,22 @@ public class GitRepositoryConfigResource { @PUT @Path("/") @Consumes(GitVndMediaType.GIT_REPOSITORY_CONFIG) - @Operation(summary = "Modifies git repository configuration", description = "Modifies the repository related git configuration.", tags = "Git") + @Operation( + summary = "Modifies git repository configuration", + description = "Modifies the repository related git configuration.", + tags = "Git", + requestBody = @RequestBody( + content = @Content( + mediaType = GitVndMediaType.GIT_REPOSITORY_CONFIG, + schema = @Schema(implementation = UpdateGitRepositoryConfigDto.class), + examples = @ExampleObject( + name = "Overwrites current configuration with this one.", + value = "{\n \"defaultBranch\":\"main\"\n}", + summary = "Simple update configuration" + ) + ) + ) + ) @ApiResponse( responseCode = "204", description = "update success" diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitConfigDto.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitConfigDto.java new file mode 100644 index 0000000000..5893e93a40 --- /dev/null +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitConfigDto.java @@ -0,0 +1,51 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.hibernate.validator.constraints.Length; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Pattern; + +import static sonia.scm.repository.Branch.VALID_BRANCH_NAMES; + +/** + * This class is currently only used in the openapi scheme + */ +@NoArgsConstructor +@Getter +@Setter +public class UpdateGitConfigDto { + private boolean disabled = false; + private String gcExpression; + private boolean nonFastForwardDisallowed; + @NotEmpty + @Length(min = 1, max = 100) + @Pattern(regexp = VALID_BRANCH_NAMES) + private String defaultBranch; +} diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitRepositoryConfigDto.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitRepositoryConfigDto.java new file mode 100644 index 0000000000..491208fae9 --- /dev/null +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitRepositoryConfigDto.java @@ -0,0 +1,39 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/** + * This class is currently only used in the openapi scheme + */ +@Getter +@Setter +@NoArgsConstructor +public class UpdateGitRepositoryConfigDto { + private String defaultBranch; +} diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/HgConfigAutoConfigurationResource.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/HgConfigAutoConfigurationResource.java index 2d8c385128..70eb367d3c 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/HgConfigAutoConfigurationResource.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/HgConfigAutoConfigurationResource.java @@ -27,7 +27,9 @@ package sonia.scm.api.v2.resources; import com.google.inject.Inject; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import sonia.scm.config.ConfigurationPermissions; import sonia.scm.repository.HgConfig; @@ -83,7 +85,22 @@ public class HgConfigAutoConfigurationResource { @PUT @Path("") @Consumes(HgVndMediaType.CONFIG) - @Operation(summary = "Modifies hg configuration and installs hg binary", description = "Modifies the mercurial config and installs the mercurial binary.", tags = "Mercurial") + @Operation( + summary = "Modifies hg configuration and installs hg binary", + description = "Modifies the mercurial config and installs the mercurial binary.", + tags = "Mercurial", + requestBody = @RequestBody( + content = @Content( + mediaType = HgVndMediaType.CONFIG, + schema = @Schema(implementation = UpdateHgConfigDto.class), + examples = @ExampleObject( + name = "Overwrites current configuration with this one and installs the mercurial binary.", + value = "{\n \"disabled\":false,\n \"hgBinary\":\"hg\",\n \"pythonBinary\":\"python\",\n \"pythonPath\":\"\",\n \"encoding\":\"UTF-8\",\n \"useOptimizedBytecode\":false,\n \"showRevisionInId\":false,\n \"disableHookSSLValidation\":false,\n \"enableHttpPostArgs\":false\n}", + summary = "Simple update configuration and installs binary" + ) + ) + ) + ) @ApiResponse( responseCode = "204", description = "update success" diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/HgConfigResource.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/HgConfigResource.java index cb2ac532ab..0c715ce8c3 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/HgConfigResource.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/HgConfigResource.java @@ -27,7 +27,9 @@ package sonia.scm.api.v2.resources; import io.swagger.v3.oas.annotations.OpenAPIDefinition; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; import sonia.scm.config.ConfigurationPermissions; @@ -121,7 +123,23 @@ public class HgConfigResource { @PUT @Path("") @Consumes(HgVndMediaType.CONFIG) - @Operation(summary = "Modify hg configuration", description = "Modifies the global mercurial configuration.", tags = "Mercurial", operationId = "hg_put_config") + @Operation( + summary = "Modify hg configuration", + description = "Modifies the global mercurial configuration.", + tags = "Mercurial", + operationId = "hg_put_config", + requestBody = @RequestBody( + content = @Content( + mediaType = HgVndMediaType.CONFIG, + schema = @Schema(implementation = UpdateHgConfigDto.class), + examples = @ExampleObject( + name = "Overwrites current configuration with this one.", + value = "{\n \"disabled\":false,\n \"hgBinary\":\"hg\",\n \"pythonBinary\":\"python\",\n \"pythonPath\":\"\",\n \"encoding\":\"UTF-8\",\n \"useOptimizedBytecode\":false,\n \"showRevisionInId\":false,\n \"disableHookSSLValidation\":false,\n \"enableHttpPostArgs\":false\n}", + summary = "Simple update configuration" + ) + ) + ) + ) @ApiResponse( responseCode = "204", description = "update success" diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateHgConfigDto.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateHgConfigDto.java new file mode 100644 index 0000000000..18ac833c76 --- /dev/null +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateHgConfigDto.java @@ -0,0 +1,47 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/** + * This class is currently only used in the openapi scheme + */ +@NoArgsConstructor +@Getter +@Setter +public class UpdateHgConfigDto { + private boolean disabled; + private String hgBinary; + private String pythonBinary; + private String pythonPath; + private String encoding; + private boolean useOptimizedBytecode; + private boolean showRevisionInId; + private boolean disableHookSSLValidation; + private boolean enableHttpPostArgs; +} diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/SvnConfigResource.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/SvnConfigResource.java index 3e45bb6c43..8197c87b7b 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/SvnConfigResource.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/SvnConfigResource.java @@ -27,7 +27,9 @@ package sonia.scm.api.v2.resources; import io.swagger.v3.oas.annotations.OpenAPIDefinition; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; import sonia.scm.config.ConfigurationPermissions; @@ -112,7 +114,23 @@ public class SvnConfigResource { @PUT @Path("") @Consumes(SvnVndMediaType.SVN_CONFIG) - @Operation(summary = "Modify svn configuration", description = "Modifies the global subversion configuration.", tags = "Subversion", operationId = "svn_put_config") + @Operation( + summary = "Modify svn configuration", + description = "Modifies the global subversion configuration.", + tags = "Subversion", + operationId = "svn_put_config", + requestBody = @RequestBody( + content = @Content( + mediaType = SvnVndMediaType.SVN_CONFIG, + schema = @Schema(implementation = UpdateSvnConfigDto.class), + examples = @ExampleObject( + name = "Overwrites current configuration with this one.", + value = "{\n \"disabled\":false,\n \"compatibility\":\"NONE\",\n \"enabledGZip\":false\n}", + summary = "Simple update configuration" + ) + ) + ) + ) @ApiResponse( responseCode = "204", description = "update success" diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateSvnConfigDto.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateSvnConfigDto.java new file mode 100644 index 0000000000..af140648bd --- /dev/null +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateSvnConfigDto.java @@ -0,0 +1,42 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import sonia.scm.repository.Compatibility; + +/** + * This class is currently only used in the openapi scheme + */ +@NoArgsConstructor +@Getter +@Setter +public class UpdateSvnConfigDto { + private boolean disabled; + private Compatibility compatibility; + private boolean enabledGZip; +} From ec87ccca9d71f42b7a153e2dbbb116b592b26b0e Mon Sep 17 00:00:00 2001 From: Florian Scholdei Date: Wed, 18 Nov 2020 11:56:56 +0100 Subject: [PATCH 3/6] Minor corrections to resources and dtos --- .../scm/api/v2/resources/ApiKeyResource.java | 2 +- .../api/v2/resources/BranchRootResource.java | 2 +- .../scm/api/v2/resources/ConfigResource.java | 2 +- .../scm/api/v2/resources/MeResource.java | 2 +- .../NamespacePermissionResource.java | 8 ++-- .../RepositoryCollectionResource.java | 4 +- .../RepositoryPermissionRootResource.java | 10 ++--- .../api/v2/resources/RepositoryRenameDto.java | 2 +- .../api/v2/resources/RepositoryResource.java | 2 +- .../RepositoryRoleCollectionResource.java | 2 +- .../v2/resources/RepositoryRoleResource.java | 2 +- .../v2/resources/UpdatePermissionListDto.java | 43 +++++++++++++++++++ .../v2/resources/UserPermissionResource.java | 4 +- .../scm/api/v2/resources/UserResource.java | 2 +- 14 files changed, 65 insertions(+), 22 deletions(-) create mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdatePermissionListDto.java diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyResource.java index 2f971a435d..bd13b7e5f6 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyResource.java @@ -142,7 +142,7 @@ public class ApiKeyResource { mediaType = VndMediaType.API_KEY, schema = @Schema(implementation = CreateApiKeyDto.class), examples = @ExampleObject( - name = "Create a new api key named readKey with READ permission role", + name = "Create a new api key named readKey with READ permission role.", value = "{\n \"displayName\":\"readKey\",\n \"permissionRole\":\"READ\"\n}", summary = "Create new api key" ) diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/BranchRootResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/BranchRootResource.java index 2988ef3697..258dd1e3e5 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/BranchRootResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/BranchRootResource.java @@ -220,7 +220,7 @@ public class BranchRootResource { mediaType = VndMediaType.BRANCH_REQUEST, schema = @Schema(implementation = BranchRequestDto.class), examples = @ExampleObject( - name = "Branch a new develop branch from main", + name = "Branch a new develop branch from main.", value = "{\n \"parent\":\"main\",\n \"name\":\"develop\"\n}", summary = "Create a branch" ) diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigResource.java index 35c363619b..f9ed6fe132 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigResource.java @@ -134,7 +134,7 @@ public class ConfigResource { mediaType = VndMediaType.CONFIG, schema = @Schema(implementation = UpdateConfigDto.class), examples = @ExampleObject( - name = "Overwrites current configuration with this one", + name = "Overwrites current configuration with this one.", value = "{\n \"realmDescription\":\"SONIA :: SCM-Manager\",\n \"dateFormat\":\"YYYY-MM-DD HH:mm:ss\",\n \"baseUrl\":\"http://localhost:8081/scm\",\n \"loginAttemptLimit\":-1,\n \"pluginUrl\":\"https://plugin-center-api.scm-manager.org/api/v1/plugins/{version}?os={os}&arch={arch}\",\n \"loginAttemptLimitTimeout\":500,\n \"namespaceStrategy\":\"CustomNamespaceStrategy\",\n \"loginInfoUrl\":\"https://login-info.scm-manager.org/api/v1/login-info\",\n \"releaseFeedUrl\":\"https://scm-manager.org/download/rss.xml\",\n \"mailDomainName\":\"scm-manager.local\"\n}", summary = "Simple update configuration" ) diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/MeResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/MeResource.java index 966a9c719f..1aad2f3d34 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/MeResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/MeResource.java @@ -116,7 +116,7 @@ public class MeResource { mediaType = VndMediaType.PASSWORD_CHANGE, schema = @Schema(implementation = PasswordChangeDto.class), examples = @ExampleObject( - name = "Change password to a more difficult one", + name = "Change password to a more difficult one.", value = "{ \"oldPassword\":\"scmadmin\",\n \"newPassword\":\"5cm4dm1n\"\n}", summary = "Simple change password" ) diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/NamespacePermissionResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/NamespacePermissionResource.java index 0d43f72484..0fe94136bb 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/NamespacePermissionResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/NamespacePermissionResource.java @@ -98,9 +98,9 @@ public class NamespacePermissionResource { requestBody = @RequestBody( content = @Content( mediaType = VndMediaType.REPOSITORY_PERMISSION, - schema = @Schema(implementation = PermissionListDto.class), + schema = @Schema(implementation = UpdatePermissionListDto.class), examples = @ExampleObject( - name = "Add read permissions for repositories and pull requests to manager group", + name = "Add read permissions for repositories and pull requests to manager group.", value = "{\n \"name\":\"manager\",\n \"verbs\":[\"read\",\"readPullRequest\"],\n \"groupPermission\":true\n}", summary = "Add a permission" ) @@ -244,9 +244,9 @@ public class NamespacePermissionResource { requestBody = @RequestBody( content = @Content( mediaType = VndMediaType.REPOSITORY_PERMISSION, - schema = @Schema(implementation = PermissionListDto.class), + schema = @Schema(implementation = UpdatePermissionListDto.class), examples = @ExampleObject( - name = "Update permissions of manager group", + name = "Update permissions of manager group.", value = "{\n \"name\":\"manager\",\n \"verbs\":[\"read\",\"permissionRead\",\"readPullRequest\"],\n \"groupPermission\":true\n}", summary = "Update a permission" ) diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryCollectionResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryCollectionResource.java index f60fa6d6ff..9e161c6136 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryCollectionResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryCollectionResource.java @@ -171,9 +171,9 @@ public class RepositoryCollectionResource { mediaType = VndMediaType.REPOSITORY, schema = @Schema(implementation = CreateRepositoryDto.class), examples = @ExampleObject( - name = "Create a new git repository named scm-manager in scmadmin namespace", + name = "Create a new git repository named scm-manager in scmadmin namespace.", value = "{\n \"namespace\":\"scmadmin\",\n \"name\":\"scm-manager\",\n \"type\":\"git\"\n}", - summary = "Create a simple git repository" + summary = "Create a git repository" ) ) ) diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryPermissionRootResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryPermissionRootResource.java index 48d17279e3..5883a50d39 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryPermissionRootResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryPermissionRootResource.java @@ -100,11 +100,11 @@ public class RepositoryPermissionRootResource { requestBody = @RequestBody( content = @Content( mediaType = VndMediaType.REPOSITORY_PERMISSION, - schema = @Schema(implementation = PermissionListDto.class), + schema = @Schema(implementation = UpdatePermissionListDto.class), examples = @ExampleObject( - name = "Add read permissions for repository and pull requests to manager group", + name = "Add read permissions for repository and pull requests to manager group.", value = "{\n \"name\":\"manager\",\n \"verbs\":[\"read\",\"readPullRequest\"],\n \"groupPermission\":true\n}", - summary = "Add a permission" + summary = "Add permissions" ) ) ) @@ -252,9 +252,9 @@ public class RepositoryPermissionRootResource { requestBody = @RequestBody( content = @Content( mediaType = VndMediaType.REPOSITORY_PERMISSION, - schema = @Schema(implementation = PermissionListDto.class), + schema = @Schema(implementation = UpdatePermissionListDto.class), examples = @ExampleObject( - name = "Update permissions of manager group", + name = "Update permissions of manager group.", value = "{\n \"name\":\"manager\",\n \"verbs\":[\"read\",\"permissionRead\",\"readPullRequest\"],\n \"groupPermission\":true\n}", summary = "Update a permission" ) diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRenameDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRenameDto.java index 67848db3fe..6f082a0b88 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRenameDto.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRenameDto.java @@ -33,7 +33,7 @@ import javax.validation.constraints.Pattern; @Getter @NoArgsConstructor public class RepositoryRenameDto { + private String namespace; @Pattern(regexp = ValidationUtil.REGEX_REPOSITORYNAME) private String name; - private String namespace; } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryResource.java index 50bb7764ca..8020131bae 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryResource.java @@ -162,7 +162,7 @@ public class RepositoryResource { mediaType = VndMediaType.REPOSITORY, schema = @Schema(implementation = UpdateRepositoryDto.class), examples = @ExampleObject( - name = "Update repository description", + name = "Update repository description.", value = "{\n \"namespace\":\"scmadmin\",\n \"name\":\"scm-manager\",\n \"description\":\"The easiest way to share and manage your Git, Mercurial and Subversion repositories.\",\n \"type\":\"git\",\n \"lastModified\":\"2020-06-05T14:42:49.000Z\"\n}", summary = "Update a repository" ) diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleCollectionResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleCollectionResource.java index 50c4c0ede7..58292cf488 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleCollectionResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleCollectionResource.java @@ -125,7 +125,7 @@ public class RepositoryRoleCollectionResource { mediaType = VndMediaType.REPOSITORY_ROLE, schema = @Schema(implementation = CreateRepositoryRoleDto.class), examples = @ExampleObject( - name = "Create repository role named hero with read and delete repository permission", + name = "Create repository role named hero with read and delete repository permission.", value = "{\n \"name\":\"hero\",\n \"system\":false,\n \"verbs\":[\"read\",\"delete\"]\n}", summary = "Add a repository role" ) diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleResource.java index 31179f0c2d..41a6f645e5 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleResource.java @@ -139,7 +139,7 @@ public class RepositoryRoleResource { mediaType = VndMediaType.REPOSITORY_ROLE, schema = @Schema(implementation = UpdateRepositoryRoleDto.class), examples = @ExampleObject( - name = "Update repository role named hero with this verbs", + name = "Update repository role named hero with this verbs.", value = "{\n \"name\":\"hero\",\n \"system\":false,\n \"verbs\":[\"read\",\"pull\",\"write\",\"push\",\"delete\"],\n \"lastModified\":\"2020-06-05T14:42:49.000Z\"\n}", summary = "Update a repository role" ) diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdatePermissionListDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdatePermissionListDto.java new file mode 100644 index 0000000000..988169bd2b --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdatePermissionListDto.java @@ -0,0 +1,43 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import javax.validation.constraints.NotNull; + +/** + * This class is currently only used in the openapi scheme + */ +@Getter +@Setter +@NoArgsConstructor +public class UpdatePermissionListDto { + + @NotNull + private String[] permissions; +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserPermissionResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserPermissionResource.java index ee27b26e0d..773d344937 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserPermissionResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserPermissionResource.java @@ -115,9 +115,9 @@ public class UserPermissionResource { requestBody = @RequestBody( content = @Content( mediaType = VndMediaType.PERMISSION_COLLECTION, - schema = @Schema(implementation = PermissionListDto.class), + schema = @Schema(implementation = UpdatePermissionListDto.class), examples = @ExampleObject( - name = "Add read permissions for all repositories and pull requests", + name = "Add read permissions for all repositories and pull requests.", value = "{\n \"permissions\":[\"repository:read,pull:*\",\"repository:readPullRequest:*\"]\n}", summary = "Simple update user permissions" ) diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserResource.java index c4a6d08a28..bed3e188c2 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserResource.java @@ -194,7 +194,7 @@ public class UserResource { mediaType = VndMediaType.PASSWORD_OVERWRITE, schema = @Schema(implementation = PasswordOverwriteDto.class), examples = @ExampleObject( - name = "Overwrites current password with a more difficult one", + name = "Overwrites current password with a more difficult one.", value = "{ \"newPassword\":\"5cm4dm1n\"\n}", summary = "Set new password" ) From 6791aba84caff4ccfb9c4d183007253b71a34b73 Mon Sep 17 00:00:00 2001 From: Florian Scholdei Date: Wed, 18 Nov 2020 12:01:24 +0100 Subject: [PATCH 4/6] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54a64a7ebc..84c6c9edb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Lookup command which provides further repository information ([#1415](https://github.com/scm-manager/scm-manager/pull/1415)) - Include messages from scm protocol in modification or merge errors ([#1420](https://github.com/scm-manager/scm-manager/pull/1420)) - Enhance trace api to accepted status codes ([#1430](https://github.com/scm-manager/scm-manager/pull/1430)) +- Add examples to core resources to simplify usage of rest api ([#1434](https://github.com/scm-manager/scm-manager/pull/1434)) ### Fixed - Missing close of hg diff command ([#1417](https://github.com/scm-manager/scm-manager/pull/1417)) From bab4a56e227f92fdbe99e26620a4951436a20d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Wed, 18 Nov 2020 18:50:59 +0100 Subject: [PATCH 5/6] Make dtos for schema docs unusable --- .../api/v2/resources/GitConfigResource.java | 23 +++++++ .../GitRepositoryConfigResource.java | 13 +++- .../api/v2/resources/UpdateGitConfigDto.java | 51 --------------- .../UpdateGitRepositoryConfigDto.java | 39 ----------- .../api/v2/resources/UpdateHgConfigDto.java | 9 ++- .../api/v2/resources/SvnConfigResource.java | 16 ++++- .../api/v2/resources/UpdateSvnConfigDto.java | 42 ------------ .../scm/api/v2/resources/ApiKeyResource.java | 16 +++++ .../scm/api/v2/resources/ConfigResource.java | 38 ++++++++++- .../scm/api/v2/resources/CreateApiKeyDto.java | 44 ------------- .../api/v2/resources/CreateRepositoryDto.java | 57 ---------------- .../v2/resources/CreateRepositoryRoleDto.java | 47 -------------- .../scm/api/v2/resources/CreateUserDto.java | 54 --------------- .../scm/api/v2/resources/GroupResource.java | 26 +++++++- .../NamespacePermissionResource.java | 3 +- .../RepositoryCollectionResource.java | 29 +++++++++ .../api/v2/resources/RepositoryResource.java | 29 +++++++++ .../RepositoryRoleCollectionResource.java | 21 +++++- .../v2/resources/RepositoryRoleResource.java | 23 ++++++- .../scm/api/v2/resources/UpdateConfigDto.java | 65 ------------------- .../scm/api/v2/resources/UpdateGroupDto.java | 53 --------------- .../v2/resources/UpdatePermissionListDto.java | 10 ++- .../api/v2/resources/UpdateRepositoryDto.java | 57 ---------------- .../v2/resources/UpdateRepositoryRoleDto.java | 49 -------------- .../scm/api/v2/resources/UpdateUserDto.java | 57 ---------------- .../v2/resources/UserCollectionResource.java | 28 ++++++++ .../scm/api/v2/resources/UserResource.java | 31 +++++++++ 27 files changed, 295 insertions(+), 635 deletions(-) delete mode 100644 scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitConfigDto.java delete mode 100644 scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitRepositoryConfigDto.java delete mode 100644 scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateSvnConfigDto.java delete mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateApiKeyDto.java delete mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryDto.java delete mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryRoleDto.java delete mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateUserDto.java delete mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateConfigDto.java delete mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateGroupDto.java delete mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryDto.java delete mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryRoleDto.java delete mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateUserDto.java diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigResource.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigResource.java index e366a35abb..5357b8d27f 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigResource.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigResource.java @@ -32,6 +32,10 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.validator.constraints.Length; import sonia.scm.config.ConfigurationPermissions; import sonia.scm.repository.GitConfig; import sonia.scm.repository.GitRepositoryHandler; @@ -41,6 +45,8 @@ import sonia.scm.web.VndMediaType; import javax.inject.Inject; import javax.inject.Provider; import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Pattern; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.PUT; @@ -48,6 +54,8 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; +import static sonia.scm.repository.Branch.VALID_BRANCH_NAMES; + /** * RESTful Web Service Resource to manage the configuration of the git plugin. */ @@ -161,4 +169,19 @@ public class GitConfigResource { public GitRepositoryConfigResource getRepositoryConfig() { return gitRepositoryConfigResource.get(); } + + /** + * This class is currently only used in the openapi scheme + */ + @Getter + @NoArgsConstructor(access = AccessLevel.PRIVATE) + private static final class UpdateGitConfigDto { + private boolean disabled = false; + private String gcExpression; + private boolean nonFastForwardDisallowed; + @NotEmpty + @Length(min = 1, max = 100) + @Pattern(regexp = VALID_BRANCH_NAMES) + private String defaultBranch; + } } diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitRepositoryConfigResource.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitRepositoryConfigResource.java index 81e8b79d60..55627aafee 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitRepositoryConfigResource.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitRepositoryConfigResource.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + package sonia.scm.api.v2.resources; import io.swagger.v3.oas.annotations.Operation; @@ -30,6 +30,7 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import lombok.Getter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import sonia.scm.repository.GitRepositoryConfig; @@ -166,4 +167,14 @@ public class GitRepositoryConfigResource { private ConfigurationStore getStore(Repository repository) { return gitRepositoryConfigStoreProvider.get(repository); } + + /** + * This class is currently only used in the openapi scheme + */ + @Getter + private static final class UpdateGitRepositoryConfigDto { + private UpdateGitRepositoryConfigDto() { + } + private String defaultBranch; + } } diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitConfigDto.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitConfigDto.java deleted file mode 100644 index 5893e93a40..0000000000 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitConfigDto.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2020-present Cloudogu GmbH and Contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package sonia.scm.api.v2.resources; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.hibernate.validator.constraints.Length; - -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.Pattern; - -import static sonia.scm.repository.Branch.VALID_BRANCH_NAMES; - -/** - * This class is currently only used in the openapi scheme - */ -@NoArgsConstructor -@Getter -@Setter -public class UpdateGitConfigDto { - private boolean disabled = false; - private String gcExpression; - private boolean nonFastForwardDisallowed; - @NotEmpty - @Length(min = 1, max = 100) - @Pattern(regexp = VALID_BRANCH_NAMES) - private String defaultBranch; -} diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitRepositoryConfigDto.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitRepositoryConfigDto.java deleted file mode 100644 index 491208fae9..0000000000 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitRepositoryConfigDto.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2020-present Cloudogu GmbH and Contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package sonia.scm.api.v2.resources; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -/** - * This class is currently only used in the openapi scheme - */ -@Getter -@Setter -@NoArgsConstructor -public class UpdateGitRepositoryConfigDto { - private String defaultBranch; -} diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateHgConfigDto.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateHgConfigDto.java index 18ac833c76..aa73b6cc6d 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateHgConfigDto.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateHgConfigDto.java @@ -21,20 +21,19 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + package sonia.scm.api.v2.resources; +import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; /** * This class is currently only used in the openapi scheme */ -@NoArgsConstructor @Getter -@Setter -public class UpdateHgConfigDto { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +final class UpdateHgConfigDto { private boolean disabled; private String hgBinary; private String pythonBinary; diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/SvnConfigResource.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/SvnConfigResource.java index 8197c87b7b..eb33cd1b3c 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/SvnConfigResource.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/SvnConfigResource.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + package sonia.scm.api.v2.resources; import io.swagger.v3.oas.annotations.OpenAPIDefinition; @@ -32,7 +32,11 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; import sonia.scm.config.ConfigurationPermissions; +import sonia.scm.repository.Compatibility; import sonia.scm.repository.SvnConfig; import sonia.scm.repository.SvnRepositoryHandler; import sonia.scm.web.SvnVndMediaType; @@ -156,4 +160,14 @@ public class SvnConfigResource { return Response.noContent().build(); } + /** + * This class is currently only used in the openapi scheme + */ + @Getter + @NoArgsConstructor(access = AccessLevel.PRIVATE) + private static final class UpdateSvnConfigDto { + private boolean disabled; + private Compatibility compatibility; + private boolean enabledGZip; + } } diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateSvnConfigDto.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateSvnConfigDto.java deleted file mode 100644 index af140648bd..0000000000 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateSvnConfigDto.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2020-present Cloudogu GmbH and Contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package sonia.scm.api.v2.resources; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import sonia.scm.repository.Compatibility; - -/** - * This class is currently only used in the openapi scheme - */ -@NoArgsConstructor -@Getter -@Setter -public class UpdateSvnConfigDto { - private boolean disabled; - private Compatibility compatibility; - private boolean enabledGZip; -} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyResource.java index bd13b7e5f6..4270b2b7ae 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyResource.java @@ -32,6 +32,9 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; import sonia.scm.ContextEntry; import sonia.scm.security.ApiKey; import sonia.scm.security.ApiKeyService; @@ -39,6 +42,7 @@ import sonia.scm.web.VndMediaType; import javax.inject.Inject; import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -187,4 +191,16 @@ public class ApiKeyResource { public void delete(@PathParam("id") String id) { apiKeyService.remove(id); } + + /** + * This class is currently only used in the openapi scheme + */ + @Getter + @NoArgsConstructor(access = AccessLevel.PRIVATE) + private static final class CreateApiKeyDto { + @NotEmpty + private String displayName; + @NotEmpty + private String permissionRole; + } } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigResource.java index f9ed6fe132..ab3fef46ec 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigResource.java @@ -27,16 +27,19 @@ package sonia.scm.api.v2.resources; import com.google.common.annotations.VisibleForTesting; import io.swagger.v3.oas.annotations.OpenAPIDefinition; import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; import sonia.scm.config.ConfigurationPermissions; import sonia.scm.config.ScmConfiguration; import sonia.scm.repository.NamespaceStrategyValidator; +import sonia.scm.security.AnonymousMode; import sonia.scm.util.ScmConfigurationUtil; import sonia.scm.web.VndMediaType; @@ -47,8 +50,8 @@ import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import java.util.Set; import java.util.function.Consumer; /** @@ -169,4 +172,35 @@ public class ConfigResource { return Response.noContent().build(); } + + /** + * This class is currently only used in the openapi scheme + */ + @Getter + @NoArgsConstructor(access = AccessLevel.PRIVATE) + private static final class UpdateConfigDto { + private String proxyPassword; + private int proxyPort; + private String proxyServer; + private String proxyUser; + private boolean enableProxy; + private String realmDescription; + private boolean disableGroupingGrid; + private String dateFormat; + private boolean anonymousAccessEnabled; + private AnonymousMode anonymousMode; + private String baseUrl; + private boolean forceBaseUrl; + private int loginAttemptLimit; + private Set proxyExcludes; + private boolean skipFailedAuthenticators; + private String pluginUrl; + private long loginAttemptLimitTimeout; + private boolean enabledXsrfProtection; + private boolean enabledUserConverter; + private String namespaceStrategy; + private String loginInfoUrl; + private String releaseFeedUrl; + private String mailDomainName; + } } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateApiKeyDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateApiKeyDto.java deleted file mode 100644 index a78719d081..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateApiKeyDto.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2020-present Cloudogu GmbH and Contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package sonia.scm.api.v2.resources; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -import javax.validation.constraints.NotEmpty; - -/** - * This class is currently only used in the openapi scheme - */ -@Getter -@Setter -@NoArgsConstructor -public class CreateApiKeyDto { - @NotEmpty - private String displayName; - @NotEmpty - private String permissionRole; -} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryDto.java deleted file mode 100644 index 420785449c..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryDto.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2020-present Cloudogu GmbH and Contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package sonia.scm.api.v2.resources; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import sonia.scm.util.ValidationUtil; - -import javax.validation.constraints.Email; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.Pattern; -import java.time.Instant; -import java.util.List; - -/** - * This class is currently only used in the openapi scheme - */ -@Getter -@Setter -@NoArgsConstructor -public class CreateRepositoryDto { - private String namespace; - @Pattern(regexp = ValidationUtil.REGEX_REPOSITORYNAME) - private String name; - @NotEmpty - private String type; - @Email - private String contact; - private String description; - private List healthCheckFailures; - @JsonInclude(JsonInclude.Include.NON_NULL) - private Instant lastModified; -} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryRoleDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryRoleDto.java deleted file mode 100644 index 6b70fb3f22..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryRoleDto.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2020-present Cloudogu GmbH and Contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package sonia.scm.api.v2.resources; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -import javax.validation.constraints.NotEmpty; -import java.util.Collection; - -/** - * This class is currently only used in the openapi scheme - */ -@Getter -@Setter -@NoArgsConstructor -public class CreateRepositoryRoleDto { - @NotEmpty - private String name; - private boolean system; - @NoBlankStrings @NotEmpty - private Collection verbs; - private String type; -} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateUserDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateUserDto.java deleted file mode 100644 index 54af7edb99..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateUserDto.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2020-present Cloudogu GmbH and Contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package sonia.scm.api.v2.resources; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import sonia.scm.util.ValidationUtil; - -import javax.validation.constraints.Email; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.Pattern; - -/** - * This class is currently only used in the openapi scheme - */ -@NoArgsConstructor @Getter @Setter -public class CreateUserDto { - @Pattern(regexp = ValidationUtil.REGEX_NAME) - private String name; - @NotEmpty - private String displayName; - @JsonInclude(JsonInclude.Include.NON_NULL) - @Email - private String mail; - private boolean external; - @JsonInclude(JsonInclude.Include.NON_NULL) - private String password; - private boolean active; - private String type; -} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/GroupResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/GroupResource.java index f3fea99bff..8245430c46 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/GroupResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/GroupResource.java @@ -21,21 +21,27 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + package sonia.scm.api.v2.resources; +import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; import sonia.scm.group.Group; import sonia.scm.group.GroupManager; +import sonia.scm.util.ValidationUtil; import sonia.scm.web.VndMediaType; import javax.inject.Inject; import javax.validation.Valid; +import javax.validation.constraints.Pattern; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -44,6 +50,8 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; +import java.time.Instant; +import java.util.List; public class GroupResource { @@ -181,4 +189,20 @@ public class GroupResource { public GroupPermissionResource permissions() { return groupPermissionResource; } + + /** + * This class is currently only used in the openapi scheme + */ + @Getter + @NoArgsConstructor(access = AccessLevel.PRIVATE) + private static final class UpdateGroupDto { + @Pattern(regexp = ValidationUtil.REGEX_NAME) + private String name; + private String description; + @JsonInclude(JsonInclude.Include.NON_NULL) + private Instant lastModified; + private String type; + private List members; + private boolean external; + } } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/NamespacePermissionResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/NamespacePermissionResource.java index 0fe94136bb..ed507c7ba5 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/NamespacePermissionResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/NamespacePermissionResource.java @@ -357,6 +357,5 @@ public class NamespacePermissionResource { .stream() .anyMatch(p -> p.getName().equals(permission.getName()) && p.isGroupPermission() == permission.isGroupPermission()); } + } - - diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryCollectionResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryCollectionResource.java index 9e161c6136..41e5a8a7e4 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryCollectionResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryCollectionResource.java @@ -24,6 +24,7 @@ package sonia.scm.api.v2.resources; +import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.headers.Header; import io.swagger.v3.oas.annotations.media.Content; @@ -31,6 +32,9 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; import org.apache.shiro.SecurityUtils; import sonia.scm.repository.Repository; import sonia.scm.repository.RepositoryInitializer; @@ -39,10 +43,14 @@ import sonia.scm.repository.RepositoryPermission; import sonia.scm.search.SearchRequest; import sonia.scm.search.SearchUtil; import sonia.scm.user.User; +import sonia.scm.util.ValidationUtil; import sonia.scm.web.VndMediaType; import javax.inject.Inject; import javax.validation.Valid; +import javax.validation.constraints.Email; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Pattern; import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; @@ -52,6 +60,8 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; +import java.time.Instant; +import java.util.List; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; @@ -237,4 +247,23 @@ public class RepositoryCollectionResource { SearchRequest searchRequest = new SearchRequest(search, true); return repository -> SearchUtil.matchesOne(searchRequest, repository.getName(), repository.getNamespace(), repository.getDescription()); } + + /** + * This class is currently only used in the openapi scheme + */ + @Getter + @NoArgsConstructor(access = AccessLevel.PRIVATE) + private static final class CreateRepositoryDto { + private String namespace; + @Pattern(regexp = ValidationUtil.REGEX_REPOSITORYNAME) + private String name; + @NotEmpty + private String type; + @Email + private String contact; + private String description; + private List healthCheckFailures; + @JsonInclude(JsonInclude.Include.NON_NULL) + private Instant lastModified; + } } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryResource.java index 8020131bae..ecc044f096 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryResource.java @@ -24,19 +24,27 @@ package sonia.scm.api.v2.resources; +import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; import sonia.scm.repository.NamespaceAndName; import sonia.scm.repository.Repository; import sonia.scm.repository.RepositoryManager; +import sonia.scm.util.ValidationUtil; import sonia.scm.web.VndMediaType; import javax.inject.Inject; import javax.validation.Valid; +import javax.validation.constraints.Email; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Pattern; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -46,6 +54,8 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; +import java.time.Instant; +import java.util.List; import java.util.Optional; import java.util.function.Predicate; import java.util.function.Supplier; @@ -290,4 +300,23 @@ public class RepositoryResource { private Predicate nameAndNamespaceStaysTheSame(String namespace, String name) { return changed -> name.equals(changed.getName()) && namespace.equals(changed.getNamespace()); } + + /** + * This class is currently only used in the openapi scheme + */ + @Getter + @NoArgsConstructor(access = AccessLevel.PRIVATE) + private static final class UpdateRepositoryDto { + private String namespace; + @Pattern(regexp = ValidationUtil.REGEX_REPOSITORYNAME) + private String name; + @NotEmpty + private String type; + @Email + private String contact; + private String description; + private List healthCheckFailures; + @JsonInclude(JsonInclude.Include.NON_NULL) + private Instant lastModified; + } } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleCollectionResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleCollectionResource.java index 58292cf488..946be8e6ee 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleCollectionResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleCollectionResource.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + package sonia.scm.api.v2.resources; import io.swagger.v3.oas.annotations.Operation; @@ -31,12 +31,16 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; import sonia.scm.repository.RepositoryRole; import sonia.scm.repository.RepositoryRoleManager; import sonia.scm.web.VndMediaType; import javax.inject.Inject; import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; @@ -45,6 +49,7 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; +import java.util.Collection; public class RepositoryRoleCollectionResource { @@ -154,4 +159,18 @@ public class RepositoryRoleCollectionResource { public Response create(@Valid RepositoryRoleDto repositoryRole) { return adapter.create(repositoryRole, () -> dtoToRepositoryRoleMapper.map(repositoryRole), u -> resourceLinks.repositoryRole().self(u.getName())); } + + /** + * This class is currently only used in the openapi scheme + */ + @Getter + @NoArgsConstructor(access = AccessLevel.PRIVATE) + private static final class CreateRepositoryRoleDto { + @NotEmpty + private String name; + private boolean system; + @NoBlankStrings @NotEmpty + private Collection verbs; + private String type; + } } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleResource.java index 41a6f645e5..72c8fbe4c8 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleResource.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + package sonia.scm.api.v2.resources; import io.swagger.v3.oas.annotations.Operation; @@ -30,12 +30,16 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; import sonia.scm.repository.RepositoryRole; import sonia.scm.repository.RepositoryRoleManager; import sonia.scm.web.VndMediaType; import javax.inject.Inject; import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -44,6 +48,8 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; +import java.time.Instant; +import java.util.Collection; public class RepositoryRoleResource { @@ -161,4 +167,19 @@ public class RepositoryRoleResource { public Response update(@PathParam("name") String name, @Valid RepositoryRoleDto repositoryRole) { return adapter.update(name, existing -> dtoToRepositoryRoleMapper.map(repositoryRole)); } + + /** + * This class is currently only used in the openapi scheme + */ + @Getter + @NoArgsConstructor(access = AccessLevel.PRIVATE) + private static final class UpdateRepositoryRoleDto { + @NotEmpty + private String name; + private boolean system; + @NoBlankStrings @NotEmpty + private Collection verbs; + private String type; + private Instant lastModified; + } } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateConfigDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateConfigDto.java deleted file mode 100644 index 7574210e3f..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateConfigDto.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2020-present Cloudogu GmbH and Contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package sonia.scm.api.v2.resources; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import sonia.scm.security.AnonymousMode; - -import java.util.Set; - -/** - * This class is currently only used in the openapi scheme - */ -@NoArgsConstructor -@Getter -@Setter -public class UpdateConfigDto { - - private String proxyPassword; - private int proxyPort; - private String proxyServer; - private String proxyUser; - private boolean enableProxy; - private String realmDescription; - private boolean disableGroupingGrid; - private String dateFormat; - private boolean anonymousAccessEnabled; - private AnonymousMode anonymousMode; - private String baseUrl; - private boolean forceBaseUrl; - private int loginAttemptLimit; - private Set proxyExcludes; - private boolean skipFailedAuthenticators; - private String pluginUrl; - private long loginAttemptLimitTimeout; - private boolean enabledXsrfProtection; - private boolean enabledUserConverter; - private String namespaceStrategy; - private String loginInfoUrl; - private String releaseFeedUrl; - private String mailDomainName; -} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateGroupDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateGroupDto.java deleted file mode 100644 index d9f06eb88b..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateGroupDto.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2020-present Cloudogu GmbH and Contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package sonia.scm.api.v2.resources; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import sonia.scm.util.ValidationUtil; - -import javax.validation.constraints.Pattern; -import java.time.Instant; -import java.util.List; - -/** - * This class is currently only used in the openapi scheme - */ -@Getter -@Setter -@NoArgsConstructor -public class UpdateGroupDto { - - @Pattern(regexp = ValidationUtil.REGEX_NAME) - private String name; - private String description; - @JsonInclude(JsonInclude.Include.NON_NULL) - private Instant lastModified; - private String type; - private List members; - private boolean external; -} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdatePermissionListDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdatePermissionListDto.java index 988169bd2b..00c49e43d7 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdatePermissionListDto.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdatePermissionListDto.java @@ -21,12 +21,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + package sonia.scm.api.v2.resources; +import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; import javax.validation.constraints.NotNull; @@ -34,10 +34,8 @@ import javax.validation.constraints.NotNull; * This class is currently only used in the openapi scheme */ @Getter -@Setter -@NoArgsConstructor -public class UpdatePermissionListDto { - +@NoArgsConstructor(access = AccessLevel.PRIVATE) +final class UpdatePermissionListDto { @NotNull private String[] permissions; } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryDto.java deleted file mode 100644 index 2dc2d89a1c..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryDto.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2020-present Cloudogu GmbH and Contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package sonia.scm.api.v2.resources; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import sonia.scm.util.ValidationUtil; - -import javax.validation.constraints.Email; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.Pattern; -import java.time.Instant; -import java.util.List; - -/** - * This class is currently only used in the openapi scheme - */ -@Getter -@Setter -@NoArgsConstructor -public class UpdateRepositoryDto { - private String namespace; - @Pattern(regexp = ValidationUtil.REGEX_REPOSITORYNAME) - private String name; - @NotEmpty - private String type; - @Email - private String contact; - private String description; - private List healthCheckFailures; - @JsonInclude(JsonInclude.Include.NON_NULL) - private Instant lastModified; -} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryRoleDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryRoleDto.java deleted file mode 100644 index 81193195fe..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryRoleDto.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2020-present Cloudogu GmbH and Contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package sonia.scm.api.v2.resources; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -import javax.validation.constraints.NotEmpty; -import java.time.Instant; -import java.util.Collection; - -/** - * This class is currently only used in the openapi scheme - */ -@Getter -@Setter -@NoArgsConstructor -public class UpdateRepositoryRoleDto { - @NotEmpty - private String name; - private boolean system; - @NoBlankStrings @NotEmpty - private Collection verbs; - private String type; - private Instant lastModified; -} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateUserDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateUserDto.java deleted file mode 100644 index 28e011f4cd..0000000000 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateUserDto.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2020-present Cloudogu GmbH and Contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package sonia.scm.api.v2.resources; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import sonia.scm.util.ValidationUtil; - -import javax.validation.constraints.Email; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.Pattern; -import java.time.Instant; - -/** - * This class is currently only used in the openapi scheme - */ -@NoArgsConstructor @Getter @Setter -public class UpdateUserDto { - @Pattern(regexp = ValidationUtil.REGEX_NAME) - private String name; - @NotEmpty - private String displayName; - @JsonInclude(JsonInclude.Include.NON_NULL) - @Email - private String mail; - private boolean external; - @JsonInclude(JsonInclude.Include.NON_NULL) - private String password; - private boolean active; - private String type; - @JsonInclude(JsonInclude.Include.NON_NULL) - private Instant lastModified; -} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserCollectionResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserCollectionResource.java index a81aa3fc7a..211a5823d5 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserCollectionResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserCollectionResource.java @@ -24,6 +24,7 @@ package sonia.scm.api.v2.resources; +import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.headers.Header; import io.swagger.v3.oas.annotations.media.Content; @@ -31,16 +32,23 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; import org.apache.shiro.authc.credential.PasswordService; import sonia.scm.search.SearchRequest; import sonia.scm.search.SearchUtil; import sonia.scm.user.User; import sonia.scm.user.UserManager; import sonia.scm.user.UserPermissions; +import sonia.scm.util.ValidationUtil; import sonia.scm.web.VndMediaType; import javax.inject.Inject; import javax.validation.Valid; +import javax.validation.constraints.Email; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Pattern; import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; @@ -173,4 +181,24 @@ public class UserCollectionResource { SearchRequest searchRequest = new SearchRequest(search, true); return user -> SearchUtil.matchesOne(searchRequest, user.getName(), user.getDisplayName(), user.getMail()); } + + /** + * This class is currently only used in the openapi scheme + */ + @Getter + @NoArgsConstructor(access = AccessLevel.PRIVATE) + private static final class CreateUserDto { + @Pattern(regexp = ValidationUtil.REGEX_NAME) + private String name; + @NotEmpty + private String displayName; + @JsonInclude(JsonInclude.Include.NON_NULL) + @Email + private String mail; + private boolean external; + @JsonInclude(JsonInclude.Include.NON_NULL) + private String password; + private boolean active; + private String type; + } } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserResource.java index bed3e188c2..db94bf1195 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserResource.java @@ -24,19 +24,27 @@ package sonia.scm.api.v2.resources; +import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; import org.apache.shiro.authc.credential.PasswordService; import sonia.scm.user.User; import sonia.scm.user.UserManager; +import sonia.scm.util.ValidationUtil; import sonia.scm.web.VndMediaType; import javax.inject.Inject; import javax.validation.Valid; +import javax.validation.constraints.Email; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Pattern; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -45,6 +53,7 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; +import java.time.Instant; public class UserResource { @@ -302,4 +311,26 @@ public class UserResource { public UserPermissionResource permissions() { return userPermissionResource; } + + /** + * This class is currently only used in the openapi scheme + */ + @Getter + @NoArgsConstructor(access = AccessLevel.PRIVATE) + private static final class UpdateUserDto { + @Pattern(regexp = ValidationUtil.REGEX_NAME) + private String name; + @NotEmpty + private String displayName; + @JsonInclude(JsonInclude.Include.NON_NULL) + @Email + private String mail; + private boolean external; + @JsonInclude(JsonInclude.Include.NON_NULL) + private String password; + private boolean active; + private String type; + @JsonInclude(JsonInclude.Include.NON_NULL) + private Instant lastModified; + } } From 69a3a8a2daee4ce4c69f0904decbb6a43946cd0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Thu, 19 Nov 2020 07:59:48 +0100 Subject: [PATCH 6/6] Convert update dto classes to interfaces --- .../scm/api/v2/resources/GitConfigDto.java | 2 +- .../api/v2/resources/GitConfigResource.java | 23 ------ .../v2/resources/GitRepositoryConfigDto.java | 4 +- .../GitRepositoryConfigResource.java | 10 --- .../api/v2/resources/UpdateGitConfigDto.java | 46 +++++++++++ .../UpdateGitRepositoryConfigDto.java | 29 +++++++ .../scm/api/v2/resources/HgConfigDto.java | 4 +- .../api/v2/resources/UpdateHgConfigDto.java | 35 ++++----- .../scm/api/v2/resources/SvnConfigDto.java | 4 +- .../api/v2/resources/SvnConfigResource.java | 14 ---- .../api/v2/resources/UpdateSvnConfigDto.java | 36 +++++++++ .../sonia/scm/api/v2/resources/ApiKeyDto.java | 2 +- .../scm/api/v2/resources/ApiKeyResource.java | 15 ---- .../sonia/scm/api/v2/resources/ConfigDto.java | 2 +- .../scm/api/v2/resources/ConfigResource.java | 35 --------- .../scm/api/v2/resources/CreateApiKeyDto.java | 35 +++++++++ .../scm/api/v2/resources/CreateGroupDto.java | 23 ++---- .../api/v2/resources/CreateRepositoryDto.java | 53 +++++++++++++ .../v2/resources/CreateRepositoryRoleDto.java | 40 ++++++++++ .../scm/api/v2/resources/CreateUserDto.java | 50 ++++++++++++ .../sonia/scm/api/v2/resources/GroupDto.java | 4 +- .../scm/api/v2/resources/GroupResource.java | 23 ------ .../NamespacePermissionResource.java | 4 +- .../api/v2/resources/PermissionListDto.java | 4 +- .../RepositoryCollectionResource.java | 28 ------- .../scm/api/v2/resources/RepositoryDto.java | 4 +- .../v2/resources/RepositoryPermissionDto.java | 4 +- .../RepositoryPermissionRootResource.java | 6 +- .../api/v2/resources/RepositoryResource.java | 28 ------- .../RepositoryRoleCollectionResource.java | 18 ----- .../api/v2/resources/RepositoryRoleDto.java | 4 +- .../v2/resources/RepositoryRoleResource.java | 20 ----- .../scm/api/v2/resources/UpdateConfigDto.java | 77 +++++++++++++++++++ .../scm/api/v2/resources/UpdateGroupDto.java | 50 ++++++++++++ .../v2/resources/UpdatePermissionListDto.java | 14 +--- .../api/v2/resources/UpdateRepositoryDto.java | 55 +++++++++++++ .../UpdateRepositoryPermissionDto.java | 43 +++++++++++ .../v2/resources/UpdateRepositoryRoleDto.java | 43 +++++++++++ .../scm/api/v2/resources/UpdateUserDto.java | 54 +++++++++++++ .../v2/resources/UserCollectionResource.java | 27 ------- .../sonia/scm/api/v2/resources/UserDto.java | 2 +- .../scm/api/v2/resources/UserResource.java | 30 -------- 42 files changed, 664 insertions(+), 340 deletions(-) create mode 100644 scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitConfigDto.java create mode 100644 scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitRepositoryConfigDto.java create mode 100644 scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateSvnConfigDto.java create mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateApiKeyDto.java create mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryDto.java create mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryRoleDto.java create mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateUserDto.java create mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateConfigDto.java create mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateGroupDto.java create mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryDto.java create mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryPermissionDto.java create mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryRoleDto.java create mode 100644 scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateUserDto.java diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigDto.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigDto.java index 893de773da..99ac469166 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigDto.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigDto.java @@ -39,7 +39,7 @@ import static sonia.scm.repository.Branch.VALID_BRANCH_NAMES; @NoArgsConstructor @Getter @Setter -public class GitConfigDto extends HalRepresentation { +public class GitConfigDto extends HalRepresentation implements UpdateGitConfigDto { private boolean disabled = false; diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigResource.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigResource.java index 5357b8d27f..e366a35abb 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigResource.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitConfigResource.java @@ -32,10 +32,6 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.hibernate.validator.constraints.Length; import sonia.scm.config.ConfigurationPermissions; import sonia.scm.repository.GitConfig; import sonia.scm.repository.GitRepositoryHandler; @@ -45,8 +41,6 @@ import sonia.scm.web.VndMediaType; import javax.inject.Inject; import javax.inject.Provider; import javax.validation.Valid; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.Pattern; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.PUT; @@ -54,8 +48,6 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; -import static sonia.scm.repository.Branch.VALID_BRANCH_NAMES; - /** * RESTful Web Service Resource to manage the configuration of the git plugin. */ @@ -169,19 +161,4 @@ public class GitConfigResource { public GitRepositoryConfigResource getRepositoryConfig() { return gitRepositoryConfigResource.get(); } - - /** - * This class is currently only used in the openapi scheme - */ - @Getter - @NoArgsConstructor(access = AccessLevel.PRIVATE) - private static final class UpdateGitConfigDto { - private boolean disabled = false; - private String gcExpression; - private boolean nonFastForwardDisallowed; - @NotEmpty - @Length(min = 1, max = 100) - @Pattern(regexp = VALID_BRANCH_NAMES) - private String defaultBranch; - } } diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitRepositoryConfigDto.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitRepositoryConfigDto.java index 92a495669b..46eb671d5c 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitRepositoryConfigDto.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitRepositoryConfigDto.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + package sonia.scm.api.v2.resources; import de.otto.edison.hal.HalRepresentation; @@ -36,7 +36,7 @@ import lombok.Setter; @AllArgsConstructor @NoArgsConstructor @SuppressWarnings("squid:S2160") // there is no proper semantic for equals on this dto -public class GitRepositoryConfigDto extends HalRepresentation { +public class GitRepositoryConfigDto extends HalRepresentation implements UpdateGitRepositoryConfigDto { private String defaultBranch; diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitRepositoryConfigResource.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitRepositoryConfigResource.java index 55627aafee..559dfddae8 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitRepositoryConfigResource.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/GitRepositoryConfigResource.java @@ -167,14 +167,4 @@ public class GitRepositoryConfigResource { private ConfigurationStore getStore(Repository repository) { return gitRepositoryConfigStoreProvider.get(repository); } - - /** - * This class is currently only used in the openapi scheme - */ - @Getter - private static final class UpdateGitRepositoryConfigDto { - private UpdateGitRepositoryConfigDto() { - } - private String defaultBranch; - } } diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitConfigDto.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitConfigDto.java new file mode 100644 index 0000000000..66bdcd7278 --- /dev/null +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitConfigDto.java @@ -0,0 +1,46 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import org.hibernate.validator.constraints.Length; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Pattern; + +import static sonia.scm.repository.Branch.VALID_BRANCH_NAMES; + +interface UpdateGitConfigDto { + + boolean isDisabled(); + + String getGcExpression(); + + boolean isNonFastForwardDisallowed(); + + @NotEmpty + @Length(min = 1, max = 100) + @Pattern(regexp = VALID_BRANCH_NAMES) + String getDefaultBranch(); +} diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitRepositoryConfigDto.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitRepositoryConfigDto.java new file mode 100644 index 0000000000..0da843e1af --- /dev/null +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateGitRepositoryConfigDto.java @@ -0,0 +1,29 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +interface UpdateGitRepositoryConfigDto { + String getDefaultBranch(); +} diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/HgConfigDto.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/HgConfigDto.java index b5039cbb44..ec303a4551 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/HgConfigDto.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/HgConfigDto.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + package sonia.scm.api.v2.resources; import de.otto.edison.hal.HalRepresentation; @@ -33,7 +33,7 @@ import lombok.Setter; @NoArgsConstructor @Getter @Setter -public class HgConfigDto extends HalRepresentation { +public class HgConfigDto extends HalRepresentation implements UpdateHgConfigDto { private boolean disabled; diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateHgConfigDto.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateHgConfigDto.java index aa73b6cc6d..743cd2cfaf 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateHgConfigDto.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateHgConfigDto.java @@ -24,23 +24,22 @@ package sonia.scm.api.v2.resources; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; +interface UpdateHgConfigDto { + boolean isDisabled(); -/** - * This class is currently only used in the openapi scheme - */ -@Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) -final class UpdateHgConfigDto { - private boolean disabled; - private String hgBinary; - private String pythonBinary; - private String pythonPath; - private String encoding; - private boolean useOptimizedBytecode; - private boolean showRevisionInId; - private boolean disableHookSSLValidation; - private boolean enableHttpPostArgs; + String getHgBinary(); + + String getPythonBinary(); + + String getPythonPath(); + + String getEncoding(); + + boolean isUseOptimizedBytecode(); + + boolean isShowRevisionInId(); + + boolean isDisableHookSSLValidation(); + + boolean isEnableHttpPostArgs(); } diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/SvnConfigDto.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/SvnConfigDto.java index 72f7513bb8..9be64e6a3b 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/SvnConfigDto.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/SvnConfigDto.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + package sonia.scm.api.v2.resources; import de.otto.edison.hal.HalRepresentation; @@ -34,7 +34,7 @@ import sonia.scm.repository.Compatibility; @NoArgsConstructor @Getter @Setter -public class SvnConfigDto extends HalRepresentation { +public class SvnConfigDto extends HalRepresentation implements UpdateSvnConfigDto { private boolean disabled; diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/SvnConfigResource.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/SvnConfigResource.java index eb33cd1b3c..394000c48a 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/SvnConfigResource.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/SvnConfigResource.java @@ -32,11 +32,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; import sonia.scm.config.ConfigurationPermissions; -import sonia.scm.repository.Compatibility; import sonia.scm.repository.SvnConfig; import sonia.scm.repository.SvnRepositoryHandler; import sonia.scm.web.SvnVndMediaType; @@ -160,14 +156,4 @@ public class SvnConfigResource { return Response.noContent().build(); } - /** - * This class is currently only used in the openapi scheme - */ - @Getter - @NoArgsConstructor(access = AccessLevel.PRIVATE) - private static final class UpdateSvnConfigDto { - private boolean disabled; - private Compatibility compatibility; - private boolean enabledGZip; - } } diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateSvnConfigDto.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateSvnConfigDto.java new file mode 100644 index 0000000000..87de7d5ec8 --- /dev/null +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/api/v2/resources/UpdateSvnConfigDto.java @@ -0,0 +1,36 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import sonia.scm.repository.Compatibility; + +interface UpdateSvnConfigDto { + + boolean isDisabled(); + + Compatibility getCompatibility(); + + boolean isEnabledGZip(); +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyDto.java index b07e329a8a..40cc0feaa0 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyDto.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyDto.java @@ -36,7 +36,7 @@ import java.time.Instant; @Getter @Setter @NoArgsConstructor -public class ApiKeyDto extends HalRepresentation { +public class ApiKeyDto extends HalRepresentation implements CreateApiKeyDto { @NotEmpty private String displayName; @NotEmpty diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyResource.java index 4270b2b7ae..04dd186b2a 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ApiKeyResource.java @@ -32,9 +32,6 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; import sonia.scm.ContextEntry; import sonia.scm.security.ApiKey; import sonia.scm.security.ApiKeyService; @@ -42,7 +39,6 @@ import sonia.scm.web.VndMediaType; import javax.inject.Inject; import javax.validation.Valid; -import javax.validation.constraints.NotEmpty; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -192,15 +188,4 @@ public class ApiKeyResource { apiKeyService.remove(id); } - /** - * This class is currently only used in the openapi scheme - */ - @Getter - @NoArgsConstructor(access = AccessLevel.PRIVATE) - private static final class CreateApiKeyDto { - @NotEmpty - private String displayName; - @NotEmpty - private String permissionRole; - } } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigDto.java index 2b7249c7e7..48b90c9175 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigDto.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigDto.java @@ -36,7 +36,7 @@ import java.util.Set; @NoArgsConstructor @Getter @Setter -public class ConfigDto extends HalRepresentation { +public class ConfigDto extends HalRepresentation implements UpdateConfigDto { private String proxyPassword; private int proxyPort; diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigResource.java index ab3fef46ec..13dec7d44e 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigResource.java @@ -33,13 +33,9 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; import sonia.scm.config.ConfigurationPermissions; import sonia.scm.config.ScmConfiguration; import sonia.scm.repository.NamespaceStrategyValidator; -import sonia.scm.security.AnonymousMode; import sonia.scm.util.ScmConfigurationUtil; import sonia.scm.web.VndMediaType; @@ -51,7 +47,6 @@ import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; -import java.util.Set; import java.util.function.Consumer; /** @@ -173,34 +168,4 @@ public class ConfigResource { return Response.noContent().build(); } - /** - * This class is currently only used in the openapi scheme - */ - @Getter - @NoArgsConstructor(access = AccessLevel.PRIVATE) - private static final class UpdateConfigDto { - private String proxyPassword; - private int proxyPort; - private String proxyServer; - private String proxyUser; - private boolean enableProxy; - private String realmDescription; - private boolean disableGroupingGrid; - private String dateFormat; - private boolean anonymousAccessEnabled; - private AnonymousMode anonymousMode; - private String baseUrl; - private boolean forceBaseUrl; - private int loginAttemptLimit; - private Set proxyExcludes; - private boolean skipFailedAuthenticators; - private String pluginUrl; - private long loginAttemptLimitTimeout; - private boolean enabledXsrfProtection; - private boolean enabledUserConverter; - private String namespaceStrategy; - private String loginInfoUrl; - private String releaseFeedUrl; - private String mailDomainName; - } } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateApiKeyDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateApiKeyDto.java new file mode 100644 index 0000000000..cd7588ffb1 --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateApiKeyDto.java @@ -0,0 +1,35 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import javax.validation.constraints.NotEmpty; + +interface CreateApiKeyDto { + @NotEmpty + String getDisplayName(); + + @NotEmpty + String getPermissionRole(); +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateGroupDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateGroupDto.java index bc1324e0f1..82ed359010 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateGroupDto.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateGroupDto.java @@ -24,26 +24,19 @@ package sonia.scm.api.v2.resources; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; import sonia.scm.util.ValidationUtil; import javax.validation.constraints.Pattern; import java.util.List; -/** - * This class is currently only used in the openapi scheme - */ -@Getter -@Setter -@NoArgsConstructor -public class CreateGroupDto { +interface CreateGroupDto { @Pattern(regexp = ValidationUtil.REGEX_NAME) - private String name; - private String description; - private String type; - private List members; - private boolean external; + String getName(); + + String getDescription(); + + List getMembers(); + + boolean isExternal(); } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryDto.java new file mode 100644 index 0000000000..29d41bc075 --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryDto.java @@ -0,0 +1,53 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import sonia.scm.util.ValidationUtil; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Pattern; +import java.time.Instant; +import java.util.List; + +interface CreateRepositoryDto { + + String getNamespace(); + + @Pattern(regexp = ValidationUtil.REGEX_REPOSITORYNAME) + String getName(); + + @NotEmpty + String getType(); + + @Email + String getContact(); + + String getDescription(); + + List getHealthCheckFailures(); + + Instant getLastModified(); +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryRoleDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryRoleDto.java new file mode 100644 index 0000000000..0f524d39f2 --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateRepositoryRoleDto.java @@ -0,0 +1,40 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import javax.validation.constraints.NotEmpty; +import java.util.Collection; + +interface CreateRepositoryRoleDto { + + @NotEmpty + String getName(); + + @NoBlankStrings + @NotEmpty + Collection getVerbs(); + + String getType(); +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateUserDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateUserDto.java new file mode 100644 index 0000000000..ff0b36b404 --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/CreateUserDto.java @@ -0,0 +1,50 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import sonia.scm.util.ValidationUtil; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Pattern; + +interface CreateUserDto { + @Pattern(regexp = ValidationUtil.REGEX_NAME) + String getName(); + + @NotEmpty + String getDisplayName(); + + @Email + String getMail(); + + boolean isExternal(); + + String getPassword(); + + boolean isActive(); + + String getType(); +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/GroupDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/GroupDto.java index 24939609b3..8881470216 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/GroupDto.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/GroupDto.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + package sonia.scm.api.v2.resources; import com.fasterxml.jackson.annotation.JsonInclude; @@ -40,7 +40,7 @@ import java.util.List; @Getter @Setter @NoArgsConstructor -public class GroupDto extends HalRepresentation { +public class GroupDto extends HalRepresentation implements UpdateGroupDto, CreateGroupDto { private Instant creationDate; private String description; diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/GroupResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/GroupResource.java index 8245430c46..00a41d7526 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/GroupResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/GroupResource.java @@ -24,24 +24,18 @@ package sonia.scm.api.v2.resources; -import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; import sonia.scm.group.Group; import sonia.scm.group.GroupManager; -import sonia.scm.util.ValidationUtil; import sonia.scm.web.VndMediaType; import javax.inject.Inject; import javax.validation.Valid; -import javax.validation.constraints.Pattern; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -50,8 +44,6 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; -import java.time.Instant; -import java.util.List; public class GroupResource { @@ -190,19 +182,4 @@ public class GroupResource { return groupPermissionResource; } - /** - * This class is currently only used in the openapi scheme - */ - @Getter - @NoArgsConstructor(access = AccessLevel.PRIVATE) - private static final class UpdateGroupDto { - @Pattern(regexp = ValidationUtil.REGEX_NAME) - private String name; - private String description; - @JsonInclude(JsonInclude.Include.NON_NULL) - private Instant lastModified; - private String type; - private List members; - private boolean external; - } } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/NamespacePermissionResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/NamespacePermissionResource.java index ed507c7ba5..68ead6ec60 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/NamespacePermissionResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/NamespacePermissionResource.java @@ -98,7 +98,7 @@ public class NamespacePermissionResource { requestBody = @RequestBody( content = @Content( mediaType = VndMediaType.REPOSITORY_PERMISSION, - schema = @Schema(implementation = UpdatePermissionListDto.class), + schema = @Schema(implementation = UpdateRepositoryPermissionDto.class), examples = @ExampleObject( name = "Add read permissions for repositories and pull requests to manager group.", value = "{\n \"name\":\"manager\",\n \"verbs\":[\"read\",\"readPullRequest\"],\n \"groupPermission\":true\n}", @@ -244,7 +244,7 @@ public class NamespacePermissionResource { requestBody = @RequestBody( content = @Content( mediaType = VndMediaType.REPOSITORY_PERMISSION, - schema = @Schema(implementation = UpdatePermissionListDto.class), + schema = @Schema(implementation = UpdateRepositoryPermissionDto.class), examples = @ExampleObject( name = "Update permissions of manager group.", value = "{\n \"name\":\"manager\",\n \"verbs\":[\"read\",\"permissionRead\",\"readPullRequest\"],\n \"groupPermission\":true\n}", diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PermissionListDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PermissionListDto.java index 0a4ae5a1a5..1cfd13d3ad 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PermissionListDto.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PermissionListDto.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + package sonia.scm.api.v2.resources; import de.otto.edison.hal.HalRepresentation; @@ -37,7 +37,7 @@ import javax.validation.constraints.NotNull; @Setter @AllArgsConstructor @NoArgsConstructor -public class PermissionListDto extends HalRepresentation { +public class PermissionListDto extends HalRepresentation implements UpdatePermissionListDto { @NotNull private String[] permissions; diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryCollectionResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryCollectionResource.java index 41e5a8a7e4..19d2daf8bd 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryCollectionResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryCollectionResource.java @@ -24,7 +24,6 @@ package sonia.scm.api.v2.resources; -import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.headers.Header; import io.swagger.v3.oas.annotations.media.Content; @@ -32,9 +31,6 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; import org.apache.shiro.SecurityUtils; import sonia.scm.repository.Repository; import sonia.scm.repository.RepositoryInitializer; @@ -43,14 +39,10 @@ import sonia.scm.repository.RepositoryPermission; import sonia.scm.search.SearchRequest; import sonia.scm.search.SearchUtil; import sonia.scm.user.User; -import sonia.scm.util.ValidationUtil; import sonia.scm.web.VndMediaType; import javax.inject.Inject; import javax.validation.Valid; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.Pattern; import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; @@ -60,8 +52,6 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; -import java.time.Instant; -import java.util.List; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; @@ -248,22 +238,4 @@ public class RepositoryCollectionResource { return repository -> SearchUtil.matchesOne(searchRequest, repository.getName(), repository.getNamespace(), repository.getDescription()); } - /** - * This class is currently only used in the openapi scheme - */ - @Getter - @NoArgsConstructor(access = AccessLevel.PRIVATE) - private static final class CreateRepositoryDto { - private String namespace; - @Pattern(regexp = ValidationUtil.REGEX_REPOSITORYNAME) - private String name; - @NotEmpty - private String type; - @Email - private String contact; - private String description; - private List healthCheckFailures; - @JsonInclude(JsonInclude.Include.NON_NULL) - private Instant lastModified; - } } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryDto.java index 2bb457e029..951470a98c 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryDto.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryDto.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + package sonia.scm.api.v2.resources; import com.fasterxml.jackson.annotation.JsonInclude; @@ -42,7 +42,7 @@ import java.util.List; @Getter @Setter @NoArgsConstructor -public class RepositoryDto extends HalRepresentation { +public class RepositoryDto extends HalRepresentation implements CreateRepositoryDto, UpdateRepositoryDto { @Email private String contact; diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryPermissionDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryPermissionDto.java index 4c533722b9..05c23f0d73 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryPermissionDto.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryPermissionDto.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + package sonia.scm.api.v2.resources; import de.otto.edison.hal.HalRepresentation; @@ -39,7 +39,7 @@ import java.util.Collection; @Getter @Setter @ToString @NoArgsConstructor @EitherRoleOrVerbs -public class RepositoryPermissionDto extends HalRepresentation { +public class RepositoryPermissionDto extends HalRepresentation implements UpdateRepositoryPermissionDto { public static final String GROUP_PREFIX = "@"; diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryPermissionRootResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryPermissionRootResource.java index 5883a50d39..e0bfda0824 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryPermissionRootResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryPermissionRootResource.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + package sonia.scm.api.v2.resources; import io.swagger.v3.oas.annotations.Operation; @@ -100,7 +100,7 @@ public class RepositoryPermissionRootResource { requestBody = @RequestBody( content = @Content( mediaType = VndMediaType.REPOSITORY_PERMISSION, - schema = @Schema(implementation = UpdatePermissionListDto.class), + schema = @Schema(implementation = UpdateRepositoryPermissionDto.class), examples = @ExampleObject( name = "Add read permissions for repository and pull requests to manager group.", value = "{\n \"name\":\"manager\",\n \"verbs\":[\"read\",\"readPullRequest\"],\n \"groupPermission\":true\n}", @@ -252,7 +252,7 @@ public class RepositoryPermissionRootResource { requestBody = @RequestBody( content = @Content( mediaType = VndMediaType.REPOSITORY_PERMISSION, - schema = @Schema(implementation = UpdatePermissionListDto.class), + schema = @Schema(implementation = UpdateRepositoryPermissionDto.class), examples = @ExampleObject( name = "Update permissions of manager group.", value = "{\n \"name\":\"manager\",\n \"verbs\":[\"read\",\"permissionRead\",\"readPullRequest\"],\n \"groupPermission\":true\n}", diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryResource.java index ecc044f096..17f82d06b7 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryResource.java @@ -24,27 +24,19 @@ package sonia.scm.api.v2.resources; -import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; import sonia.scm.repository.NamespaceAndName; import sonia.scm.repository.Repository; import sonia.scm.repository.RepositoryManager; -import sonia.scm.util.ValidationUtil; import sonia.scm.web.VndMediaType; import javax.inject.Inject; import javax.validation.Valid; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.Pattern; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -54,8 +46,6 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; -import java.time.Instant; -import java.util.List; import java.util.Optional; import java.util.function.Predicate; import java.util.function.Supplier; @@ -301,22 +291,4 @@ public class RepositoryResource { return changed -> name.equals(changed.getName()) && namespace.equals(changed.getNamespace()); } - /** - * This class is currently only used in the openapi scheme - */ - @Getter - @NoArgsConstructor(access = AccessLevel.PRIVATE) - private static final class UpdateRepositoryDto { - private String namespace; - @Pattern(regexp = ValidationUtil.REGEX_REPOSITORYNAME) - private String name; - @NotEmpty - private String type; - @Email - private String contact; - private String description; - private List healthCheckFailures; - @JsonInclude(JsonInclude.Include.NON_NULL) - private Instant lastModified; - } } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleCollectionResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleCollectionResource.java index 946be8e6ee..bd82ac4210 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleCollectionResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleCollectionResource.java @@ -31,16 +31,12 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; import sonia.scm.repository.RepositoryRole; import sonia.scm.repository.RepositoryRoleManager; import sonia.scm.web.VndMediaType; import javax.inject.Inject; import javax.validation.Valid; -import javax.validation.constraints.NotEmpty; import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; @@ -49,7 +45,6 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; -import java.util.Collection; public class RepositoryRoleCollectionResource { @@ -160,17 +155,4 @@ public class RepositoryRoleCollectionResource { return adapter.create(repositoryRole, () -> dtoToRepositoryRoleMapper.map(repositoryRole), u -> resourceLinks.repositoryRole().self(u.getName())); } - /** - * This class is currently only used in the openapi scheme - */ - @Getter - @NoArgsConstructor(access = AccessLevel.PRIVATE) - private static final class CreateRepositoryRoleDto { - @NotEmpty - private String name; - private boolean system; - @NoBlankStrings @NotEmpty - private Collection verbs; - private String type; - } } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleDto.java index 7efef72826..1174ea48af 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleDto.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleDto.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + package sonia.scm.api.v2.resources; import de.otto.edison.hal.Embedded; @@ -38,7 +38,7 @@ import java.util.Collection; @Getter @Setter @NoArgsConstructor -public class RepositoryRoleDto extends HalRepresentation { +public class RepositoryRoleDto extends HalRepresentation implements CreateRepositoryRoleDto, UpdateRepositoryRoleDto { @NotEmpty private String name; @NoBlankStrings @NotEmpty diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleResource.java index 72c8fbe4c8..c9367cf655 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/RepositoryRoleResource.java @@ -30,16 +30,12 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; import sonia.scm.repository.RepositoryRole; import sonia.scm.repository.RepositoryRoleManager; import sonia.scm.web.VndMediaType; import javax.inject.Inject; import javax.validation.Valid; -import javax.validation.constraints.NotEmpty; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -48,8 +44,6 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; -import java.time.Instant; -import java.util.Collection; public class RepositoryRoleResource { @@ -168,18 +162,4 @@ public class RepositoryRoleResource { return adapter.update(name, existing -> dtoToRepositoryRoleMapper.map(repositoryRole)); } - /** - * This class is currently only used in the openapi scheme - */ - @Getter - @NoArgsConstructor(access = AccessLevel.PRIVATE) - private static final class UpdateRepositoryRoleDto { - @NotEmpty - private String name; - private boolean system; - @NoBlankStrings @NotEmpty - private Collection verbs; - private String type; - private Instant lastModified; - } } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateConfigDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateConfigDto.java new file mode 100644 index 0000000000..dbe07a2620 --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateConfigDto.java @@ -0,0 +1,77 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import sonia.scm.security.AnonymousMode; + +import java.util.Set; + +interface UpdateConfigDto { + String getProxyPassword(); + + int getProxyPort(); + + String getProxyServer(); + + String getProxyUser(); + + boolean isEnableProxy(); + + String getRealmDescription(); + + boolean isDisableGroupingGrid(); + + String getDateFormat(); + + boolean isAnonymousAccessEnabled(); + + AnonymousMode getAnonymousMode(); + + String getBaseUrl(); + + boolean isForceBaseUrl(); + + int getLoginAttemptLimit(); + + Set getProxyExcludes(); + + boolean isSkipFailedAuthenticators(); + + String getPluginUrl(); + + long getLoginAttemptLimitTimeout(); + + boolean isEnabledXsrfProtection(); + + boolean isEnabledUserConverter(); + + String getNamespaceStrategy(); + + String getLoginInfoUrl(); + + String getReleaseFeedUrl(); + + String getMailDomainName(); +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateGroupDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateGroupDto.java new file mode 100644 index 0000000000..ba91365c3c --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateGroupDto.java @@ -0,0 +1,50 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import com.fasterxml.jackson.annotation.JsonInclude; +import sonia.scm.util.ValidationUtil; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Pattern; +import java.time.Instant; +import java.util.List; + +interface UpdateGroupDto { + + @Pattern(regexp = ValidationUtil.REGEX_NAME) + String getName(); + + String getDescription(); + + @JsonInclude(JsonInclude.Include.NON_NULL) + Instant getLastModified(); + + String getType(); + + List getMembers(); + + boolean isExternal(); +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdatePermissionListDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdatePermissionListDto.java index 00c49e43d7..90fb81a34a 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdatePermissionListDto.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdatePermissionListDto.java @@ -24,18 +24,10 @@ package sonia.scm.api.v2.resources; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - import javax.validation.constraints.NotNull; -/** - * This class is currently only used in the openapi scheme - */ -@Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) -final class UpdatePermissionListDto { +interface UpdatePermissionListDto { + @NotNull - private String[] permissions; + String[] getPermissions(); } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryDto.java new file mode 100644 index 0000000000..9b50ba04df --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryDto.java @@ -0,0 +1,55 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import com.fasterxml.jackson.annotation.JsonInclude; +import sonia.scm.util.ValidationUtil; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Pattern; +import java.time.Instant; +import java.util.List; + +interface UpdateRepositoryDto { + + String getNamespace(); + + @Pattern(regexp = ValidationUtil.REGEX_REPOSITORYNAME) + String getName(); + + @NotEmpty + String getType(); + + @Email + String getContact(); + + String getDescription(); + + List getHealthCheckFailures(); + + @JsonInclude(JsonInclude.Include.NON_NULL) + Instant getLastModified(); +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryPermissionDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryPermissionDto.java new file mode 100644 index 0000000000..c726ad5ca5 --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryPermissionDto.java @@ -0,0 +1,43 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import sonia.scm.util.ValidationUtil; + +import javax.validation.constraints.Pattern; +import java.util.Collection; + +interface UpdateRepositoryPermissionDto { + + @Pattern(regexp = ValidationUtil.REGEX_NAME) + String getName(); + + @NoBlankStrings + Collection getVerbs(); + + String getRole(); + + boolean isGroupPermission(); +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryRoleDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryRoleDto.java new file mode 100644 index 0000000000..499c0da7dd --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateRepositoryRoleDto.java @@ -0,0 +1,43 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import javax.validation.constraints.NotEmpty; +import java.time.Instant; +import java.util.Collection; + +interface UpdateRepositoryRoleDto { + + @NotEmpty + String getName(); + + @NoBlankStrings + @NotEmpty + Collection getVerbs(); + + String getType(); + + Instant getLastModified(); +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateUserDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateUserDto.java new file mode 100644 index 0000000000..a4b359c005 --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UpdateUserDto.java @@ -0,0 +1,54 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package sonia.scm.api.v2.resources; + +import sonia.scm.util.ValidationUtil; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Pattern; +import java.time.Instant; + +interface UpdateUserDto { + + @Pattern(regexp = ValidationUtil.REGEX_NAME) + String getName(); + + @NotEmpty + String getDisplayName(); + + @Email + String getMail(); + + boolean isExternal(); + + String getPassword(); + + boolean isActive(); + + String getType(); + + Instant getLastModified(); +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserCollectionResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserCollectionResource.java index 211a5823d5..12d5294769 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserCollectionResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserCollectionResource.java @@ -24,7 +24,6 @@ package sonia.scm.api.v2.resources; -import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.headers.Header; import io.swagger.v3.oas.annotations.media.Content; @@ -32,23 +31,16 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; import org.apache.shiro.authc.credential.PasswordService; import sonia.scm.search.SearchRequest; import sonia.scm.search.SearchUtil; import sonia.scm.user.User; import sonia.scm.user.UserManager; import sonia.scm.user.UserPermissions; -import sonia.scm.util.ValidationUtil; import sonia.scm.web.VndMediaType; import javax.inject.Inject; import javax.validation.Valid; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.Pattern; import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; @@ -182,23 +174,4 @@ public class UserCollectionResource { return user -> SearchUtil.matchesOne(searchRequest, user.getName(), user.getDisplayName(), user.getMail()); } - /** - * This class is currently only used in the openapi scheme - */ - @Getter - @NoArgsConstructor(access = AccessLevel.PRIVATE) - private static final class CreateUserDto { - @Pattern(regexp = ValidationUtil.REGEX_NAME) - private String name; - @NotEmpty - private String displayName; - @JsonInclude(JsonInclude.Include.NON_NULL) - @Email - private String mail; - private boolean external; - @JsonInclude(JsonInclude.Include.NON_NULL) - private String password; - private boolean active; - private String type; - } } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserDto.java index b1eaa1d7a6..26f120b870 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserDto.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserDto.java @@ -39,7 +39,7 @@ import javax.validation.constraints.Pattern; import java.time.Instant; @NoArgsConstructor @Getter @Setter -public class UserDto extends HalRepresentation { +public class UserDto extends HalRepresentation implements CreateUserDto, UpdateUserDto { private boolean active; private boolean external; private Instant creationDate; diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserResource.java index db94bf1195..76902505d7 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserResource.java @@ -24,27 +24,19 @@ package sonia.scm.api.v2.resources; -import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; import org.apache.shiro.authc.credential.PasswordService; import sonia.scm.user.User; import sonia.scm.user.UserManager; -import sonia.scm.util.ValidationUtil; import sonia.scm.web.VndMediaType; import javax.inject.Inject; import javax.validation.Valid; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.Pattern; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -53,7 +45,6 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; -import java.time.Instant; public class UserResource { @@ -312,25 +303,4 @@ public class UserResource { return userPermissionResource; } - /** - * This class is currently only used in the openapi scheme - */ - @Getter - @NoArgsConstructor(access = AccessLevel.PRIVATE) - private static final class UpdateUserDto { - @Pattern(regexp = ValidationUtil.REGEX_NAME) - private String name; - @NotEmpty - private String displayName; - @JsonInclude(JsonInclude.Include.NON_NULL) - @Email - private String mail; - private boolean external; - @JsonInclude(JsonInclude.Include.NON_NULL) - private String password; - private boolean active; - private String type; - @JsonInclude(JsonInclude.Include.NON_NULL) - private Instant lastModified; - } }