mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25:44 +01:00
enhance NamespaceStrategy API / improve frontend validation and use namespace extension point in RenameRepository component
This commit is contained in:
@@ -32,6 +32,7 @@ import org.mapstruct.ObjectFactory;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.repository.Feature;
|
||||
import sonia.scm.repository.HealthCheckFailure;
|
||||
import sonia.scm.repository.NamespaceStrategy;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryPermissions;
|
||||
import sonia.scm.repository.api.Command;
|
||||
@@ -43,6 +44,7 @@ import sonia.scm.web.api.RepositoryToHalMapper;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static de.otto.edison.hal.Embedded.embeddedBuilder;
|
||||
import static de.otto.edison.hal.Link.link;
|
||||
@@ -60,6 +62,8 @@ public abstract class RepositoryToRepositoryDtoMapper extends BaseMapper<Reposit
|
||||
private ScmConfiguration scmConfiguration;
|
||||
@Inject
|
||||
private RepositoryServiceFactory serviceFactory;
|
||||
@Inject
|
||||
private Set<NamespaceStrategy> strategies;
|
||||
|
||||
abstract HealthCheckFailureDto toDto(HealthCheckFailure failure);
|
||||
|
||||
@@ -76,7 +80,7 @@ public abstract class RepositoryToRepositoryDtoMapper extends BaseMapper<Reposit
|
||||
linksBuilder.single(link("update", resourceLinks.repository().update(repository.getNamespace(), repository.getName())));
|
||||
}
|
||||
if (RepositoryPermissions.rename(repository).isPermitted()) {
|
||||
if (scmConfiguration.getNamespaceStrategy().equals("CustomNamespaceStrategy")) {
|
||||
if (isRenameNamespacePossible()) {
|
||||
linksBuilder.single(link("renameWithNamespace", resourceLinks.repository().rename(repository.getNamespace(), repository.getName())));
|
||||
} else {
|
||||
linksBuilder.single(link("rename", resourceLinks.repository().rename(repository.getNamespace(), repository.getName())));
|
||||
@@ -115,6 +119,15 @@ public abstract class RepositoryToRepositoryDtoMapper extends BaseMapper<Reposit
|
||||
return new RepositoryDto(linksBuilder.build(), embeddedBuilder.build());
|
||||
}
|
||||
|
||||
private boolean isRenameNamespacePossible() {
|
||||
for (NamespaceStrategy strategy : strategies) {
|
||||
if (strategy.getClass().getSimpleName().equals(scmConfiguration.getNamespaceStrategy())) {
|
||||
return strategy.canBeChanged();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Link createProtocolLink(ScmProtocol protocol) {
|
||||
return Link.linkBuilder("protocol", protocol.getUrl()).withName(protocol.getType()).build();
|
||||
}
|
||||
|
||||
@@ -50,4 +50,9 @@ public class CurrentYearNamespaceStrategy implements NamespaceStrategy {
|
||||
public String createNamespace(Repository repository) {
|
||||
return String.valueOf(Year.now(clock).getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeChanged() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,4 +41,9 @@ public class CustomNamespaceStrategy implements NamespaceStrategy {
|
||||
|
||||
return namespace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeChanged() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
import sonia.scm.plugin.Extension;
|
||||
@@ -32,4 +32,9 @@ public class RepositoryTypeNamespaceStrategy implements NamespaceStrategy {
|
||||
public String createNamespace(Repository repository) {
|
||||
return repository.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeChanged() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
@@ -34,4 +34,9 @@ public class UsernameNamespaceStrategy implements NamespaceStrategy {
|
||||
public String createNamespace(Repository repository) {
|
||||
return SecurityUtils.getSubject().getPrincipal().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeChanged() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user