summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/wicket/pages
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/gitblit/wicket/pages')
-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
9 files changed, 63 insertions, 66 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()));