| | |
| | | import java.util.Collections;
|
| | | import java.util.HashSet;
|
| | | import java.util.Iterator;
|
| | | import java.util.LinkedHashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | |
| | | import org.apache.wicket.PageParameters;
|
| | | import org.apache.wicket.behavior.SimpleAttributeModifier;
|
| | | import org.apache.wicket.extensions.markup.html.form.palette.Palette;
|
| | | import org.apache.wicket.markup.html.WebMarkupContainer;
|
| | | 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.IChoiceRenderer;
|
| | | 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 org.apache.wicket.model.util.CollectionModel;
|
| | | import org.apache.wicket.model.util.ListModel;
|
| | |
|
| | | import com.gitblit.Constants;
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.Constants.AuthorizationControl;
|
| | | import com.gitblit.Constants.FederationStrategy;
|
| | | import com.gitblit.GitBlit;
|
| | | import com.gitblit.GitBlitException;
|
| | |
| | | // create constructor
|
| | | super();
|
| | | isCreate = true;
|
| | | setupPage(new RepositoryModel());
|
| | | RepositoryModel model = new RepositoryModel();
|
| | | String restriction = GitBlit.getString(Keys.git.defaultAccessRestriction, null);
|
| | | model.accessRestriction = AccessRestrictionType.fromName(restriction);
|
| | | String authorization = GitBlit.getString(Keys.git.defaultAuthorizationControl, null);
|
| | | model.authorizationControl = AuthorizationControl.fromName(authorization);
|
| | | setupPage(model);
|
| | | }
|
| | |
|
| | | public EditRepositoryPage(PageParameters params) {
|
| | |
| | | new StringChoiceRenderer(), 8, false);
|
| | |
|
| | | // indexed local branches palette
|
| | | List<String> allLocalBranches = repositoryModel.getLocalBranches();
|
| | | List<String> allLocalBranches = new ArrayList<String>();
|
| | | allLocalBranches.add(Constants.DEFAULT_BRANCH);
|
| | | allLocalBranches.addAll(repositoryModel.getLocalBranches());
|
| | | boolean luceneEnabled = GitBlit.getBoolean(Keys.web.allowLuceneIndexing, true);
|
| | | final Palette<String> indexedBranchesPalette = new Palette<String>("indexedBranches", new ListModel<String>(
|
| | | indexedBranches), new CollectionModel<String>(allLocalBranches),
|
| | | new StringChoiceRenderer(), 8, false);
|
| | | indexedBranchesPalette.setEnabled(luceneEnabled && (allLocalBranches.size() > 0));
|
| | | indexedBranchesPalette.setEnabled(luceneEnabled);
|
| | |
|
| | | // federation sets palette
|
| | | List<String> sets = GitBlit.getStrings(Keys.federation.sets);
|
| | |
| | | new ListModel<String>(postReceiveScripts), new CollectionModel<String>(GitBlit
|
| | | .self().getPostReceiveScriptsUnused(repositoryModel)),
|
| | | new StringChoiceRenderer(), 12, true);
|
| | | |
| | | // custom fields
|
| | | final Map<String, String> customFieldsMap = GitBlit.getMap(Keys.groovy.customFields);
|
| | | List<String> customKeys = new ArrayList<String>(customFieldsMap.keySet());
|
| | | final ListView<String> customFieldsListView = new ListView<String>("customFieldsListView", customKeys) {
|
| | | |
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | @Override
|
| | | protected void populateItem(ListItem<String> item) {
|
| | | String key = item.getModelObject();
|
| | | item.add(new Label("customFieldLabel", customFieldsMap.get(key)));
|
| | | |
| | | String value = "";
|
| | | if (repositoryModel.customFields != null && repositoryModel.customFields.containsKey(key)) {
|
| | | value = repositoryModel.customFields.get(key);
|
| | | }
|
| | | TextField<String> field = new TextField<String>("customFieldValue", new Model<String>(value));
|
| | | item.add(field);
|
| | | }
|
| | | };
|
| | | customFieldsListView.setReuseItems(true);
|
| | |
|
| | | CompoundPropertyModel<RepositoryModel> model = new CompoundPropertyModel<RepositoryModel>(
|
| | | repositoryModel);
|
| | |
| | | if (repositoryModel.name.contains("/../")) {
|
| | | error(getString("gb.illegalRelativeSlash"));
|
| | | return;
|
| | | } |
| | | if (repositoryModel.name.endsWith("/")) {
|
| | | repositoryModel.name = repositoryModel.name.substring(0, repositoryModel.name.length() - 1);
|
| | | }
|
| | |
|
| | | // confirm valid characters in repository name
|
| | |
| | | postReceiveScripts.add(post.next());
|
| | | }
|
| | | repositoryModel.postReceiveScripts = postReceiveScripts;
|
| | | |
| | | // custom fields
|
| | | repositoryModel.customFields = new LinkedHashMap<String, String>();
|
| | | for (int i = 0; i < customFieldsListView.size(); i++) {
|
| | | ListItem<String> child = (ListItem<String>) customFieldsListView.get(i);
|
| | | String key = child.getModelObject();
|
| | |
|
| | | TextField<String> field = (TextField<String>) child.get("customFieldValue");
|
| | | String value = field.getValue();
|
| | | |
| | | repositoryModel.customFields.put(key, value);
|
| | | }
|
| | | |
| | | // save the repository
|
| | | GitBlit.self().updateRepositoryModel(oldName, repositoryModel, isCreate);
|
| | |
|
| | |
| | | : StringUtils.flattenStrings(repositoryModel.mailingLists, " "));
|
| | | form.add(new TextField<String>("mailingLists", mailingLists));
|
| | | form.add(indexedBranchesPalette);
|
| | | |
| | | RadioGroup<AuthorizationControl> group = new RadioGroup<AuthorizationControl>("authorizationControl");
|
| | | Radio<AuthorizationControl> allowAuthenticated = new Radio<AuthorizationControl>("allowAuthenticated", new Model<AuthorizationControl>(AuthorizationControl.AUTHENTICATED)); |
| | | Radio<AuthorizationControl> allowNamed = new Radio<AuthorizationControl>("allowNamed", new Model<AuthorizationControl>(AuthorizationControl.NAMED));
|
| | | group.add(allowAuthenticated);
|
| | | group.add(allowNamed);
|
| | | form.add(group);
|
| | | |
| | | form.add(usersPalette);
|
| | | form.add(teamsPalette);
|
| | | form.add(federationSetsPalette);
|
| | | form.add(preReceivePalette);
|
| | | form.add(new BulletListPanel("inheritedPreReceive", "inherited", GitBlit.self()
|
| | | form.add(new BulletListPanel("inheritedPreReceive", getString("gb.inherited"), GitBlit.self()
|
| | | .getPreReceiveScriptsInherited(repositoryModel)));
|
| | | form.add(postReceivePalette);
|
| | | form.add(new BulletListPanel("inheritedPostReceive", "inherited", GitBlit.self()
|
| | | form.add(new BulletListPanel("inheritedPostReceive", getString("gb.inherited"), GitBlit.self()
|
| | | .getPostReceiveScriptsInherited(repositoryModel)));
|
| | | |
| | | WebMarkupContainer customFieldsSection = new WebMarkupContainer("customFieldsSection");
|
| | | customFieldsSection.add(customFieldsListView);
|
| | | form.add(customFieldsSection.setVisible(!GitBlit.getString(Keys.groovy.customFields, "").isEmpty()));
|
| | |
|
| | | form.add(new Button(getString("gb.save")));
|
| | | Button cancel = new Button(getString("gb.cancel")) {
|
| | | form.add(new Button("save"));
|
| | | Button cancel = new Button("cancel") {
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | @Override
|
| | |
| | | if (authenticateAdmin) {
|
| | | if (user == null) {
|
| | | // No Login Available
|
| | | error("Administration requires a login", true);
|
| | | error(getString("gb.errorAdminLoginRequired"), true);
|
| | | }
|
| | | if (isCreate) {
|
| | | // Create Repository
|
| | | if (!user.canAdmin) {
|
| | | // Only Administrators May Create
|
| | | error("Only an administrator may create a repository", true);
|
| | | error(getString("gb.errorOnlyAdminMayCreateRepository"), true);
|
| | | }
|
| | | } else {
|
| | | // Edit Repository
|
| | |
| | | } else {
|
| | | if (!model.owner.equalsIgnoreCase(user.username)) {
|
| | | // User is not an Admin nor Owner
|
| | | error("Only an administrator or the owner may edit a repository", true);
|
| | | error(getString("gb.errorOnlyAdminOrOwnerMayEditRepository"), true);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | } else {
|
| | | // No Administration Permitted
|
| | | error("Administration is disabled", true);
|
| | | error(getString("gb.errorAdministrationDisabled"), true);
|
| | | }
|
| | | }
|
| | |
|