diff options
Diffstat (limited to 'src/main/java/com/gitblit/wicket/panels')
3 files changed, 191 insertions, 207 deletions
diff --git a/src/main/java/com/gitblit/wicket/panels/ProjectRepositoryPanel.java b/src/main/java/com/gitblit/wicket/panels/ProjectRepositoryPanel.java index 8630d201..a30faff1 100644 --- a/src/main/java/com/gitblit/wicket/panels/ProjectRepositoryPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/ProjectRepositoryPanel.java @@ -15,6 +15,7 @@ */
package com.gitblit.wicket.panels;
+import java.util.List;
import java.util.Map;
import org.apache.wicket.Component;
@@ -27,6 +28,7 @@ import org.apache.wicket.markup.html.panel.Fragment; import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.Keys;
+import com.gitblit.models.Owner;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
import com.gitblit.servlet.SyndicationServlet;
@@ -64,7 +66,7 @@ public class ProjectRepositoryPanel extends BasePanel { swatch.setVisible(showSwatch);
PageParameters pp = WicketUtils.newRepositoryParameter(entry.name);
- add(new LinkPanel("repositoryName", "list", StringUtils.getRelativePath(entry.projectPath,
+ add(new LinkPanel("repositoryName", "list", StringUtils.getRelativePath(entry.getProject(),
StringUtils.stripDotGit(entry.name)), SummaryPage.class, pp));
add(new Label("repositoryDescription", entry.description).setVisible(!StringUtils
.isEmpty(entry.description)));
@@ -102,23 +104,17 @@ public class ProjectRepositoryPanel extends BasePanel { add(WicketUtils.newClearPixel("federatedIcon").setVisible(false));
}
- if (ArrayUtils.isEmpty(entry.owners)) {
+ List<Owner> owners = app().users().getOwners(entry);
+ if (ArrayUtils.isEmpty(owners)) {
add(new Label("repositoryOwner").setVisible(false));
} else {
- String owner = "";
- for (String username : entry.owners) {
- UserModel ownerModel = app().users().getUserModel(username);
-
- if (ownerModel != null) {
- owner = ownerModel.getDisplayName();
- }
- }
- if (entry.owners.size() > 1) {
+ String owner = owners.get(0).getDisplayName();
+ if (owners.size() > 1) {
owner += ", ...";
}
Label ownerLabel = (new Label("repositoryOwner", owner + " (" +
localizer.getString("gb.owner", parent) + ")"));
- WicketUtils.setHtmlTooltip(ownerLabel, ArrayUtils.toString(entry.owners));
+ WicketUtils.setHtmlTooltip(ownerLabel, ArrayUtils.toString(owners));
add(ownerLabel);
}
diff --git a/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java b/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java index 8573e1a6..49ec0489 100644 --- a/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java @@ -42,6 +42,7 @@ import org.apache.wicket.model.Model; import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.Keys;
+import com.gitblit.models.Owner;
import com.gitblit.models.ProjectModel;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
@@ -275,22 +276,17 @@ public class RepositoriesPanel extends BasePanel { row.add(WicketUtils.newBlankImage("accessRestrictionIcon"));
}
+ List<Owner> owners = app().users().getOwners(entry);
+ // display first owner
String owner = "";
- if (!ArrayUtils.isEmpty(entry.owners)) {
- // display first owner
- for (String username : entry.owners) {
- UserModel ownerModel = app().users().getUserModel(username);
- if (ownerModel != null) {
- owner = ownerModel.getDisplayName();
- break;
- }
- }
- if (entry.owners.size() > 1) {
+ if (!owners.isEmpty()) {
+ owner = owners.get(0).getDisplayName();
+ if (owners.size() > 1) {
owner += ", ...";
}
}
Label ownerLabel = new Label("repositoryOwner", owner);
- WicketUtils.setHtmlTooltip(ownerLabel, ArrayUtils.toString(entry.owners));
+ WicketUtils.setHtmlTooltip(ownerLabel, ArrayUtils.toString(owners));
row.add(ownerLabel);
String lastChange;
@@ -336,7 +332,7 @@ public class RepositoriesPanel extends BasePanel { String title;
GroupRepositoryModel(String name, int count) {
- super(name, "", "", new Date(0));
+ super(name, "", new Date(0));
this.count = count;
}
@@ -412,18 +408,6 @@ public class RepositoriesPanel extends BasePanel { return o2.name.compareTo(o1.name);
}
});
- } else if (prop.equals(SortBy.owner.name())) {
- Collections.sort(list, new Comparator<RepositoryModel>() {
- @Override
- public int compare(RepositoryModel o1, RepositoryModel o2) {
- String own1 = ArrayUtils.toString(o1.owners);
- String own2 = ArrayUtils.toString(o2.owners);
- if (asc) {
- return own1.compareTo(own2);
- }
- return own2.compareTo(own1);
- }
- });
} else if (prop.equals(SortBy.description.name())) {
Collections.sort(list, new Comparator<RepositoryModel>() {
@Override
diff --git a/src/main/java/com/gitblit/wicket/panels/RepositoryNamePanel.java b/src/main/java/com/gitblit/wicket/panels/RepositoryNamePanel.java index f381a45e..2b2a3adf 100644 --- a/src/main/java/com/gitblit/wicket/panels/RepositoryNamePanel.java +++ b/src/main/java/com/gitblit/wicket/panels/RepositoryNamePanel.java @@ -1,172 +1,176 @@ -/*
- * 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.Set;
-import java.util.TreeSet;
-
-import org.apache.wicket.markup.html.form.DropDownChoice;
-import org.apache.wicket.markup.html.form.TextField;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.Model;
-
-import com.gitblit.models.ProjectModel;
-import com.gitblit.models.RepositoryModel;
-import com.gitblit.models.UserModel;
-import com.gitblit.utils.StringUtils;
-import com.gitblit.wicket.GitBlitWebSession;
-
-/**
- * A panel for naming a repository, specifying it's project, and entering a description.
- *
- * @author James Moger
- *
- */
-public class RepositoryNamePanel extends BasePanel {
-
- private static final long serialVersionUID = 1L;
-
- private String fullName;
-
- private final IModel<String> projectPath;
-
- private DropDownChoice<String> pathChoice;
-
- private final IModel<String> repoName;
-
- private TextField<String> nameField;
-
- public RepositoryNamePanel(String wicketId, RepositoryModel repository) {
- super(wicketId);
-
- GitBlitWebSession session = GitBlitWebSession.get();
- UserModel user = session.getUser();
-
- // build project set for repository destination
- String defaultPath = null;
- String defaultName = null;
- Set<String> pathNames = new TreeSet<String>();
-
- // add the registered/known projects
- for (ProjectModel project : app().projects().getProjectModels(user, false)) {
- // TODO issue-351: user.canAdmin(project)
- if (user.canAdmin()) {
- if (project.isRoot) {
- pathNames.add("/");
- } else {
- pathNames.add(project.name + "/");
- }
- }
- }
-
- // add the user's personal project namespace
- if (user.canAdmin() || user.canCreate()) {
- pathNames.add(user.getPersonalPath() + "/");
- }
-
- if (!StringUtils.isEmpty(repository.name)) {
- // editing a repository name
- // set the defaultProject to the current repository project
- if (StringUtils.isEmpty(repository.projectPath)) {
- defaultPath = "/";
- defaultName = repository.name;
- } else {
- defaultPath = repository.projectPath + "/";
- defaultName = repository.name.substring(defaultPath.length());
- }
- pathNames.add(defaultPath);
- }
-
- // if default project is not already set, set preference based on the user permissions
- if (defaultPath == null) {
- if (user.canAdmin()) {
- defaultPath = "/";
- } else if (user.canCreate()) {
- defaultPath = user.getPersonalPath() + "/";
- }
- }
-
- projectPath = Model.of(defaultPath);
- pathChoice = new DropDownChoice<String>("projectPath", projectPath, new ArrayList<String>(pathNames));
- repoName = Model.of(defaultName);
- nameField = new TextField<String>("name", repoName);
-
- // only enable project selection if we actually have multiple choices
- add(pathChoice.setEnabled(pathNames.size() > 1));
- add(nameField);
- add(new TextField<String>("description"));
- }
-
- public void setEditable(boolean editable) {
- // only enable project selection if we actually have multiple choices
- pathChoice.setEnabled(pathChoice.getChoices().size() > 1 && editable);
- nameField.setEnabled(editable);
- }
-
- public boolean updateModel(RepositoryModel repositoryModel) {
- // confirm a project path was selected
- if (StringUtils.isEmpty(projectPath.getObject())) {
- error(getString("gb.pleaseSelectProject"));
- return false;
- }
-
- // confirm a repository name was entered
- if (StringUtils.isEmpty(repoName.getObject())) {
- error(getString("gb.pleaseSetRepositoryName"));
- return false;
- }
-
- String project = projectPath.getObject();
- String name = repoName.getObject();
-
- fullName = (project + 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;
-
- return true;
- }
-
- @Override
- protected boolean getStatelessHint() {
- return false;
- }
+/* + * 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.Set; +import java.util.TreeSet; + +import org.apache.wicket.markup.html.form.DropDownChoice; +import org.apache.wicket.markup.html.form.TextField; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; + +import com.gitblit.models.ProjectModel; +import com.gitblit.models.RepositoryModel; +import com.gitblit.models.UserModel; +import com.gitblit.utils.StringUtils; +import com.gitblit.wicket.GitBlitWebSession; + +/** + * A panel for naming a repository, specifying it's project, and entering a description. + * + * @author James Moger + * + */ +public class RepositoryNamePanel extends BasePanel { + + private static final long serialVersionUID = 1L; + + private String fullName; + + private final IModel<String> projectPath; + + private DropDownChoice<String> pathChoice; + + private final IModel<String> repoName; + + private TextField<String> nameField; + + public RepositoryNamePanel(String wicketId, RepositoryModel repository) { + super(wicketId); + + GitBlitWebSession session = GitBlitWebSession.get(); + UserModel user = session.getUser(); + + // build project set for repository destination + String defaultPath = null; + String defaultName = null; + Set<String> pathNames = new TreeSet<String>(); + +// // add all specified project paths +// if (user.ownerOf != null) { +// for (String path : user.ownerOf) { +// if (path.charAt(path.length() - 1) == '/') { +// projectNames.add(path); +// } +// } +// } +// + // add the registered/known projects + for (ProjectModel project : app().projects().getProjectModels(user, false)) { + // TODO issue-351: user.canAdmin(project) + if (user.canAdmin()) { + if (project.isRoot) { + pathNames.add("/"); + } else { + pathNames.add(project.name + "/"); + } + } + } + + // add the user's personal project namespace + if (user.canAdmin() || user.canCreate()) { + pathNames.add(user.getPersonalPath()); + } + + if (!StringUtils.isEmpty(repository.name)) { + // editing a repository name + // set the defaultProject to the current repository project + defaultPath = repository.getProjectPath(); + defaultName = repository.name.substring(defaultPath.length()); + pathNames.add(defaultPath); + } + + // if default project is not already set, set preference based on the user permissions + if (defaultPath == null) { + if (user.canAdmin()) { + defaultPath = "/"; + } else if (user.canCreate()) { + defaultPath = user.getPersonalPath(); + } + } + + projectPath = Model.of(defaultPath); + pathChoice = new DropDownChoice<String>("projectPath", projectPath, new ArrayList<String>(pathNames)); + repoName = Model.of(defaultName); + nameField = new TextField<String>("name", repoName); + + // only enable project selection if we actually have multiple choices + add(pathChoice.setEnabled(pathNames.size() > 1)); + add(nameField); + add(new TextField<String>("description")); + } + + public void setEditable(boolean editable) { + // only enable project selection if we actually have multiple choices + pathChoice.setEnabled(pathChoice.getChoices().size() > 1 && editable); + nameField.setEnabled(editable); + } + + public boolean updateModel(RepositoryModel repositoryModel) { + // confirm a project path was selected + if (StringUtils.isEmpty(projectPath.getObject())) { + error(getString("gb.pleaseSelectProject")); + return false; + } + + // confirm a repository name was entered + if (StringUtils.isEmpty(repoName.getObject())) { + error(getString("gb.pleaseSetRepositoryName")); + return false; + } + + String project = projectPath.getObject(); + String name = repoName.getObject(); + + fullName = (project + 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; + + return true; + } + + @Override + protected boolean getStatelessHint() { + return false; + } }
\ No newline at end of file |