Search in sources :

Example 1 with ResultJson

use of org.eclipse.openvsx.json.ResultJson in project openvsx by eclipse.

the class AdminService method editNamespaceMember.

@Transactional(rollbackOn = ErrorResultException.class)
public ResultJson editNamespaceMember(String namespaceName, String userName, String provider, String role, UserData admin) throws ErrorResultException {
    var namespace = repositories.findNamespace(namespaceName);
    if (namespace == null) {
        throw new ErrorResultException("Namespace not found: " + namespaceName);
    }
    var user = repositories.findUserByLoginName(provider, userName);
    if (user == null) {
        throw new ErrorResultException("User not found: " + provider + "/" + userName);
    }
    ResultJson result;
    if (role.equals("remove")) {
        result = users.removeNamespaceMember(namespace, user);
    } else {
        result = users.addNamespaceMember(namespace, user, role);
    }
    for (var extension : repositories.findActiveExtensions(namespace)) {
        search.updateSearchEntry(extension);
    }
    logAdminAction(admin, result);
    return result;
}
Also used : ErrorResultException(org.eclipse.openvsx.util.ErrorResultException) ResultJson(org.eclipse.openvsx.json.ResultJson) Transactional(javax.transaction.Transactional)

Example 2 with ResultJson

use of org.eclipse.openvsx.json.ResultJson in project openvsx by eclipse.

the class AdminAPI method deleteExtension.

@PostMapping(path = "/admin/extension/{namespaceName}/{extensionName}/delete", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<ResultJson> deleteExtension(@PathVariable String namespaceName, @PathVariable String extensionName, @RequestBody(required = false) List<String> versions) {
    try {
        ResultJson result;
        var adminUser = admins.checkAdminUser();
        if (versions == null) {
            result = admins.deleteExtension(namespaceName, extensionName, adminUser);
        } else {
            var results = new ArrayList<ResultJson>();
            for (var version : versions) {
                results.add(admins.deleteExtensionVersion(namespaceName, extensionName, version, adminUser));
            }
            result = new ResultJson();
            result.error = results.stream().map(r -> r.error).filter(Objects::nonNull).collect(Collectors.joining("\n"));
            result.success = results.stream().map(r -> r.success).filter(Objects::nonNull).collect(Collectors.joining("\n"));
        }
        return ResponseEntity.ok(result);
    } catch (ErrorResultException exc) {
        return exc.toResponseEntity();
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) ExtensionVersion(org.eclipse.openvsx.entities.ExtensionVersion) RequestParam(org.springframework.web.bind.annotation.RequestParam) LocalDateTime(java.time.LocalDateTime) ErrorResultException(org.eclipse.openvsx.util.ErrorResultException) Autowired(org.springframework.beans.factory.annotation.Autowired) NamespaceMembershipListJson(org.eclipse.openvsx.json.NamespaceMembershipListJson) UrlUtil(org.eclipse.openvsx.util.UrlUtil) AdminStatistics(org.eclipse.openvsx.entities.AdminStatistics) TimeUtil(org.eclipse.openvsx.util.TimeUtil) ArrayList(java.util.ArrayList) RequestBody(org.springframework.web.bind.annotation.RequestBody) Strings(com.google.common.base.Strings) PersistedLog(org.eclipse.openvsx.entities.PersistedLog) NamespaceJson(org.eclipse.openvsx.json.NamespaceJson) GetMapping(org.springframework.web.bind.annotation.GetMapping) URI(java.net.URI) ExtensionJson(org.eclipse.openvsx.json.ExtensionJson) DateTimeException(java.time.DateTimeException) NotFoundException(org.eclipse.openvsx.util.NotFoundException) Period(java.time.Period) SearchUtilService(org.eclipse.openvsx.search.SearchUtilService) PostMapping(org.springframework.web.bind.annotation.PostMapping) LongStream(java.util.stream.LongStream) ResponseStatusException(org.springframework.web.server.ResponseStatusException) Extension(org.eclipse.openvsx.entities.Extension) MediaType(org.springframework.http.MediaType) SemanticVersion(org.eclipse.openvsx.util.SemanticVersion) ROLE_ADMIN(org.eclipse.openvsx.entities.UserData.ROLE_ADMIN) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) ResultJson(org.eclipse.openvsx.json.ResultJson) Objects(java.util.Objects) RepositoryService(org.eclipse.openvsx.repositories.RepositoryService) HttpStatus(org.springframework.http.HttpStatus) DateTimeParseException(java.time.format.DateTimeParseException) List(java.util.List) Streamable(org.springframework.data.util.Streamable) StatsJson(org.eclipse.openvsx.json.StatsJson) ResponseEntity(org.springframework.http.ResponseEntity) Collections(java.util.Collections) UserPublishInfoJson(org.eclipse.openvsx.json.UserPublishInfoJson) ErrorResultException(org.eclipse.openvsx.util.ErrorResultException) ResultJson(org.eclipse.openvsx.json.ResultJson) ArrayList(java.util.ArrayList) Objects(java.util.Objects) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

ResultJson (org.eclipse.openvsx.json.ResultJson)2 ErrorResultException (org.eclipse.openvsx.util.ErrorResultException)2 Strings (com.google.common.base.Strings)1 URI (java.net.URI)1 DateTimeException (java.time.DateTimeException)1 LocalDateTime (java.time.LocalDateTime)1 Period (java.time.Period)1 DateTimeParseException (java.time.format.DateTimeParseException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 LongStream (java.util.stream.LongStream)1 Transactional (javax.transaction.Transactional)1 AdminStatistics (org.eclipse.openvsx.entities.AdminStatistics)1 Extension (org.eclipse.openvsx.entities.Extension)1 ExtensionVersion (org.eclipse.openvsx.entities.ExtensionVersion)1 PersistedLog (org.eclipse.openvsx.entities.PersistedLog)1 ROLE_ADMIN (org.eclipse.openvsx.entities.UserData.ROLE_ADMIN)1