| | |
| | |
|
| | | import java.io.File;
|
| | | import java.io.IOException;
|
| | | import java.io.Serializable;
|
| | | import java.io.UnsupportedEncodingException;
|
| | | import java.text.MessageFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Collections;
|
| | | import java.util.List;
|
| | |
|
| | | import org.apache.wicket.ajax.AjaxRequestTarget;
|
| | | import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
|
| | | import org.apache.wicket.behavior.SimpleAttributeModifier;
|
| | | import org.apache.wicket.markup.html.basic.Label;
|
| | | import org.apache.wicket.markup.html.form.Button;
|
| | | import org.apache.wicket.markup.html.form.CheckBox;
|
| | | import org.apache.wicket.markup.html.form.DropDownChoice;
|
| | | import org.apache.wicket.markup.html.form.Form;
|
| | | import org.apache.wicket.markup.html.form.Radio;
|
| | | import org.apache.wicket.markup.html.form.RadioGroup;
|
| | | import org.apache.wicket.markup.html.form.TextField;
|
| | | import org.apache.wicket.markup.html.list.ListItem;
|
| | | import org.apache.wicket.markup.html.list.ListView;
|
| | | import org.apache.wicket.model.CompoundPropertyModel;
|
| | | import org.apache.wicket.model.IModel;
|
| | | import org.apache.wicket.model.Model;
|
| | |
| | | import com.gitblit.utils.StringUtils;
|
| | | import com.gitblit.wicket.GitBlitWebSession;
|
| | | import com.gitblit.wicket.WicketUtils;
|
| | | import com.gitblit.wicket.panels.AccessPolicyPanel;
|
| | | import com.gitblit.wicket.panels.BooleanChoiceOption;
|
| | | import com.gitblit.wicket.panels.BooleanOption;
|
| | | import com.gitblit.wicket.panels.RepositoryNamePanel;
|
| | | import com.google.common.base.Optional;
|
| | |
|
| | | public class NewRepositoryPage extends RootSubPage {
|
| | |
|
| | | private final RepositoryModel repositoryModel;
|
| | | private RadioGroup<Permission> permissionGroup;
|
| | | private IModel<Boolean> addReadmeModel;
|
| | | private Model<String> gitignoreModel;
|
| | | private IModel<Boolean> addGitflowModel;
|
| | | private IModel<Boolean> addGitignoreModel;
|
| | | private AccessPolicyPanel accessPolicyPanel;
|
| | | private RepositoryNamePanel namePanel;
|
| | |
|
| | | public NewRepositoryPage() {
|
| | | // create constructor
|
| | |
| | |
|
| | | @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;
|
| | |
|
| | | Permission permisison = permissionGroup.getModelObject();
|
| | | repositoryModel.accessRestriction = permisison.type;
|
| | | repositoryModel.authorizationControl = AuthorizationControl.NAMED;
|
| | | accessPolicyPanel.updateModel(repositoryModel);
|
| | |
|
| | | repositoryModel.owners = new ArrayList<String>();
|
| | | repositoryModel.owners.add(GitBlitWebSession.get().getUsername());
|
| | |
| | | if (addGitignore) {
|
| | | gitignore = gitignoreModel.getObject();
|
| | | if (StringUtils.isEmpty(gitignore)) {
|
| | | throw new GitBlitException("Please select a .gitignore file");
|
| | | throw new GitBlitException(getString("gb.pleaseSelectGitIgnore"));
|
| | | }
|
| | | }
|
| | |
|
| | |
| | |
|
| | | } 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);
|
| | | }
|
| | | 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"));
|
| | | form.add(new TextField<String>("description"));
|
| | | namePanel = new RepositoryNamePanel("namePanel", repositoryModel);
|
| | | form.add(namePanel);
|
| | |
|
| | | Permission anonymousPermission = new Permission(getString("gb.anonymous"), getString("gb.anonymousRepoDescription"), "blank.png", AccessRestrictionType.NONE);
|
| | | Permission publicPermission = new Permission(getString("gb.public"), getString("gb.publicRepoDescription"), "lock_go_16x16.png", AccessRestrictionType.PUSH);
|
| | | Permission protectedPermission = new Permission(getString("gb.protected"), getString("gb.protectedRepoDescription"), "lock_pull_16x16.png", AccessRestrictionType.CLONE);
|
| | | Permission privatePermission = new Permission(getString("gb.private"), getString("gb.privateRepoDescription"), "shield_16x16.png", AccessRestrictionType.VIEW);
|
| | |
|
| | | List<Permission> permissions = new ArrayList<Permission>();
|
| | | if (app().settings().getBoolean(Keys.git.allowAnonymousPushes, false)) {
|
| | | permissions.add(anonymousPermission);
|
| | | }
|
| | | permissions.add(publicPermission);
|
| | | permissions.add(protectedPermission);
|
| | | permissions.add(privatePermission);
|
| | |
|
| | | // determine default permission selection
|
| | | // prepare the default access controls
|
| | | AccessRestrictionType defaultRestriction = AccessRestrictionType.fromName(
|
| | | app().settings().getString(Keys.git.defaultAccessRestriction, AccessRestrictionType.PUSH.name()));
|
| | | if (AccessRestrictionType.NONE == defaultRestriction) {
|
| | | defaultRestriction = AccessRestrictionType.PUSH;
|
| | | }
|
| | | AuthorizationControl defaultControl = AuthorizationControl.fromName(
|
| | | app().settings().getString(Keys.git.defaultAuthorizationControl, AuthorizationControl.NAMED.name()));
|
| | |
|
| | | Permission defaultPermission = publicPermission;
|
| | | for (Permission permission : permissions) {
|
| | | if (permission.type == defaultRestriction) {
|
| | | defaultPermission = permission;
|
| | | }
|
| | | if (AuthorizationControl.AUTHENTICATED == defaultControl) {
|
| | | defaultRestriction = AccessRestrictionType.PUSH;
|
| | | }
|
| | |
|
| | | permissionGroup = new RadioGroup<>("permissionsGroup", new Model<Permission>(defaultPermission));
|
| | | form.add(permissionGroup);
|
| | | repositoryModel.authorizationControl = defaultControl;
|
| | | repositoryModel.accessRestriction = defaultRestriction;
|
| | |
|
| | | ListView<Permission> permissionsList = new ListView<Permission>("permissions", permissions) {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | @Override
|
| | | protected void populateItem(ListItem<Permission> item) {
|
| | | Permission p = item.getModelObject();
|
| | | item.add(new Radio<Permission>("radio", item.getModel()));
|
| | | item.add(WicketUtils.newImage("image", p.image));
|
| | | item.add(new Label("name", p.name));
|
| | | item.add(new Label("description", p.description));
|
| | | }
|
| | | };
|
| | | permissionGroup.add(permissionsList);
|
| | | accessPolicyPanel = new AccessPolicyPanel("accessPolicyPanel", repositoryModel);
|
| | | form.add(accessPolicyPanel);
|
| | |
|
| | | //
|
| | | // initial commit options
|
| | |
| | |
|
| | | // add README
|
| | | addReadmeModel = Model.of(false);
|
| | | form.add(new CheckBox("addReadme", addReadmeModel));
|
| | | form.add(new BooleanOption("addReadme",
|
| | | getString("gb.initWithReadme"),
|
| | | getString("gb.initWithReadmeDescription"),
|
| | | addReadmeModel));
|
| | |
|
| | | // add .gitignore
|
| | | File gitignoreDir = app().runtime().getFileOrFolder(Keys.git.gitignoreFolder, "${baseFolder}/gitignore");
|
| | |
| | | }
|
| | | }
|
| | | Collections.sort(gitignores);
|
| | |
|
| | | gitignoreModel = Model.of("");
|
| | | final DropDownChoice<String> gitignoreChoice = new DropDownChoice<String>("gitignore", gitignoreModel, gitignores);
|
| | | gitignoreChoice.setOutputMarkupId(true);
|
| | | form.add(gitignoreChoice.setEnabled(false));
|
| | |
|
| | | addGitignoreModel = Model.of(false);
|
| | | final CheckBox gitignoreCheckbox = new CheckBox("addGitignore", addGitignoreModel);
|
| | | form.add(gitignoreCheckbox);
|
| | | form.add(new BooleanChoiceOption<String>("addGitIgnore",
|
| | | getString("gb.initWithGitignore"),
|
| | | getString("gb.initWithGitignoreDescription"),
|
| | | addGitignoreModel,
|
| | | gitignoreModel,
|
| | | gitignores).setVisible(gitignores.size() > 0));
|
| | |
|
| | | gitignoreCheckbox.add(new AjaxFormComponentUpdatingBehavior("onchange") {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | @Override
|
| | | protected void onUpdate(AjaxRequestTarget target) {
|
| | | gitignoreChoice.setEnabled(addGitignoreModel.getObject());
|
| | | target.addComponent(gitignoreChoice);
|
| | | }
|
| | | });
|
| | |
|
| | | // TODO add .gitflow
|
| | | // TODO consider gitflow at creation (ticket-55)
|
| | | addGitflowModel = Model.of(false);
|
| | | form.add(new CheckBox("addGitflow", addGitflowModel));
|
| | | form.add(new BooleanOption("addGitFlow",
|
| | | "Include a .gitflow file",
|
| | | "This will generate a config file which guides Git clients in setting up Gitflow branches.",
|
| | | addGitflowModel).setVisible(false));
|
| | |
|
| | | form.add(new Button("create"));
|
| | |
|
| | |
| | | try {
|
| | |
|
| | | UserModel user = GitBlitWebSession.get().getUser();
|
| | | PersonIdent author = new PersonIdent(user.getDisplayName(), user.emailAddress);
|
| | | String email = Optional.fromNullable(user.emailAddress).or(user.username + "@" + "gitblit");
|
| | | PersonIdent author = new PersonIdent(user.getDisplayName(), email);
|
| | |
|
| | | DirCache newIndex = DirCache.newInCore();
|
| | | DirCacheBuilder indexBuilder = newIndex.builder();
|
| | |
| | | }
|
| | | }
|
| | | } finally {
|
| | | revWalk.release();
|
| | | revWalk.close();
|
| | | }
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | logger().error(null, e);
|
| | | } catch (IOException e) {
|
| | | logger().error(null, e);
|
| | | } finally {
|
| | | odi.release();
|
| | | odi.close();
|
| | | db.close();
|
| | | }
|
| | | return success;
|
| | | }
|
| | |
|
| | | private static class Permission implements Serializable {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | final String name;
|
| | | final String description;
|
| | | final String image;
|
| | | final AccessRestrictionType type;
|
| | |
|
| | | Permission(String name, String description, String img, AccessRestrictionType type) {
|
| | | this.name = name;
|
| | | this.description = description;
|
| | | this.image = img;
|
| | | this.type = type;
|
| | | }
|
| | | }
|
| | | }
|