Browse Source

Change IGitblit API to be more distinct from IUserService

Change-Id: I8fb38fb6a3dae74ad7a12b045b054373b9b02518
tags/v1.4.0
James Moger 10 years ago
parent
commit
5ae529ea8a

+ 31
- 11
src/main/java/com/gitblit/GitBlit.java View File

@@ -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);
}
}
}
@@ -221,16 +221,26 @@ public class GitBlit implements IGitblit {
return cloneModel;
}

/**
* 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!");
}
}


+ 20
- 6
src/main/java/com/gitblit/manager/IGitblit.java View File

@@ -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

+ 3
- 3
src/main/java/com/gitblit/service/FederationPullService.java View File

@@ -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()) {

+ 4
- 4
src/main/java/com/gitblit/servlet/RpcServlet.java View File

@@ -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);
}

+ 1
- 1
src/main/java/com/gitblit/wicket/pages/ChangePasswordPage.java View File

@@ -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);

+ 5
- 1
src/main/java/com/gitblit/wicket/pages/EditTeamPage.java View File

@@ -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;

+ 5
- 1
src/main/java/com/gitblit/wicket/pages/EditUserPage.java View File

@@ -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;

+ 1
- 1
src/main/java/com/gitblit/wicket/pages/RepositoryPage.java View File

@@ -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);

+ 5
- 5
src/test/java/com/gitblit/tests/GitServletTest.java View File

@@ -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);

Loading…
Cancel
Save