@@ -685,6 +685,7 @@ gb.closedMilestones = closed milestones | |||
gb.administration = administration | |||
gb.plugins = plugins | |||
gb.extensions = extensions | |||
gb.pleaseSelectProject = Please select the project! | |||
gb.anonymousPush = Anonymous Pushes | |||
gb.anonymousPushDescription = Anyone can see, clone, and push to this repository. | |||
gb.pushRestrictedAuthenticated = Restrict Pushes (Authenticated) |
@@ -10,20 +10,7 @@ | |||
<div class="row"> | |||
<div class="span12"> | |||
<table class="plain"> | |||
<tbody class="settings"> | |||
<tr> | |||
<th><wicket:message key="gb.project"></wicket:message></th> | |||
<td></td> | |||
<th><wicket:message key="gb.name"></wicket:message></th> | |||
</tr> | |||
<tr> | |||
<td><select class="span2" wicket:id="projectPath" /></td> | |||
<td style="font-size:24px;color:#ccc;">/</td> | |||
<td class="edit"><input class="span3" type="text" wicket:id="name" id="name" /> <span class="help-inline"><wicket:message key="gb.nameDescription"></wicket:message></span></td> | |||
</tr> | |||
</tbody> | |||
</table> | |||
<div wicket:id="namePanel"></div> | |||
<div> | |||
<b><wicket:message key="gb.description"></wicket:message></b><br/> | |||
@@ -32,7 +19,7 @@ | |||
<hr/> | |||
<span wicket:id="permissionPanel"></span> | |||
<div wicket:id="permissionPanel"></div> | |||
<hr/> | |||
@@ -18,7 +18,6 @@ package com.gitblit.wicket.pages; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.io.UnsupportedEncodingException; | |||
import java.text.MessageFormat; | |||
import java.util.ArrayList; | |||
import java.util.Collections; | |||
import java.util.List; | |||
@@ -61,6 +60,7 @@ import com.gitblit.utils.FileUtils; | |||
import com.gitblit.utils.StringUtils; | |||
import com.gitblit.wicket.GitBlitWebSession; | |||
import com.gitblit.wicket.WicketUtils; | |||
import com.gitblit.wicket.panels.RepositoryNamePanel; | |||
import com.gitblit.wicket.panels.RepositoryPermissionPanel; | |||
public class NewRepositoryPage extends RootSubPage { | |||
@@ -71,6 +71,7 @@ public class NewRepositoryPage extends RootSubPage { | |||
private IModel<Boolean> addGitflowModel; | |||
private IModel<Boolean> addGitignoreModel; | |||
private RepositoryPermissionPanel permissionPanel; | |||
private RepositoryNamePanel namePanel; | |||
public NewRepositoryPage() { | |||
// create constructor | |||
@@ -104,46 +105,11 @@ public class NewRepositoryPage extends RootSubPage { | |||
@Override | |||
protected void onSubmit() { | |||
// confirm a repository name was entered | |||
if (StringUtils.isEmpty(repositoryModel.name)) { | |||
error(getString("gb.pleaseSetRepositoryName")); | |||
return; | |||
} | |||
String project = repositoryModel.projectPath; | |||
String fullName = (project + "/" + repositoryModel.name).trim(); | |||
fullName = fullName.replace('\\', '/'); | |||
fullName = fullName.replace("//", "/"); | |||
if (fullName.charAt(0) == '/') { | |||
fullName = fullName.substring(1); | |||
} | |||
if (fullName.endsWith("/")) { | |||
fullName = fullName.substring(0, fullName.length() - 1); | |||
} | |||
try { | |||
if (fullName.contains("../")) { | |||
error(getString("gb.illegalRelativeSlash")); | |||
if (!namePanel.updateModel(repositoryModel)) { | |||
return; | |||
} | |||
if (fullName.contains("/../")) { | |||
error(getString("gb.illegalRelativeSlash")); | |||
return; | |||
} | |||
// confirm valid characters in repository name | |||
Character c = StringUtils.findInvalidCharacter(fullName); | |||
if (c != null) { | |||
error(MessageFormat.format(getString("gb.illegalCharacterRepositoryName"), | |||
c)); | |||
return; | |||
} | |||
repositoryModel.name = fullName; | |||
repositoryModel.projectPath = null; | |||
permissionPanel.setPermission(repositoryModel); | |||
permissionPanel.updateModel(repositoryModel); | |||
repositoryModel.owners = new ArrayList<String>(); | |||
repositoryModel.owners.add(GitBlitWebSession.get().getUsername()); | |||
@@ -179,47 +145,20 @@ public class NewRepositoryPage extends RootSubPage { | |||
} catch (GitBlitException e) { | |||
error(e.getMessage()); | |||
// restore project and name fields on error condition | |||
repositoryModel.projectPath = StringUtils.getFirstPathElement(fullName); | |||
if (!StringUtils.isEmpty(repositoryModel.projectPath)) { | |||
repositoryModel.name = fullName.substring(repositoryModel.projectPath.length() + 1); | |||
} | |||
namePanel.resetModel(repositoryModel); | |||
return; | |||
} | |||
setRedirect(true); | |||
setResponsePage(SummaryPage.class, WicketUtils.newRepositoryParameter(fullName)); | |||
setResponsePage(SummaryPage.class, WicketUtils.newRepositoryParameter(repositoryModel.name)); | |||
} | |||
}; | |||
GitBlitWebSession session = GitBlitWebSession.get(); | |||
UserModel user = session.getUser(); | |||
// build project list for repository destination | |||
String defaultProject = null; | |||
List<String> projects = new ArrayList<String>(); | |||
if (user.canAdmin()) { | |||
String main = app().settings().getString(Keys.web.repositoryRootGroupName, "main"); | |||
projects.add(main); | |||
defaultProject = main; | |||
} | |||
if (user.canCreate()) { | |||
projects.add(user.getPersonalPath()); | |||
if (defaultProject == null) { | |||
// only prefer personal namespace if default is not already set | |||
defaultProject = user.getPersonalPath(); | |||
} | |||
} | |||
repositoryModel.projectPath = defaultProject; | |||
// do not let the browser pre-populate these fields | |||
form.add(new SimpleAttributeModifier("autocomplete", "off")); | |||
form.add(new DropDownChoice<String>("projectPath", projects)); | |||
form.add(new TextField<String>("name")); | |||
namePanel = new RepositoryNamePanel("namePanel", repositoryModel); | |||
form.add(namePanel); | |||
form.add(new TextField<String>("description")); | |||
// prepare the default access controls |
@@ -0,0 +1,27 @@ | |||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |||
<html xmlns="http://www.w3.org/1999/xhtml" | |||
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd" | |||
xml:lang="en" | |||
lang="en"> | |||
<body> | |||
<wicket:panel> | |||
<table class="plain"> | |||
<tbody class="settings"> | |||
<tr> | |||
<th><wicket:message key="gb.project"></wicket:message></th> | |||
<td></td> | |||
<th><wicket:message key="gb.name"></wicket:message></th> | |||
</tr> | |||
<tr> | |||
<td><select class="span2" wicket:id="projectPath" /></td> | |||
<td style="font-size:24px;color:#ccc;">/</td> | |||
<td class="edit"><input class="span3" type="text" wicket:id="name" id="name" /> <span class="help-inline"><wicket:message key="gb.nameDescription"></wicket:message></span></td> | |||
</tr> | |||
</tbody> | |||
</table> | |||
</wicket:panel> | |||
</body> | |||
</html> |
@@ -0,0 +1,139 @@ | |||
/* | |||
* Copyright 2014 gitblit.com. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package com.gitblit.wicket.panels; | |||
import java.text.MessageFormat; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import org.apache.wicket.markup.html.form.DropDownChoice; | |||
import org.apache.wicket.markup.html.form.TextField; | |||
import com.gitblit.models.RepositoryModel; | |||
import com.gitblit.models.UserModel; | |||
import com.gitblit.utils.StringUtils; | |||
import com.gitblit.wicket.GitBlitWebSession; | |||
/** | |||
* A radio group panel of the 5 available authorization/access restriction combinations. | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
public class RepositoryNamePanel extends BasePanel { | |||
private static final long serialVersionUID = 1L; | |||
private final RepositoryModel repository; | |||
private String fullName; | |||
public RepositoryNamePanel(String wicketId, RepositoryModel repository) { | |||
super(wicketId); | |||
this.repository = repository; | |||
} | |||
@Override | |||
protected void onInitialize() { | |||
super.onInitialize(); | |||
GitBlitWebSession session = GitBlitWebSession.get(); | |||
UserModel user = session.getUser(); | |||
// build project list for repository destination | |||
String defaultProject = null; | |||
List<String> projects = new ArrayList<String>(); | |||
if (user.canAdmin()) { | |||
projects.add("/"); | |||
defaultProject = "/"; | |||
} | |||
if (user.canCreate()) { | |||
String p = user.getPersonalPath() + "/"; | |||
projects.add(p); | |||
if (defaultProject == null) { | |||
// only prefer personal namespace if default is not already set | |||
defaultProject = p; | |||
} | |||
} | |||
repository.projectPath = defaultProject; | |||
add(new DropDownChoice<String>("projectPath", projects)); | |||
add(new TextField<String>("name")); | |||
} | |||
public boolean updateModel(RepositoryModel repositoryModel) { | |||
// confirm a project was selected | |||
if (StringUtils.isEmpty(repositoryModel.projectPath)) { | |||
error(getString("gb.pleaseSelectProject")); | |||
return false; | |||
} | |||
// confirm a repository name was entered | |||
if (StringUtils.isEmpty(repositoryModel.name)) { | |||
error(getString("gb.pleaseSetRepositoryName")); | |||
return false; | |||
} | |||
String project = repositoryModel.projectPath; | |||
fullName = (project + repositoryModel.name).trim(); | |||
fullName = fullName.replace('\\', '/'); | |||
fullName = fullName.replace("//", "/"); | |||
if (fullName.charAt(0) == '/') { | |||
fullName = fullName.substring(1); | |||
} | |||
if (fullName.endsWith("/")) { | |||
fullName = fullName.substring(0, fullName.length() - 1); | |||
} | |||
if (fullName.contains("../")) { | |||
error(getString("gb.illegalRelativeSlash")); | |||
return false; | |||
} | |||
if (fullName.contains("/../")) { | |||
error(getString("gb.illegalRelativeSlash")); | |||
return false; | |||
} | |||
// confirm valid characters in repository name | |||
Character c = StringUtils.findInvalidCharacter(fullName); | |||
if (c != null) { | |||
error(MessageFormat.format(getString("gb.illegalCharacterRepositoryName"), c)); | |||
return false; | |||
} | |||
repositoryModel.name = fullName; | |||
repositoryModel.projectPath = null; | |||
return true; | |||
} | |||
public void resetModel(RepositoryModel repositoryModel) { | |||
// restore project and name fields on error condition | |||
repositoryModel.projectPath = StringUtils.getFirstPathElement(fullName) + "/"; | |||
if (repositoryModel.projectPath.length() > 1) { | |||
repositoryModel.name = fullName.substring(repositoryModel.projectPath.length()); | |||
} | |||
} | |||
@Override | |||
protected boolean getStatelessHint() { | |||
return false; | |||
} | |||
} |
@@ -134,7 +134,7 @@ public class RepositoryPermissionPanel extends BasePanel { | |||
add(permissionGroup); | |||
} | |||
public void setPermission(RepositoryModel repository) { | |||
public void updateModel(RepositoryModel repository) { | |||
Permission permission = permissionGroup.getModelObject(); | |||
repository.authorizationControl = permission.control; | |||
repository.accessRestriction = permission.type; |