From 2e141ff31dedaa6dfefc4af47eda803d8dbb3eff Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Tue, 01 Sep 2015 08:49:02 -0400
Subject: [PATCH] Fix #909: Add missing SLFJ dependencies in Manager build
---
src/main/java/com/gitblit/wicket/pages/EditUserPage.java | 76 +++++++++++++++++++++++++++++---------
1 files changed, 58 insertions(+), 18 deletions(-)
diff --git a/src/main/java/com/gitblit/wicket/pages/EditUserPage.java b/src/main/java/com/gitblit/wicket/pages/EditUserPage.java
index b2d3d3b..c6b5c3c 100644
--- a/src/main/java/com/gitblit/wicket/pages/EditUserPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/EditUserPage.java
@@ -35,6 +35,7 @@
import org.apache.wicket.model.util.ListModel;
import com.gitblit.Constants.RegistrantType;
+import com.gitblit.Constants.Role;
import com.gitblit.GitBlitException;
import com.gitblit.Keys;
import com.gitblit.models.RegistrantAccessPermission;
@@ -54,10 +55,6 @@
public EditUserPage() {
// create constructor
super();
- if (!app().users().supportsAddUser()) {
- error(MessageFormat.format(getString("gb.userServiceDoesNotPermitAddUser"),
- app().settings().getString(Keys.realm.userService, "${baseFolder}/users.conf")), true);
- }
isCreate = true;
setupPage(new UserModel(""));
setStatelessHint(false);
@@ -138,7 +135,7 @@
}
boolean rename = !StringUtils.isEmpty(oldName)
&& !oldName.equalsIgnoreCase(username);
- if (app().users().supportsCredentialChanges(userModel)) {
+ if (app().authentication().supportsCredentialChanges(userModel)) {
if (!userModel.password.equals(confirmPassword.getObject())) {
error(getString("gb.passwordsDoNotMatch"));
return;
@@ -157,6 +154,9 @@
minLength));
return;
}
+
+ // change the cookie
+ userModel.cookie = StringUtils.getSHA1(userModel.username + password);
// Optionally store the password MD5 digest.
String type = app().settings().getString(Keys.realm.passwordStorage, "md5");
@@ -178,7 +178,9 @@
// update user permissions
for (RegistrantAccessPermission repositoryPermission : permissions) {
- userModel.setRepositoryPermission(repositoryPermission.registrant, repositoryPermission.permission);
+ if (repositoryPermission.mutable) {
+ userModel.setRepositoryPermission(repositoryPermission.registrant, repositoryPermission.permission);
+ }
}
Iterator<String> selectedTeams = teams.getSelectedChoices();
@@ -192,7 +194,11 @@
}
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;
@@ -213,17 +219,26 @@
// do not let the browser pre-populate these fields
form.add(new SimpleAttributeModifier("autocomplete", "off"));
- // not all user services support manipulating username and password
- boolean editCredentials = app().users().supportsCredentialChanges(userModel);
+ // not all user providers support manipulating username and password
+ boolean editCredentials = app().authentication().supportsCredentialChanges(userModel);
- // not all user services support manipulating display name
- boolean editDisplayName = app().users().supportsDisplayNameChanges(userModel);
+ // not all user providers support manipulating display name
+ boolean editDisplayName = app().authentication().supportsDisplayNameChanges(userModel);
- // not all user services support manipulating email address
- boolean editEmailAddress = app().users().supportsEmailAddressChanges(userModel);
+ // not all user providers support manipulating email address
+ boolean editEmailAddress = app().authentication().supportsEmailAddressChanges(userModel);
- // not all user services support manipulating team memberships
- boolean editTeams = app().users().supportsTeamMembershipChanges(userModel);
+ // not all user providers support manipulating team memberships
+ boolean editTeams = app().authentication().supportsTeamMembershipChanges(userModel);
+
+ // not all user providers support manipulating the admin role
+ boolean changeAdminRole = app().authentication().supportsRoleChanges(userModel, Role.ADMIN);
+
+ // not all user providers support manipulating the create role
+ boolean changeCreateRole = app().authentication().supportsRoleChanges(userModel, Role.CREATE);
+
+ // not all user providers support manipulating the fork role
+ boolean changeForkRole = app().authentication().supportsRoleChanges(userModel, Role.FORK);
// field names reflective match UserModel fields
form.add(new TextField<String>("username").setEnabled(editCredentials));
@@ -236,10 +251,35 @@
form.add(confirmPasswordField.setEnabled(editCredentials));
form.add(new TextField<String>("displayName").setEnabled(editDisplayName));
form.add(new TextField<String>("emailAddress").setEnabled(editEmailAddress));
- form.add(new CheckBox("canAdmin"));
- form.add(new CheckBox("canFork").setEnabled(app().settings().getBoolean(Keys.web.allowForking, true)));
- form.add(new CheckBox("canCreate"));
+
+ if (userModel.canAdmin() && !userModel.canAdmin) {
+ // user inherits Admin permission
+ // display a disabled-yet-checked checkbox
+ form.add(new CheckBox("canAdmin", Model.of(true)).setEnabled(false));
+ } else {
+ form.add(new CheckBox("canAdmin").setEnabled(changeAdminRole));
+ }
+
+ if (userModel.canFork() && !userModel.canFork) {
+ // user inherits Fork permission
+ // display a disabled-yet-checked checkbox
+ form.add(new CheckBox("canFork", Model.of(true)).setEnabled(false));
+ } else {
+ final boolean forkingAllowed = app().settings().getBoolean(Keys.web.allowForking, true);
+ form.add(new CheckBox("canFork").setEnabled(forkingAllowed && changeForkRole));
+ }
+
+ if (userModel.canCreate() && !userModel.canCreate) {
+ // user inherits Create permission
+ // display a disabled-yet-checked checkbox
+ form.add(new CheckBox("canCreate", Model.of(true)).setEnabled(false));
+ } else {
+ form.add(new CheckBox("canCreate").setEnabled(changeCreateRole));
+ }
+
form.add(new CheckBox("excludeFromFederation"));
+ form.add(new CheckBox("disabled"));
+
form.add(new RegistrantPermissionsPanel("repositories", RegistrantType.REPOSITORY, repos, permissions, getAccessPermissions()));
form.add(teams.setEnabled(editTeams));
--
Gitblit v1.9.1