use of org.eclipse.openvsx.json.NamespaceJson in project openvsx by eclipse.
the class LocalRegistryService method getNamespace.
@Override
public NamespaceJson getNamespace(String namespaceName) {
var namespace = repositories.findNamespace(namespaceName);
if (namespace == null)
throw new NotFoundException();
var json = new NamespaceJson();
json.name = namespace.getName();
json.extensions = new LinkedHashMap<>();
var serverUrl = UrlUtil.getBaseUrl();
for (var ext : repositories.findActiveExtensions(namespace)) {
String url = createApiUrl(serverUrl, "api", namespace.getName(), ext.getName());
json.extensions.put(ext.getName(), url);
}
json.verified = repositories.countMemberships(namespace, NamespaceMembership.ROLE_OWNER) > 0;
json.access = "restricted";
return json;
}
use of org.eclipse.openvsx.json.NamespaceJson in project openvsx by eclipse.
the class AdminAPITest method testCreateNamespace.
@Test
public void testCreateNamespace() throws Exception {
mockAdminUser();
mockMvc.perform(post("/admin/create-namespace").contentType(MediaType.APPLICATION_JSON).content(namespaceJson(n -> {
n.name = "foobar";
})).with(user("admin_user").authorities(new SimpleGrantedAuthority(("ROLE_ADMIN")))).with(csrf().asHeader())).andExpect(status().isCreated()).andExpect(redirectedUrl("http://localhost/admin/namespace/foobar")).andExpect(content().json(successJson("Created namespace foobar")));
}
use of org.eclipse.openvsx.json.NamespaceJson in project openvsx by eclipse.
the class UserAPI method getOwnNamespaces.
@GetMapping(path = "/user/namespaces", produces = MediaType.APPLICATION_JSON_VALUE)
public List<NamespaceJson> getOwnNamespaces() {
var user = users.findLoggedInUser();
if (user == null) {
throw new ResponseStatusException(HttpStatus.FORBIDDEN);
}
var memberships = repositories.findMemberships(user, NamespaceMembership.ROLE_OWNER);
return memberships.map(membership -> {
var namespace = membership.getNamespace();
var json = new NamespaceJson();
json.name = namespace.getName();
json.extensions = new LinkedHashMap<>();
var serverUrl = UrlUtil.getBaseUrl();
for (var ext : repositories.findActiveExtensions(namespace)) {
String url = createApiUrl(serverUrl, "api", namespace.getName(), ext.getName());
json.extensions.put(ext.getName(), url);
}
json.verified = true;
json.membersUrl = createApiUrl(serverUrl, "user", "namespace", namespace.getName(), "members");
json.roleUrl = createApiUrl(serverUrl, "user", "namespace", namespace.getName(), "role");
return json;
}).toList();
}
use of org.eclipse.openvsx.json.NamespaceJson in project openvsx by eclipse.
the class RegistryAPITest method namespaceJson.
private String namespaceJson(Consumer<NamespaceJson> content) throws JsonProcessingException {
var json = new NamespaceJson();
content.accept(json);
return new ObjectMapper().writeValueAsString(json);
}
use of org.eclipse.openvsx.json.NamespaceJson in project openvsx by eclipse.
the class AdminAPITest method namespaceJson.
private String namespaceJson(Consumer<NamespaceJson> content) throws JsonProcessingException {
var json = new NamespaceJson();
content.accept(json);
return new ObjectMapper().writeValueAsString(json);
}
Aggregations