summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/wicket
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/gitblit/wicket')
-rw-r--r--src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java47
-rw-r--r--src/main/java/com/gitblit/wicket/pages/ForksPage.java8
-rw-r--r--src/main/java/com/gitblit/wicket/pages/MyDashboardPage.java2
-rw-r--r--src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java9
-rw-r--r--src/main/java/com/gitblit/wicket/pages/OverviewPage.java27
-rw-r--r--src/main/java/com/gitblit/wicket/pages/RepositoryPage.java2
-rw-r--r--src/main/java/com/gitblit/wicket/pages/RootPage.java2
-rw-r--r--src/main/java/com/gitblit/wicket/pages/RootSubPage.java11
-rw-r--r--src/main/java/com/gitblit/wicket/pages/SummaryPage.java21
-rw-r--r--src/main/java/com/gitblit/wicket/panels/ProjectRepositoryPanel.java20
-rw-r--r--src/main/java/com/gitblit/wicket/panels/RepositoriesPanel.java32
-rw-r--r--src/main/java/com/gitblit/wicket/panels/RepositoryNamePanel.java346
12 files changed, 254 insertions, 273 deletions
diff --git a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java
index a1c37385..85ee55fc 100644
--- a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java
@@ -59,6 +59,7 @@ import com.gitblit.Constants.FederationStrategy;
import com.gitblit.Constants.RegistrantType;
import com.gitblit.GitBlitException;
import com.gitblit.Keys;
+import com.gitblit.models.Owner;
import com.gitblit.models.RegistrantAccessPermission;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserChoice;
@@ -107,9 +108,8 @@ public class EditRepositoryPage extends RootSubPage {
UserModel user = session.getUser();
if (user != null && user.canCreate() && !user.canAdmin()) {
// personal create permissions, inject personal repository path
- model.name = user.getPersonalPath() + "/";
- model.projectPath = user.getPersonalPath();
- model.addOwner(user.username);
+ model.name = user.getPersonalPath();
+
// personal repositories are private by default
model.accessRestriction = AccessRestrictionType.VIEW;
model.authorizationControl = AuthorizationControl.NAMED;
@@ -156,7 +156,6 @@ public class EditRepositoryPage extends RootSubPage {
GitBlitWebSession session = GitBlitWebSession.get();
final UserModel user = session.getUser() == null ? UserModel.ANONYMOUS : session.getUser();
- final boolean allowEditName = isCreate || isAdmin || repositoryModel.isUsersPersonalRepository(user.username);
if (isCreate) {
if (user.canAdmin()) {
@@ -186,12 +185,10 @@ public class EditRepositoryPage extends RootSubPage {
// owners palette
List<UserChoice> owners = new ArrayList<UserChoice>();
- for (String owner : repositoryModel.owners) {
- UserModel o = app().users().getUserModel(owner);
- if (o != null) {
- owners.add(new UserChoice(o.getDisplayName(), o.username, o.emailAddress));
- } else {
- owners.add(new UserChoice(owner));
+ for (Owner owner : app().users().getOwners(repositoryModel)) {
+ if (owner instanceof UserModel) {
+ UserModel userOwner = (UserModel) owner;
+ owners.add(new UserChoice(userOwner.getDisplayName(), userOwner.username, userOwner.emailAddress));
}
}
List<UserChoice> persons = new ArrayList<UserChoice>();
@@ -338,13 +335,6 @@ public class EditRepositoryPage extends RootSubPage {
}
repositoryModel.indexedBranches = indexedBranches;
- // owners
- repositoryModel.owners.clear();
- Iterator<UserChoice> owners = ownersPalette.getSelectedChoices();
- while (owners.hasNext()) {
- repositoryModel.addOwner(owners.next().getUserId());
- }
-
// pre-receive scripts
List<String> preReceiveScripts = new ArrayList<String>();
Iterator<String> pres = preReceivePalette.getSelectedChoices();
@@ -381,6 +371,21 @@ public class EditRepositoryPage extends RootSubPage {
app().gitblit().setUserAccessPermissions(repositoryModel, repositoryUsers);
app().gitblit().setTeamAccessPermissions(repositoryModel, repositoryTeams);
}
+
+ //
+ // handle ownership changes
+ //
+
+ List<Owner> newOwners = new ArrayList<>();
+ Iterator<UserChoice> owners = ownersPalette.getSelectedChoices();
+ while (owners.hasNext()) {
+ String username = owners.next().getUserId();
+ UserModel owner = app().users().getUserModel(username);
+ newOwners.add(owner);
+ }
+
+ app().users().setOwners(repositoryModel, newOwners);
+
} catch (GitBlitException e) {
error(e.getMessage());
return;
@@ -413,7 +418,6 @@ public class EditRepositoryPage extends RootSubPage {
// GENERAL
//
namePanel = new RepositoryNamePanel("namePanel", repositoryModel);
- namePanel.setEditable(allowEditName);
form.add(namePanel);
// XXX AccessPolicyPanel is defined later.
@@ -667,7 +671,7 @@ public class EditRepositoryPage extends RootSubPage {
// the user can delete if deletions are allowed AND the user is an admin or the personal owner
// assigned ownership is not sufficient to allow deletion
boolean canDelete = !isCreate && app().repositories().canDelete(repositoryModel)
- && (user.canAdmin() || user.isMyPersonalRepository(repositoryModel.name));
+ && user.canDelete(repositoryModel);
Link<Void> delete = new Link<Void>("delete") {
@@ -682,8 +686,7 @@ public class EditRepositoryPage extends RootSubPage {
info(MessageFormat.format(getString("gb.repositoryDeleted"), latestModel));
if (latestModel.isPersonalRepository()) {
// redirect to user's profile page
- String prefix = app().settings().getString(Keys.git.userRepositoryPrefix, "~");
- String username = latestModel.projectPath.substring(prefix.length());
+ String username = latestModel.getPersonalRepositoryOwner();
setResponsePage(UserPage.class, WicketUtils.newUsernameParameter(username));
} else {
// redirect to server repositories page
@@ -740,7 +743,7 @@ public class EditRepositoryPage extends RootSubPage {
isAdmin = true;
return;
} else {
- if (!model.isOwner(user.username)) {
+ if (!user.isOwner(model)) {
// User is not an Admin nor Owner
error(getString("gb.errorOnlyAdminOrOwnerMayEditRepository"), true);
}
diff --git a/src/main/java/com/gitblit/wicket/pages/ForksPage.java b/src/main/java/com/gitblit/wicket/pages/ForksPage.java
index 9fd7f4db..1c113c3b 100644
--- a/src/main/java/com/gitblit/wicket/pages/ForksPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/ForksPage.java
@@ -31,6 +31,7 @@ import com.gitblit.Keys;
import com.gitblit.models.ForkModel;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
+import com.gitblit.utils.ModelUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.WicketUtils;
@@ -57,10 +58,11 @@ public class ForksPage extends RepositoryPage {
RepositoryModel repository = fork.repository;
if (repository.isPersonalRepository()) {
- UserModel user = app().users().getUserModel(repository.projectPath.substring(1));
+ String name = ModelUtils.getUserNameFromRepoPath(repository.name);
+ UserModel user = app().users().getUserModel(name);
if (user == null) {
// user account no longer exists
- user = new UserModel(repository.projectPath.substring(1));
+ user = new UserModel(name);
}
PersonIdent ident = new PersonIdent(user.getDisplayName(), user.emailAddress == null ? user.getDisplayName() : user.emailAddress);
item.add(new GravatarImage("anAvatar", ident, 20));
@@ -81,7 +83,7 @@ public class ForksPage extends RepositoryPage {
WicketUtils.setCssClass(swatch, "repositorySwatch");
WicketUtils.setCssBackground(swatch, repository.toString());
item.add(swatch);
- String projectName = repository.projectPath;
+ String projectName = repository.getProject();
if (StringUtils.isEmpty(projectName)) {
projectName = app().settings().getString(Keys.web.repositoryRootGroupName, "main");
}
diff --git a/src/main/java/com/gitblit/wicket/pages/MyDashboardPage.java b/src/main/java/com/gitblit/wicket/pages/MyDashboardPage.java
index 0f7d602b..d7d522c7 100644
--- a/src/main/java/com/gitblit/wicket/pages/MyDashboardPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/MyDashboardPage.java
@@ -112,7 +112,7 @@ public class MyDashboardPage extends DashboardPage {
List<RepositoryModel> active = new ArrayList<RepositoryModel>();
for (RepositoryModel model : getRepositoryModels()) {
- if (model.isUsersPersonalRepository(user.username) || model.isOwner(user.username)) {
+ if (user.isOwner(model)) {
owned.add(model);
}
diff --git a/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java
index 46877168..b4c2f664 100644
--- a/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java
@@ -19,6 +19,7 @@ import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -48,6 +49,7 @@ import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.Constants.AuthorizationControl;
import com.gitblit.GitBlitException;
import com.gitblit.Keys;
+import com.gitblit.models.Owner;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
import com.gitblit.utils.ArrayUtils;
@@ -108,9 +110,6 @@ public class NewRepositoryPage extends RootSubPage {
}
accessPolicyPanel.updateModel(repositoryModel);
- repositoryModel.owners = new ArrayList<String>();
- repositoryModel.owners.add(GitBlitWebSession.get().getUsername());
-
// setup branch defaults
boolean useGitFlow = addGitflowModel.getObject();
@@ -137,6 +136,10 @@ public class NewRepositoryPage extends RootSubPage {
// init the repository
app().gitblit().updateRepositoryModel(repositoryModel.name, repositoryModel, true);
+ // save the owner change
+ List<Owner> owners = Arrays.asList((Owner) GitBlitWebSession.get().getUser());
+ app().gitblit().setOwners(repositoryModel, owners);
+
// optionally create an initial commit
initialCommit(repositoryModel, addReadme, gitignore, useGitFlow);
diff --git a/src/main/java/com/gitblit/wicket/pages/OverviewPage.java b/src/main/java/com/gitblit/wicket/pages/OverviewPage.java
index 1979f97f..e70d3b15 100644
--- a/src/main/java/com/gitblit/wicket/pages/OverviewPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/OverviewPage.java
@@ -16,7 +16,6 @@
package com.gitblit.wicket.pages;
import java.text.MessageFormat;
-import java.util.ArrayList;
import java.util.List;
import org.apache.wicket.PageParameters;
@@ -30,6 +29,7 @@ import org.eclipse.jgit.lib.Repository;
import com.gitblit.Keys;
import com.gitblit.models.Metric;
+import com.gitblit.models.Owner;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
import com.gitblit.utils.JGitUtils;
@@ -74,23 +74,18 @@ public class OverviewPage extends RepositoryPage {
add(new Label("repositoryDescription", getRepositoryModel().description));
// owner links
- final List<String> owners = new ArrayList<String>(getRepositoryModel().owners);
- ListDataProvider<String> ownersDp = new ListDataProvider<String>(owners);
- DataView<String> ownersView = new DataView<String>("repositoryOwners", ownersDp) {
+ final List<Owner> owners = app().users().getOwners(getRepositoryModel());
+ ListDataProvider<Owner> ownersDp = new ListDataProvider<Owner>(owners);
+ DataView<Owner> ownersView = new DataView<Owner>("repositoryOwners", ownersDp) {
private static final long serialVersionUID = 1L;
int counter = 0;
@Override
- public void populateItem(final Item<String> item) {
- String ownername = item.getModelObject();
- UserModel ownerModel = app().users().getUserModel(ownername);
- if (ownerModel != null) {
- item.add(new LinkPanel("owner", null, ownerModel.getDisplayName(), UserPage.class,
- WicketUtils.newUsernameParameter(ownerModel.username)).setRenderBodyOnly(true));
- } else {
- Label owner = new Label("owner", ownername);
- WicketUtils.setCssStyle(owner, "text-decoration: line-through;");
- WicketUtils.setHtmlTooltip(owner, MessageFormat.format(getString("gb.failedToFindAccount"), ownername));
- item.add(owner);
+ public void populateItem(final Item<Owner> item) {
+ Owner owner = item.getModelObject();
+ if (owner instanceof UserModel) {
+ UserModel user = (UserModel) owner;
+ item.add(new LinkPanel("owner", null, user.getDisplayName(), UserPage.class,
+ WicketUtils.newUsernameParameter(user.username)).setRenderBodyOnly(true));
}
counter++;
item.add(new Label("comma", ",").setVisible(counter < owners.size()));
@@ -136,7 +131,7 @@ public class OverviewPage extends RepositoryPage {
&& app().settings().getBoolean(Keys.web.generateActivityGraph, true)) {
Charts charts = new Flotr2Charts();
-
+
// daily line chart
Chart chart = charts.createLineChart("chartDaily", "", "unit",
getString("gb.commits"));
diff --git a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
index fcf659af..71eb859e 100644
--- a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
@@ -156,7 +156,7 @@ public abstract class RepositoryPage extends RootPage {
showAdmin = app().settings().getBoolean(Keys.web.allowAdministration, false);
}
isOwner = GitBlitWebSession.get().isLoggedIn()
- && (getRepositoryModel().isOwner(GitBlitWebSession.get().getUsername()));
+ && (GitBlitWebSession.get().getUser().isOwner(getRepositoryModel()));
// register the available navigation links for this page and user
List<NavLink> navLinks = registerNavLinks();
diff --git a/src/main/java/com/gitblit/wicket/pages/RootPage.java b/src/main/java/com/gitblit/wicket/pages/RootPage.java
index b1c3639d..98a8df89 100644
--- a/src/main/java/com/gitblit/wicket/pages/RootPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/RootPage.java
@@ -412,7 +412,7 @@ public abstract class RootPage extends BasePage {
String userName = WicketUtils.getUsername(params);
if (StringUtils.isEmpty(projectName)) {
if (!StringUtils.isEmpty(userName)) {
- projectName = ModelUtils.getPersonalPath(userName);
+ projectName = ModelUtils.getPersonalProject(userName);
}
}
String repositoryName = WicketUtils.getRepositoryName(params);
diff --git a/src/main/java/com/gitblit/wicket/pages/RootSubPage.java b/src/main/java/com/gitblit/wicket/pages/RootSubPage.java
index 62d07a7f..53ed198f 100644
--- a/src/main/java/com/gitblit/wicket/pages/RootSubPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/RootSubPage.java
@@ -89,17 +89,16 @@ public abstract class RootSubPage extends RootPage {
RepositoryModel repositoryModel = app().repositories().getRepositoryModel(repo);
if (repositoryModel.accessRestriction.exceeds(AccessRestrictionType.NONE)
&& repositoryModel.authorizationControl.equals(AuthorizationControl.NAMED)) {
- if (user != null &&
- (repositoryModel.isOwner(user.username) || repositoryModel.isUsersPersonalRepository(user.username))) {
+ if (user != null && user.isOwner(repositoryModel)) {
// exclude Owner or personal repositories
continue;
}
if (includeWildcards) {
- if (lastProject == null || !lastProject.equalsIgnoreCase(repositoryModel.projectPath)) {
- lastProject = repositoryModel.projectPath.toLowerCase();
- if (!StringUtils.isEmpty(repositoryModel.projectPath)) {
+ if (lastProject == null || !lastProject.equalsIgnoreCase(repositoryModel.getProject())) {
+ lastProject = repositoryModel.getProject().toLowerCase();
+ if (!StringUtils.isEmpty(repositoryModel.getProject())) {
// regex for all repositories within a project
- repos.add(repositoryModel.projectPath + "/.*");
+ repos.add(repositoryModel.getProjectPath() + "/.*");
}
}
}
diff --git a/src/main/java/com/gitblit/wicket/pages/SummaryPage.java b/src/main/java/com/gitblit/wicket/pages/SummaryPage.java
index 090c0952..a3544c70 100644
--- a/src/main/java/com/gitblit/wicket/pages/SummaryPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/SummaryPage.java
@@ -18,7 +18,6 @@ package com.gitblit.wicket.pages;
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -36,6 +35,7 @@ import org.eclipse.jgit.revwalk.RevCommit;
import com.gitblit.Keys;
import com.gitblit.models.Metric;
+import com.gitblit.models.Owner;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
import com.gitblit.utils.JGitUtils;
@@ -88,23 +88,18 @@ public class SummaryPage extends RepositoryPage {
add(new Label("repositoryDescription", getRepositoryModel().description));
// owner links
- final List<String> owners = new ArrayList<String>(getRepositoryModel().owners);
- ListDataProvider<String> ownersDp = new ListDataProvider<String>(owners);
- DataView<String> ownersView = new DataView<String>("repositoryOwners", ownersDp) {
+ final List<Owner> owners = app().users().getOwners(getRepositoryModel());
+ ListDataProvider<Owner> ownersDp = new ListDataProvider<>(owners);
+ DataView<Owner> ownersView = new DataView<Owner>("repositoryOwners", ownersDp) {
private static final long serialVersionUID = 1L;
int counter = 0;
@Override
- public void populateItem(final Item<String> item) {
- String ownername = item.getModelObject();
- UserModel ownerModel = app().users().getUserModel(ownername);
- if (ownerModel != null) {
+ public void populateItem(final Item<Owner> item) {
+ Owner owner = item.getModelObject();
+ if (owner instanceof UserModel) {
+ UserModel ownerModel = (UserModel) owner;
item.add(new LinkPanel("owner", null, ownerModel.getDisplayName(), UserPage.class,
WicketUtils.newUsernameParameter(ownerModel.username)).setRenderBodyOnly(true));
- } else {
- Label owner = new Label("owner", ownername);
- WicketUtils.setCssStyle(owner, "text-decoration: line-through;");
- WicketUtils.setHtmlTooltip(owner, MessageFormat.format(getString("gb.failedToFindAccount"), ownername));
- item.add(owner);
}
counter++;
item.add(new Label("comma", ",").setVisible(counter < owners.size()));
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