From 3636765f0d46e513cb7aa1c665c49b933f435b22 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Fri, 26 Sep 2014 10:01:07 -0400
Subject: [PATCH] Merged #191 "Allow authentication providers to control user and team role changes"

---
 src/main/java/com/gitblit/wicket/pages/EditUserPage.java |   24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/gitblit/wicket/pages/EditUserPage.java b/src/main/java/com/gitblit/wicket/pages/EditUserPage.java
index 454aa61..5ee2f9f 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;
@@ -216,17 +217,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
+		// not all user providers support manipulating username and password
 		boolean editCredentials = app().authentication().supportsCredentialChanges(userModel);
 
-		// not all user services support manipulating display name
+		// not all user providers support manipulating display name
 		boolean editDisplayName = app().authentication().supportsDisplayNameChanges(userModel);
 
-		// not all user services support manipulating email address
+		// not all user providers support manipulating email address
 		boolean editEmailAddress = app().authentication().supportsEmailAddressChanges(userModel);
 
-		// not all user services support manipulating team memberships
+		// 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));
@@ -245,7 +255,7 @@
 			// display a disabled-yet-checked checkbox
 			form.add(new CheckBox("canAdmin", Model.of(true)).setEnabled(false));
 		} else {
-			form.add(new CheckBox("canAdmin"));
+			form.add(new CheckBox("canAdmin").setEnabled(changeAdminRole));
 		}
 
 		if (userModel.canFork() && !userModel.canFork) {
@@ -254,7 +264,7 @@
 			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));
+			form.add(new CheckBox("canFork").setEnabled(forkingAllowed && changeForkRole));
 		}
 
 		if (userModel.canCreate() && !userModel.canCreate) {
@@ -262,7 +272,7 @@
 			// display a disabled-yet-checked checkbox
 			form.add(new CheckBox("canCreate", Model.of(true)).setEnabled(false));
 		} else {
-			form.add(new CheckBox("canCreate"));
+			form.add(new CheckBox("canCreate").setEnabled(changeCreateRole));
 		}
 
 		form.add(new CheckBox("excludeFromFederation"));

--
Gitblit v1.9.1