roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r581941 - in /roller/branches/roller_4.1_dev/apps/weblogger: src/java/org/apache/roller/weblogger/business/jpa/ src/java/org/apache/roller/weblogger/config/ test/java/org/apache/roller/weblogger/business/
Date Thu, 04 Oct 2007 15:01:55 GMT
Author: snoopdave
Date: Thu Oct  4 08:01:54 2007
New Revision: 581941

URL: http://svn.apache.org/viewvc?rev=581941&view=rev
Log:
Make first-user-is-admin configurable as not all user management implementations work that
way

Modified:
    roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java
    roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/config/roller.properties
    roller/branches/roller_4.1_dev/apps/weblogger/test/java/org/apache/roller/weblogger/business/UserTest.java

Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java?rev=581941&r1=581940&r2=581941&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java
Thu Oct  4 08:01:54 2007
@@ -38,6 +38,7 @@
 import java.util.Comparator;
 import javax.persistence.Query;
 import org.apache.roller.weblogger.business.Weblogger;
+import org.apache.roller.weblogger.config.WebloggerConfig;
 
 
 @com.google.inject.Singleton
@@ -102,7 +103,8 @@
         // TODO BACKEND: we must do this in a better fashion, like getUserCnt()?
         boolean adminUser = false;
         List existingUsers = this.getUsers(Boolean.TRUE, null, null, 0, 1);
-        if (existingUsers.size() == 0) {
+        boolean firstUserAdmin = WebloggerConfig.getBooleanProperty("users.firstUserAdmin");
+        if (existingUsers.size() == 0 && firstUserAdmin) {
             // Make first user an admin
             adminUser = true;
             

Modified: roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/config/roller.properties
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/config/roller.properties?rev=581941&r1=581940&r2=581941&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/config/roller.properties
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/src/java/org/apache/roller/weblogger/config/roller.properties
Thu Oct  4 08:01:54 2007
@@ -352,6 +352,9 @@
 role.action.editor=login,comment,createWeblog
 role.action.admin=login,comment,createWeblog,admin
 
+# True to give the first user that is registered admin privileges
+users.firstUserAdmin=true
+
 # Enable scheme enforcement?
 # Scheme enforcement ensures that specific URLs are viewed only via HTTPS
 schemeenforcement.enabled=false

Modified: roller/branches/roller_4.1_dev/apps/weblogger/test/java/org/apache/roller/weblogger/business/UserTest.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_4.1_dev/apps/weblogger/test/java/org/apache/roller/weblogger/business/UserTest.java?rev=581941&r1=581940&r2=581941&view=diff
==============================================================================
--- roller/branches/roller_4.1_dev/apps/weblogger/test/java/org/apache/roller/weblogger/business/UserTest.java
(original)
+++ roller/branches/roller_4.1_dev/apps/weblogger/test/java/org/apache/roller/weblogger/business/UserTest.java
Thu Oct  4 08:01:54 2007
@@ -29,6 +29,7 @@
 import org.apache.roller.weblogger.TestUtils;
 import org.apache.roller.weblogger.business.WebloggerFactory;
 import org.apache.roller.weblogger.business.UserManager;
+import org.apache.roller.weblogger.config.WebloggerConfig;
 import org.apache.roller.weblogger.pojos.User;
 
 
@@ -183,15 +184,21 @@
         User testUser = TestUtils.setupUser("roleTestUser");
         TestUtils.endSession(true);
         
-        // verify user has 2 roles, admin & editor
         user = mgr.getUserByUserName(testUser.getUserName());
         assertNotNull(user);
-        assertEquals(2, mgr.getRoles(user).size());
-        assertTrue(mgr.hasRole("editor", user));
-        assertTrue(mgr.hasRole("admin", user));
+        
+        if (WebloggerConfig.getBooleanProperty("users.firstUserAdmin")) {
+            assertEquals(2, mgr.getRoles(user).size());
+            assertTrue(mgr.hasRole("editor", user));
+            assertTrue(mgr.hasRole("admin", user));
+        } else {
+            assertEquals(1, mgr.getRoles(user).size());
+            assertTrue(mgr.hasRole("editor", user));
+            assertFalse(mgr.hasRole("admin", user));
+        }
         
         // remove role
-        mgr.revokeRole("admin",user);
+        mgr.revokeRole("editor",user);
         mgr.saveUser(user);
         TestUtils.endSession(true);
         
@@ -199,12 +206,17 @@
         user = null;
         user = mgr.getUserByUserName(testUser.getUserName());
         assertNotNull(user);
-        assertEquals(1, mgr.getRoles(user).size());
-        assertTrue(mgr.hasRole("editor", user));
-        assertFalse(mgr.hasRole("admin", user));
-        
+        if (WebloggerConfig.getBooleanProperty("users.firstUserAdmin")) {
+            assertEquals(1, mgr.getRoles(user).size());
+            assertFalse(mgr.hasRole("editor", user));
+            assertTrue(mgr.hasRole("admin", user));
+        } else {
+            assertEquals(0, mgr.getRoles(user).size());
+            assertFalse(mgr.hasRole("editor", user));
+            assertFalse(mgr.hasRole("admin", user));
+        }
         // add role
-        mgr.grantRole("admin", user);
+        mgr.grantRole("editor", user);
         mgr.saveUser(user);
         TestUtils.endSession(true);
         
@@ -212,10 +224,15 @@
         user = null;
         user = mgr.getUserByUserName(testUser.getUserName());
         assertNotNull(user);
-        assertEquals(2, mgr.getRoles(user).size());
-        assertTrue(mgr.hasRole("editor", user));
-        assertTrue(mgr.hasRole("admin", user));
-        
+        if (WebloggerConfig.getBooleanProperty("users.firstUserAdmin")) {
+            assertEquals(2, mgr.getRoles(user).size());
+            assertTrue(mgr.hasRole("editor", user));
+            assertTrue(mgr.hasRole("admin", user));
+        } else {
+            assertEquals(1, mgr.getRoles(user).size());
+            assertTrue(mgr.hasRole("editor", user));
+            assertFalse(mgr.hasRole("admin", user));
+        }
         // remove test user
         TestUtils.teardownUser(testUser.getUserName());
         TestUtils.endSession(true);



Mime
View raw message