mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 17:26:22 +01:00
Small fixes
This commit is contained in:
@@ -41,7 +41,7 @@ public class IndexDtoGenerator extends HalAppenderMapper {
|
|||||||
link("me", resourceLinks.me().self()),
|
link("me", resourceLinks.me().self()),
|
||||||
link("logout", resourceLinks.authentication().logout())
|
link("logout", resourceLinks.authentication().logout())
|
||||||
);
|
);
|
||||||
if (PluginPermissions.custom(PluginPermissions.ACTION_READ).isPermitted()) {
|
if (PluginPermissions.read().isPermitted()) {
|
||||||
builder.single(link("plugins", resourceLinks.pluginCollection().self()));
|
builder.single(link("plugins", resourceLinks.pluginCollection().self()));
|
||||||
}
|
}
|
||||||
if (UserPermissions.list().isPermitted()) {
|
if (UserPermissions.list().isPermitted()) {
|
||||||
|
|||||||
@@ -18,9 +18,7 @@ public class PluginDto extends HalRepresentation {
|
|||||||
private String author;
|
private String author;
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@Override
|
public PluginDto(Links links) {
|
||||||
protected HalRepresentation add(Links links) {
|
add(links);
|
||||||
return super.add(links);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,35 +3,30 @@ package sonia.scm.api.v2.resources;
|
|||||||
import de.otto.edison.hal.Links;
|
import de.otto.edison.hal.Links;
|
||||||
import sonia.scm.plugin.PluginWrapper;
|
import sonia.scm.plugin.PluginWrapper;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
import static de.otto.edison.hal.Links.linkingTo;
|
import static de.otto.edison.hal.Links.linkingTo;
|
||||||
|
|
||||||
public class PluginDtoMapper {
|
public class PluginDtoMapper {
|
||||||
|
|
||||||
private final ResourceLinks resourceLinks;
|
private final ResourceLinks resourceLinks;
|
||||||
private final HttpServletRequest request;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public PluginDtoMapper(ResourceLinks resourceLinks, HttpServletRequest request) {
|
public PluginDtoMapper(ResourceLinks resourceLinks) {
|
||||||
this.resourceLinks = resourceLinks;
|
this.resourceLinks = resourceLinks;
|
||||||
this.request = request;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginDto map(PluginWrapper plugin) {
|
public PluginDto map(PluginWrapper plugin) {
|
||||||
PluginDto pluginDto = new PluginDto();
|
Links.Builder linksBuilder = linkingTo()
|
||||||
|
.self(resourceLinks.plugin()
|
||||||
|
.self(plugin.getId()));
|
||||||
|
|
||||||
|
PluginDto pluginDto = new PluginDto(linksBuilder.build());
|
||||||
pluginDto.setName(plugin.getPlugin().getInformation().getName());
|
pluginDto.setName(plugin.getPlugin().getInformation().getName());
|
||||||
pluginDto.setType(plugin.getPlugin().getInformation().getCategory() != null ? plugin.getPlugin().getInformation().getCategory() : "Miscellaneous");
|
pluginDto.setType(plugin.getPlugin().getInformation().getCategory() != null ? plugin.getPlugin().getInformation().getCategory() : "Miscellaneous");
|
||||||
pluginDto.setVersion(plugin.getPlugin().getInformation().getVersion());
|
pluginDto.setVersion(plugin.getPlugin().getInformation().getVersion());
|
||||||
pluginDto.setAuthor(plugin.getPlugin().getInformation().getAuthor());
|
pluginDto.setAuthor(plugin.getPlugin().getInformation().getAuthor());
|
||||||
pluginDto.setDescription(plugin.getPlugin().getInformation().getDescription());
|
pluginDto.setDescription(plugin.getPlugin().getInformation().getDescription());
|
||||||
|
|
||||||
Links.Builder linksBuilder = linkingTo()
|
|
||||||
.self(resourceLinks.uiPlugin()
|
|
||||||
.self(plugin.getId()));
|
|
||||||
|
|
||||||
pluginDto.add(linksBuilder.build());
|
|
||||||
|
|
||||||
return pluginDto;
|
return pluginDto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package sonia.scm.api.v2.resources;
|
|||||||
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
||||||
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
import com.webcohesion.enunciate.metadata.rs.TypeHint;
|
import com.webcohesion.enunciate.metadata.rs.TypeHint;
|
||||||
|
import sonia.scm.plugin.Plugin;
|
||||||
import sonia.scm.plugin.PluginLoader;
|
import sonia.scm.plugin.PluginLoader;
|
||||||
import sonia.scm.plugin.PluginPermissions;
|
import sonia.scm.plugin.PluginPermissions;
|
||||||
import sonia.scm.plugin.PluginWrapper;
|
import sonia.scm.plugin.PluginWrapper;
|
||||||
@@ -14,9 +15,12 @@ import javax.ws.rs.Path;
|
|||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
||||||
|
import static sonia.scm.NotFoundException.notFound;
|
||||||
|
|
||||||
public class PluginResource {
|
public class PluginResource {
|
||||||
|
|
||||||
@@ -45,10 +49,8 @@ public class PluginResource {
|
|||||||
@TypeHint(CollectionDto.class)
|
@TypeHint(CollectionDto.class)
|
||||||
@Produces(VndMediaType.PLUGIN_COLLECTION)
|
@Produces(VndMediaType.PLUGIN_COLLECTION)
|
||||||
public Response getInstalledPlugins() {
|
public Response getInstalledPlugins() {
|
||||||
List<PluginWrapper> plugins = pluginLoader.getInstalledPlugins()
|
|
||||||
.stream()
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
PluginPermissions.read().check();
|
PluginPermissions.read().check();
|
||||||
|
List<PluginWrapper> plugins = new ArrayList<>(pluginLoader.getInstalledPlugins());
|
||||||
return Response.ok(collectionMapper.map(plugins)).build();
|
return Response.ok(collectionMapper.map(plugins)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,16 +71,16 @@ public class PluginResource {
|
|||||||
@TypeHint(PluginDto.class)
|
@TypeHint(PluginDto.class)
|
||||||
@Produces(VndMediaType.PLUGIN)
|
@Produces(VndMediaType.PLUGIN)
|
||||||
public Response getInstalledPlugin(@PathParam("id") String id) {
|
public Response getInstalledPlugin(@PathParam("id") String id) {
|
||||||
|
PluginPermissions.read().check();
|
||||||
Optional<PluginDto> pluginDto = pluginLoader.getInstalledPlugins()
|
Optional<PluginDto> pluginDto = pluginLoader.getInstalledPlugins()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(plugin -> id.equals(plugin.getId()))
|
.filter(plugin -> id.equals(plugin.getId()))
|
||||||
.map(mapper::map)
|
.map(mapper::map)
|
||||||
.findFirst();
|
.findFirst();
|
||||||
PluginPermissions.read().check();
|
|
||||||
if (pluginDto.isPresent()) {
|
if (pluginDto.isPresent()) {
|
||||||
return Response.ok(pluginDto.get()).build();
|
return Response.ok(pluginDto.get()).build();
|
||||||
} else {
|
} else {
|
||||||
return Response.status(Response.Status.NOT_FOUND).build();
|
throw notFound(entity(Plugin.class, id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,9 +70,10 @@
|
|||||||
<value>repositoryRole:read,write</value>
|
<value>repositoryRole:read,write</value>
|
||||||
</permission>
|
</permission>
|
||||||
<permission>
|
<permission>
|
||||||
<value>plugin:read:*</value>
|
<value>plugin:read</value>
|
||||||
</permission>
|
</permission>
|
||||||
<permission>
|
<permission>
|
||||||
<value>plugin:read,write:*</value>
|
<value>plugin:read,write</value>
|
||||||
</permission>
|
</permission>
|
||||||
</permissions>
|
</permissions>
|
||||||
|
|
||||||
|
|||||||
@@ -68,17 +68,13 @@
|
|||||||
},
|
},
|
||||||
"plugin": {
|
"plugin": {
|
||||||
"read": {
|
"read": {
|
||||||
"*": {
|
|
||||||
"displayName": "Alle Plugins lesen",
|
"displayName": "Alle Plugins lesen",
|
||||||
"description": "Darf alle installierten und verfügbaren Plugins lesen"
|
"description": "Darf alle installierten und verfügbaren Plugins lesen"
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"read,write": {
|
"read,write": {
|
||||||
"*": {
|
|
||||||
"displayName": "Alle Plugins lesen und verwalten",
|
"displayName": "Alle Plugins lesen und verwalten",
|
||||||
"description": "Darf alle installierten und verfügbaren Plugins lesen und verwalten"
|
"description": "Darf alle installierten und verfügbaren Plugins lesen und verwalten"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"unknown": "Unbekannte Berechtigung"
|
"unknown": "Unbekannte Berechtigung"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -68,17 +68,13 @@
|
|||||||
},
|
},
|
||||||
"plugin": {
|
"plugin": {
|
||||||
"read": {
|
"read": {
|
||||||
"*": {
|
|
||||||
"displayName": "Read all plugins",
|
"displayName": "Read all plugins",
|
||||||
"description": "May see all installed and available plugins"
|
"description": "May see all installed and available plugins"
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"read,write": {
|
"read,write": {
|
||||||
"*": {
|
|
||||||
"displayName": "Read and manage all plugins",
|
"displayName": "Read and manage all plugins",
|
||||||
"description": "May see and manage all installed and available plugins"
|
"description": "May see and manage all installed and available plugins"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"unknown": "Unknown permission"
|
"unknown": "Unknown permission"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user