mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-02 03:25:56 +01:00
Preferred checkout variant
Add ability to prioritize the repository checkout variants. These are displayed sorted. Co-authored-by: Eduard Heimbuch<eduard.heimbuch@cloudogu.com> Pushed-by: Florian Scholdei<florian.scholdei@cloudogu.com> Co-authored-by: Florian Scholdei<florian.scholdei@cloudogu.com> Pushed-by: Eduard Heimbuch<eduard.heimbuch@cloudogu.com>
This commit is contained in:
@@ -34,6 +34,7 @@ import sonia.scm.config.ConfigurationPermissions;
|
||||
import sonia.scm.store.ConfigurationStore;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Provider;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
@@ -143,7 +144,10 @@ public abstract class ConfigurationAdapterBase<DAO, DTO extends HalRepresentatio
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("")
|
||||
public DTO get(@Context UriInfo uriInfo) {
|
||||
getReadPermission().check();
|
||||
PermissionCheck readPermission = getReadPermission();
|
||||
if (readPermission != null) {
|
||||
readPermission.check();
|
||||
}
|
||||
return daoToDtoMapper.mapDaoToDto(getConfiguration(), createDtoLinks());
|
||||
}
|
||||
|
||||
@@ -163,14 +167,18 @@ public abstract class ConfigurationAdapterBase<DAO, DTO extends HalRepresentatio
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Path("")
|
||||
public void update(@NotNull @Valid DTO payload) {
|
||||
getWritePermission().check();
|
||||
PermissionCheck writePermission = getWritePermission();
|
||||
if (writePermission != null) {
|
||||
writePermission.check();
|
||||
}
|
||||
getConfigStore().set(dtoToDaoMapper.mapDtoToDao(payload));
|
||||
}
|
||||
|
||||
private Links.Builder createDtoLinks() {
|
||||
Links.Builder builder = Links.linkingTo();
|
||||
builder.single(Link.link("self", getReadLink()));
|
||||
if (getWritePermission().isPermitted()) {
|
||||
PermissionCheck writePermission = getWritePermission();
|
||||
if (writePermission == null || writePermission.isPermitted()) {
|
||||
builder.single(Link.link("update", getUpdateLink()));
|
||||
}
|
||||
|
||||
@@ -189,15 +197,18 @@ public abstract class ConfigurationAdapterBase<DAO, DTO extends HalRepresentatio
|
||||
|
||||
@Override
|
||||
public final void enrich(HalEnricherContext context, HalAppender appender) {
|
||||
if (getReadPermission().isPermitted()) {
|
||||
PermissionCheck readPermission = getReadPermission();
|
||||
if (readPermission == null || readPermission.isPermitted()) {
|
||||
appender.appendLink(getName(), getReadLink());
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected PermissionCheck getReadPermission() {
|
||||
return ConfigurationPermissions.read(getName());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected PermissionCheck getWritePermission() {
|
||||
return ConfigurationPermissions.write(getName());
|
||||
}
|
||||
|
||||
@@ -47,4 +47,14 @@ public interface ScmProtocol {
|
||||
default boolean isAnonymousEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Priority for frontend evaluation order
|
||||
*
|
||||
* @return priority number
|
||||
* @since 2.48.0
|
||||
*/
|
||||
default int getPriority() {
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,11 @@ public abstract class HttpScmProtocol implements ScmProtocol {
|
||||
return URI.create(basePath + "/").resolve(String.format("repo/%s/%s", HttpUtil.encode(repository.getNamespace()), HttpUtil.encode(repository.getName()))).toASCIIString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return 150;
|
||||
}
|
||||
|
||||
public final void serve(HttpServletRequest request, HttpServletResponse response, ServletConfig config) throws ServletException, IOException {
|
||||
serve(request, response, repository, config);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user