summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/gitblit/GitBlit.java42
-rw-r--r--src/main/java/com/gitblit/manager/IGitblit.java26
-rw-r--r--src/main/java/com/gitblit/service/FederationPullService.java6
-rw-r--r--src/main/java/com/gitblit/servlet/RpcServlet.java8
-rw-r--r--src/main/java/com/gitblit/wicket/pages/ChangePasswordPage.java2
-rw-r--r--src/main/java/com/gitblit/wicket/pages/EditTeamPage.java6
-rw-r--r--src/main/java/com/gitblit/wicket/pages/EditUserPage.java6
-rw-r--r--src/main/java/com/gitblit/wicket/pages/RepositoryPage.java2
-rw-r--r--src/test/java/com/gitblit/tests/GitServletTest.java10
9 files changed, 75 insertions, 33 deletions
diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java
index d736c57a..d07ac9a7 100644
--- a/src/main/java/com/gitblit/GitBlit.java
+++ b/src/main/java/com/gitblit/GitBlit.java
@@ -183,7 +183,7 @@ public class GitBlit implements IGitblit {
UserModel originOwner = userManager.getUserModel(owner);
if (originOwner != null) {
originOwner.setRepositoryPermission(cloneName, AccessPermission.CLONE);
- updateUserModel(originOwner.username, originOwner, false);
+ reviseUser(originOwner.username, originOwner);
}
}
}
@@ -222,15 +222,25 @@ public class GitBlit implements IGitblit {
}
/**
+ * Adds a TeamModel object.
+ *
+ * @param team
+ */
+ @Override
+ public void addTeam(TeamModel team) throws GitBlitException {
+ if (!userManager.updateTeamModel(team)) {
+ throw new GitBlitException("Failed to add team!");
+ }
+ }
+
+ /**
* Updates the TeamModel object for the specified name.
*
* @param teamname
* @param team
- * @param isCreate
*/
@Override
- public void updateTeamModel(String teamname, TeamModel team, boolean isCreate)
- throws GitBlitException {
+ public void reviseTeam(String teamname, TeamModel team) throws GitBlitException {
if (!teamname.equalsIgnoreCase(team.name)) {
if (userManager.getTeamModel(team.name) != null) {
throw new GitBlitException(MessageFormat.format(
@@ -239,23 +249,33 @@ public class GitBlit implements IGitblit {
}
}
if (!userManager.updateTeamModel(teamname, team)) {
- throw new GitBlitException(isCreate ? "Failed to add team!" : "Failed to update team!");
+ throw new GitBlitException("Failed to update team!");
+ }
+ }
+
+ /**
+ * Adds a user object.
+ *
+ * @param user
+ * @throws GitBlitException
+ */
+ @Override
+ public void addUser(UserModel user) throws GitBlitException {
+ if (!userManager.updateUserModel(user)) {
+ throw new GitBlitException("Failed to add user!");
}
}
/**
- * Adds/updates a complete user object keyed by username. This method allows
+ * Updates a user object keyed by username. This method allows
* for renaming a user.
*
- * @see IUserService.updateUserModel(String, UserModel)
* @param username
* @param user
- * @param isCreate
* @throws GitBlitException
*/
@Override
- public void updateUserModel(String username, UserModel user, boolean isCreate)
- throws GitBlitException {
+ public void reviseUser(String username, UserModel user) throws GitBlitException {
if (!username.equalsIgnoreCase(user.username)) {
if (userManager.getUserModel(user.username) != null) {
throw new GitBlitException(MessageFormat.format(
@@ -280,7 +300,7 @@ public class GitBlit implements IGitblit {
}
}
if (!userManager.updateUserModel(username, user)) {
- throw new GitBlitException(isCreate ? "Failed to add user!" : "Failed to update user!");
+ throw new GitBlitException("Failed to update user!");
}
}
diff --git a/src/main/java/com/gitblit/manager/IGitblit.java b/src/main/java/com/gitblit/manager/IGitblit.java
index c0167f0d..aa091226 100644
--- a/src/main/java/com/gitblit/manager/IGitblit.java
+++ b/src/main/java/com/gitblit/manager/IGitblit.java
@@ -47,25 +47,39 @@ public interface IGitblit extends IManager,
List<RepositoryUrl> getRepositoryUrls(HttpServletRequest request, UserModel user, RepositoryModel repository);
/**
- * Adds/updates a complete user object keyed by username. This method allows
+ * Creates a complete user object.
+ *
+ * @param user
+ * @param isCreate
+ * @throws GitBlitException
+ */
+ void addUser(UserModel user) throws GitBlitException;
+
+ /**
+ * Updates a complete user object keyed by username. This method allows
* for renaming a user.
*
- * @see IUserService.updateUserModel(String, UserModel)
* @param username
* @param user
- * @param isCreate
* @throws GitBlitException
*/
- void updateUserModel(String username, UserModel user, boolean isCreate) throws GitBlitException;
+ void reviseUser(String username, UserModel user) throws GitBlitException;
+
+ /**
+ * Creates a TeamModel object.
+ *
+ * @param team
+ * @param isCreate
+ */
+ void addTeam(TeamModel team) throws GitBlitException;
/**
* Updates the TeamModel object for the specified name.
*
* @param teamname
* @param team
- * @param isCreate
*/
- void updateTeamModel(String teamname, TeamModel team, boolean isCreate) throws GitBlitException;
+ void reviseTeam(String teamname, TeamModel team) throws GitBlitException;
/**
* Creates a personal fork of the specified repository. The clone is view
diff --git a/src/main/java/com/gitblit/service/FederationPullService.java b/src/main/java/com/gitblit/service/FederationPullService.java
index c804f3f1..e2a50f29 100644
--- a/src/main/java/com/gitblit/service/FederationPullService.java
+++ b/src/main/java/com/gitblit/service/FederationPullService.java
@@ -31,8 +31,8 @@ import com.gitblit.Constants;
import com.gitblit.Constants.AccessPermission;
import com.gitblit.Constants.FederationPullStatus;
import com.gitblit.Constants.FederationStrategy;
-import com.gitblit.GitBlitException.ForbiddenException;
import com.gitblit.GitBlit;
+import com.gitblit.GitBlitException.ForbiddenException;
import com.gitblit.IUserService;
import com.gitblit.Keys;
import com.gitblit.models.FederationModel;
@@ -346,7 +346,7 @@ public abstract class FederationPullService implements Runnable {
UserModel localUser = gitblit.getUserModel(user.username);
if (localUser == null) {
// create new local user
- gitblit.updateUserModel(user.username, user, true);
+ gitblit.addUser(user);
} else {
// update repository permissions of local user
if (user.permissions != null) {
@@ -363,7 +363,7 @@ public abstract class FederationPullService implements Runnable {
}
localUser.password = user.password;
localUser.canAdmin = user.canAdmin;
- gitblit.updateUserModel(localUser.username, localUser, false);
+ gitblit.reviseUser(localUser.username, localUser);
}
for (String teamname : gitblit.getAllTeamNames()) {
diff --git a/src/main/java/com/gitblit/servlet/RpcServlet.java b/src/main/java/com/gitblit/servlet/RpcServlet.java
index 481a8bae..856bd839 100644
--- a/src/main/java/com/gitblit/servlet/RpcServlet.java
+++ b/src/main/java/com/gitblit/servlet/RpcServlet.java
@@ -218,7 +218,7 @@ public class RpcServlet extends JsonServlet {
// create user
UserModel model = deserialize(request, response, UserModel.class);
try {
- gitblit.updateUserModel(model.username, model, true);
+ gitblit.addUser(model);
} catch (GitBlitException e) {
response.setStatus(failureCode);
}
@@ -231,7 +231,7 @@ public class RpcServlet extends JsonServlet {
username = model.username;
}
try {
- gitblit.updateUserModel(username, model, false);
+ gitblit.reviseUser(username, model);
} catch (GitBlitException e) {
response.setStatus(failureCode);
}
@@ -245,7 +245,7 @@ public class RpcServlet extends JsonServlet {
// create team
TeamModel model = deserialize(request, response, TeamModel.class);
try {
- gitblit.updateTeamModel(model.name, model, true);
+ gitblit.addTeam(model);
} catch (GitBlitException e) {
response.setStatus(failureCode);
}
@@ -258,7 +258,7 @@ public class RpcServlet extends JsonServlet {
teamname = model.name;
}
try {
- gitblit.updateTeamModel(teamname, model, false);
+ gitblit.reviseTeam(teamname, model);
} catch (GitBlitException e) {
response.setStatus(failureCode);
}
diff --git a/src/main/java/com/gitblit/wicket/pages/ChangePasswordPage.java b/src/main/java/com/gitblit/wicket/pages/ChangePasswordPage.java
index ec5fe16e..4c8d3a1d 100644
--- a/src/main/java/com/gitblit/wicket/pages/ChangePasswordPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/ChangePasswordPage.java
@@ -97,7 +97,7 @@ public class ChangePasswordPage extends RootSubPage {
user.password = password;
try {
- app().gitblit().updateUserModel(user.username, user, false);
+ app().gitblit().reviseUser(user.username, user);
if (app().settings().getBoolean(Keys.web.allowCookieAuthentication, false)) {
WebResponse response = (WebResponse) getRequestCycle().getResponse();
app().authentication().setCookie(response.getHttpServletResponse(), user);
diff --git a/src/main/java/com/gitblit/wicket/pages/EditTeamPage.java b/src/main/java/com/gitblit/wicket/pages/EditTeamPage.java
index 232dbe3b..82b28fc4 100644
--- a/src/main/java/com/gitblit/wicket/pages/EditTeamPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/EditTeamPage.java
@@ -196,7 +196,11 @@ public class EditTeamPage extends RootSubPage {
teamModel.postReceiveScripts.addAll(postReceiveScripts);
try {
- app().gitblit().updateTeamModel(oldName, teamModel, isCreate);
+ if (isCreate) {
+ app().gitblit().addTeam(teamModel);
+ } else {
+ app().gitblit().reviseTeam(oldName, teamModel);
+ }
} catch (GitBlitException e) {
error(e.getMessage());
return;
diff --git a/src/main/java/com/gitblit/wicket/pages/EditUserPage.java b/src/main/java/com/gitblit/wicket/pages/EditUserPage.java
index 4e91b45a..62a8ea5a 100644
--- a/src/main/java/com/gitblit/wicket/pages/EditUserPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/EditUserPage.java
@@ -188,7 +188,11 @@ public class EditUserPage extends RootSubPage {
}
try {
- app().gitblit().updateUserModel(oldName, userModel, isCreate);
+ if (isCreate) {
+ app().gitblit().addUser(userModel);
+ } else {
+ app().gitblit().reviseUser(oldName, userModel);
+ }
} catch (GitBlitException e) {
error(e.getMessage());
return;
diff --git a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
index dd6763d5..a108f922 100644
--- a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
@@ -139,7 +139,7 @@ public abstract class RepositoryPage extends RootPage {
UserRepositoryPreferences prefs = user.getPreferences().getRepositoryPreferences(getRepositoryModel().name);
prefs.starred = star;
try {
- app().gitblit().updateUserModel(user.username, user, false);
+ app().gitblit().reviseUser(user.username, user);
} catch (GitBlitException e) {
logger.error("Failed to update user " + user.username, e);
error(getString("gb.failedToUpdateUser"), false);
diff --git a/src/test/java/com/gitblit/tests/GitServletTest.java b/src/test/java/com/gitblit/tests/GitServletTest.java
index ad61a676..705684a3 100644
--- a/src/test/java/com/gitblit/tests/GitServletTest.java
+++ b/src/test/java/com/gitblit/tests/GitServletTest.java
@@ -177,7 +177,7 @@ public class GitServletTest extends GitblitUnitTest {
model.authorizationControl = AuthorizationControl.NAMED;
UserModel user = new UserModel("james");
user.password = "james";
- gitblit().updateUserModel(user.username, user, true);
+ gitblit().addUser(user);
repositories().updateRepositoryModel(model.name, model, false);
FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE);
@@ -419,7 +419,7 @@ public class GitServletTest extends GitblitUnitTest {
// grant user push permission
user.setRepositoryPermission(model.name, AccessPermission.PUSH);
- gitblit().updateUserModel(user.username, user, true);
+ gitblit().addUser(user);
repositories().updateRepositoryModel(model.name, model, false);
// clone temp bare repo to working copy
@@ -504,7 +504,7 @@ public class GitServletTest extends GitblitUnitTest {
// grant user push permission
user.setRepositoryPermission(model.name, AccessPermission.PUSH);
- gitblit().updateUserModel(user.username, user, true);
+ gitblit().addUser(user);
repositories().updateRepositoryModel(model.name, model, false);
// clone temp bare repo to working copy
@@ -657,7 +657,7 @@ public class GitServletTest extends GitblitUnitTest {
// grant user specified
user.setRepositoryPermission(model.name, permission);
- gitblit().updateUserModel(user.username, user, true);
+ gitblit().addUser(user);
repositories().updateRepositoryModel(model.name, model, false);
// clone temp bare repo to working copy
@@ -827,7 +827,7 @@ public class GitServletTest extends GitblitUnitTest {
user.canCreate = canCreate;
user.canAdmin = canAdmin;
- gitblit().updateUserModel(user.username, user, true);
+ gitblit().addUser(user);
CredentialsProvider cp = new UsernamePasswordCredentialsProvider(user.username, user.password);