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