mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-04-01 09:50:16 +02:00
prepare ui and repository manager for directory structure
This commit is contained in:
@@ -219,8 +219,18 @@ public abstract class AbstractSimpleRepositoryHandler<C extends SimpleRepository
|
||||
|
||||
if (isConfigured())
|
||||
{
|
||||
directory = new File(config.getRepositoryDirectory(),
|
||||
repository.getName());
|
||||
File repositoryDirectory = config.getRepositoryDirectory();
|
||||
|
||||
directory = new File(repositoryDirectory, repository.getName());
|
||||
|
||||
if (!IOUtil.isChild(repositoryDirectory, directory))
|
||||
{
|
||||
StringBuilder msg = new StringBuilder(directory.getPath());
|
||||
|
||||
msg.append("is not a child of ").append(repositoryDirectory.getPath());
|
||||
|
||||
throw new ConfigurationException(msg.toString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -434,7 +434,7 @@ public class Repository extends BasicPropertiesAware implements ModelObject
|
||||
/**
|
||||
* Returns true if the {@link Repository} is valid.
|
||||
* <ul>
|
||||
* <li>The name is not empty and contains only A-z, 0-9, _, -</li>
|
||||
* <li>The name is not empty and contains only A-z, 0-9, _, -, /</li>
|
||||
* <li>The type is not empty</li>
|
||||
* <li>The contact is empty or contains a valid email address</li>
|
||||
* </ul>
|
||||
@@ -445,7 +445,7 @@ public class Repository extends BasicPropertiesAware implements ModelObject
|
||||
@Override
|
||||
public boolean isValid()
|
||||
{
|
||||
return ValidationUtil.isNameValid(name) && Util.isNotEmpty(type)
|
||||
return ValidationUtil.isRepositoryNameValid(name) && Util.isNotEmpty(type)
|
||||
&& ((Util.isEmpty(contact))
|
||||
|| ValidationUtil.isMailAddressValid(contact));
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ import sonia.scm.TypeManager;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* The central class for managing {@link Repository} objects.
|
||||
* This class is a singleton and is available via injection.
|
||||
@@ -80,6 +82,41 @@ public interface RepositoryManager
|
||||
*/
|
||||
public Collection<Type> getConfiguredTypes();
|
||||
|
||||
/**
|
||||
* Returns the {@link Repository} associated to the request uri.
|
||||
*
|
||||
*
|
||||
* @param request the current http request
|
||||
*
|
||||
* @return associated to the request uri
|
||||
* @since 1.9
|
||||
*/
|
||||
public Repository getFromRequest(HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* Returns the {@link Repository} associated to the given type and path.
|
||||
*
|
||||
*
|
||||
* @param type type of the repository (hg, git ...)
|
||||
* @param uri
|
||||
*
|
||||
* @return the {@link Repository} associated to the given type and path
|
||||
* @since 1.9
|
||||
*/
|
||||
public Repository getFromTypeAndUri(String type, String uri);
|
||||
|
||||
/**
|
||||
* Returns the {@link Repository} associated to the request uri.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param uri request uri without context path
|
||||
*
|
||||
* @return associated to the request uri
|
||||
* @since 1.9
|
||||
*/
|
||||
public Repository getFromUri(String uri);
|
||||
|
||||
/**
|
||||
* Returns a {@link RepositoryHandler} by the given type (hg, git, svn ...).
|
||||
*
|
||||
|
||||
@@ -664,6 +664,29 @@ public class IOUtil
|
||||
return getScript(baseFile, baseFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param parent
|
||||
* @param child
|
||||
* @since 1.9
|
||||
*
|
||||
* @return
|
||||
*
|
||||
*/
|
||||
public static boolean isChild(File parent, File child)
|
||||
{
|
||||
try
|
||||
{
|
||||
return child.getCanonicalPath().startsWith(parent.getCanonicalPath());
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -51,6 +51,9 @@ public class ValidationUtil
|
||||
/** Field description */
|
||||
private static final String REGEX_NAME = "^[A-z0-9\\.\\-_]+$";
|
||||
|
||||
/** Field description */
|
||||
private static final String REGEX_REPOSITORYNAME = "^[A-z0-9\\.\\-_/]+$";
|
||||
|
||||
/** Field description */
|
||||
private static final String REGEX_USERNAME = "^[A-z0-9\\.\\-_@]+$";
|
||||
|
||||
@@ -125,6 +128,20 @@ public class ValidationUtil
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* @since 1.9
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean isRepositoryNameValid(String name)
|
||||
{
|
||||
return Util.isNotEmpty(name) && name.matches(REGEX_REPOSITORYNAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user