本文整理汇总了Java中com.gitblit.models.RepositoryModel.isUsersPersonalRepository方法的典型用法代码示例。如果您正苦于以下问题:Java RepositoryModel.isUsersPersonalRepository方法的具体用法?Java RepositoryModel.isUsersPersonalRepository怎么用?Java RepositoryModel.isUsersPersonalRepository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.gitblit.models.RepositoryModel
的用法示例。
在下文中一共展示了RepositoryModel.isUsersPersonalRepository方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateUserModel
import com.gitblit.models.RepositoryModel; //导入方法依赖的package包/类
/**
* Adds/updates a complete user object keyed by username. This method allows
* for renaming a user.
*
* @see IUserService.updateUserModel(String, UserModel)
* @param username
* @param user
* @param isCreate
* @throws GitBlitException
*/
public void updateUserModel(String username, UserModel user, boolean isCreate)
throws GitBlitException {
if (!username.equalsIgnoreCase(user.username)) {
if (userService.getUserModel(user.username) != null) {
throw new GitBlitException(MessageFormat.format(
"Failed to rename ''{0}'' because ''{1}'' already exists.", username,
user.username));
}
// rename repositories and owner fields for all repositories
for (RepositoryModel model : getRepositoryModels(user)) {
if (model.isUsersPersonalRepository(username)) {
// personal repository
model.addOwner(user.username);
String oldRepositoryName = model.name;
model.name = "~" + user.username + model.name.substring(model.projectPath.length());
model.projectPath = "~" + user.username;
updateRepositoryModel(oldRepositoryName, model, false);
} else if (model.isOwner(username)) {
// common/shared repo
model.addOwner(user.username);
updateRepositoryModel(model.name, model, false);
}
}
}
if (!userService.updateUserModel(username, user)) {
throw new GitBlitException(isCreate ? "Failed to add user!" : "Failed to update user!");
}
}
示例2: getAccessRestrictedRepositoryList
import com.gitblit.models.RepositoryModel; //导入方法依赖的package包/类
protected List<String> getAccessRestrictedRepositoryList(boolean includeWildcards, UserModel user) {
// build list of access-restricted projects
String lastProject = null;
List<String> repos = new ArrayList<String>();
if (includeWildcards) {
// all repositories
repos.add(".*");
// all repositories excluding personal repositories
repos.add("[^~].*");
}
for (String repo : GitBlit.self().getRepositoryList()) {
RepositoryModel repositoryModel = GitBlit.self().getRepositoryModel(repo);
if (repositoryModel.accessRestriction.exceeds(AccessRestrictionType.NONE)
&& repositoryModel.authorizationControl.equals(AuthorizationControl.NAMED)) {
if (user != null &&
(repositoryModel.isOwner(user.username) || repositoryModel.isUsersPersonalRepository(user.username))) {
// exclude Owner or personal repositories
continue;
}
if (includeWildcards) {
if (lastProject == null || !lastProject.equalsIgnoreCase(repositoryModel.projectPath)) {
lastProject = repositoryModel.projectPath.toLowerCase();
if (!StringUtils.isEmpty(repositoryModel.projectPath)) {
// regex for all repositories within a project
repos.add(repositoryModel.projectPath + "/.*");
}
}
}
repos.add(repo.toLowerCase());
}
}
return repos;
}
示例3: createRepository
import com.gitblit.models.RepositoryModel; //导入方法依赖的package包/类
/**
* An authenticated user with the CREATE role can create a repository on
* push.
*
* @param user
* @param repository
* @param action
* @return the repository model, if it is created, null otherwise
*/
@Override
protected RepositoryModel createRepository(UserModel user, String repository, String action) {
boolean isPush = !StringUtils.isEmpty(action) && gitReceivePack.equals(action);
if (isPush) {
if (user.canCreate(repository)) {
// user is pushing to a new repository
// validate name
if (repository.startsWith("../")) {
logger.error(MessageFormat.format("Illegal relative path in repository name! {0}", repository));
return null;
}
if (repository.contains("/../")) {
logger.error(MessageFormat.format("Illegal relative path in repository name! {0}", repository));
return null;
}
// confirm valid characters in repository name
Character c = StringUtils.findInvalidCharacter(repository);
if (c != null) {
logger.error(MessageFormat.format("Invalid character '{0}' in repository name {1}!", c, repository));
return null;
}
// create repository
RepositoryModel model = new RepositoryModel();
model.name = repository;
model.addOwner(user.username);
model.projectPath = StringUtils.getFirstPathElement(repository);
if (model.isUsersPersonalRepository(user.username)) {
// personal repository, default to private for user
model.authorizationControl = AuthorizationControl.NAMED;
model.accessRestriction = AccessRestrictionType.VIEW;
} else {
// common repository, user default server settings
model.authorizationControl = AuthorizationControl.fromName(GitBlit.getString(Keys.git.defaultAuthorizationControl, ""));
model.accessRestriction = AccessRestrictionType.fromName(GitBlit.getString(Keys.git.defaultAccessRestriction, ""));
}
// create the repository
try {
GitBlit.self().updateRepositoryModel(model.name, model, true);
logger.info(MessageFormat.format("{0} created {1} ON-PUSH", user.username, model.name));
return GitBlit.self().getRepositoryModel(model.name);
} catch (GitBlitException e) {
logger.error(MessageFormat.format("{0} failed to create repository {1} ON-PUSH!", user.username, model.name), e);
}
} else {
logger.warn(MessageFormat.format("{0} is not permitted to create repository {1} ON-PUSH!", user.username, repository));
}
}
// repository could not be created or action was not a push
return null;
}