mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
change NamespaceStrategy signature to createNamespace(Repository)
This change allows us to implement NamespaceStrategies, such as by type (git, hg, svn) or manual defined. The DefaultNamespaceStrategy accepts now a predefined namespace and only if no namespace was set the username of the currently logged in user is used.
This commit is contained in:
@@ -1,17 +1,24 @@
|
||||
package sonia.scm.repository;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import sonia.scm.plugin.Extension;
|
||||
|
||||
/**
|
||||
* The DefaultNamespaceStrategy returns the username of the currently logged in user as namespace.
|
||||
* The DefaultNamespaceStrategy returns the predefined namespace of the given repository, if the namespace was not set
|
||||
* the username of the currently loggedin user is used.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Extension
|
||||
public class DefaultNamespaceStrategy implements NamespaceStrategy {
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return SecurityUtils.getSubject().getPrincipal().toString();
|
||||
public String createNamespace(Repository repository) {
|
||||
String namespace = repository.getNamespace();
|
||||
if (Strings.isNullOrEmpty(namespace)) {
|
||||
namespace = SecurityUtils.getSubject().getPrincipal().toString();
|
||||
}
|
||||
return namespace;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user