This is an automated email from the ASF dual-hosted git repository.

snoopdave pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/roller.git


The following commit(s) were added to refs/heads/master by this push:
     new 58ec8978e Let only global admins manage Admin on the aggregated 
front-page weblog (#383)
58ec8978e is described below

commit 58ec8978e1b2c213bd14558cbf7ed9186db3eacf
Author: David M. Johnson <[email protected]>
AuthorDate: Tue Nov 24 17:34:42 2026 -0500

    Let only global admins manage Admin on the aggregated front-page weblog 
(#383)
    
    With aggregation on, the front-page weblog's templates read across the
    whole site, so its Admins are trusted like global admins. A weblog Admin
    could still promote members or invite new Admins there. Granting, removing
    or inviting Admin on that weblog now needs a global admin.
---
 CHANGES.md                                         |   6 +
 .../weblogger/ui/struts2/editor/Members.java       |  12 ++
 .../weblogger/ui/struts2/editor/MembersInvite.java |   4 +
 .../roller/weblogger/ui/struts2/util/UIAction.java |  12 ++
 .../main/resources/ApplicationResources.properties |   1 +
 .../editor/FrontPageAdminMembershipTest.java       | 224 +++++++++++++++++++++
 6 files changed, 259 insertions(+)

diff --git a/CHANGES.md b/CHANGES.md
index 576aec502..e57fe0437 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -185,6 +185,12 @@
   a weblog reached through `$site`, now returns null for draft, pending and
   scheduled entries.
 
+- **Only global admins manage Admin on the aggregated front-page weblog.**
+  With `site.frontpage.weblog.aggregated=true`, that weblog's templates can
+  read the whole site, so granting, removing or inviting an Admin there now
+  needs a global admin. Before turning aggregation on, review who is Admin
+  on the front-page weblog.
+
 - **Weblog templates have render limits.** A page stops rendering, with a
   logged error, once it writes more than `rendering.maxOutputChars` (10 MB),
   inserts a longer string, or runs longer than `rendering.maxRenderSeconds`
diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Members.java 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Members.java
index 9f692687b..989420439 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Members.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Members.java
@@ -119,6 +119,18 @@ public class Members extends UIAction implements 
ParametersAware {
                 addError("memberPermissions.oneAdminRequired");
                 error = true;
             }
+            if (!error && isAdminMembershipLocked()) {
+                for (WeblogPermission perms : permsList) {
+                    String sval = getParameter("perm-" + 
perms.getUser().getId());
+                    if (sval != null && !perms.hasAction(sval)
+                            && (perms.hasAction(WeblogPermission.ADMIN)
+                                || Utilities.stringToStringList(sval, 
",").contains(WeblogPermission.ADMIN))) {
+                        
addError("memberPermissions.frontPageAdminsGlobalOnly");
+                        error = true;
+                        break;
+                    }
+                }
+            }
             // one iteration for each line (user) in the members table
             for (WeblogPermission perms : permsList) {
 
diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MembersInvite.java
 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MembersInvite.java
index 7bd6fe24a..b666f928e 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MembersInvite.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MembersInvite.java
@@ -100,6 +100,10 @@ public class MembersInvite extends UIAction {
             addError("Error looking up invitee");
         }
         
+        if (WeblogPermission.ADMIN.equals(getPermissionString()) && 
isAdminMembershipLocked()) {
+            addError("memberPermissions.frontPageAdminsGlobalOnly");
+        }
+
         // if we already have an error then bail now
         if(hasActionErrors()) {
             return INPUT;
diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIAction.java 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIAction.java
index 9ac3d4272..ee0cea2ce 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIAction.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIAction.java
@@ -158,6 +158,18 @@ public abstract class UIAction extends ActionSupport
         return false;
     }
 
+    /**
+     * Whether Admin membership of the action weblog is closed to this user.
+     * On the aggregated front-page weblog, whose templates read the whole
+     * site, only global admins may grant, change or remove Admin.
+     */
+    protected boolean isAdminMembershipLocked() {
+        Weblog weblog = getActionWeblog();
+        return weblog != null
+                && WebloggerRuntimeConfig.isSiteWideWeblog(weblog.getHandle())
+                && !isUserIsAdmin();
+    }
+
     /**
      * Cancel.
      *
diff --git a/app/src/main/resources/ApplicationResources.properties 
b/app/src/main/resources/ApplicationResources.properties
index 574e03c6f..f13f12715 100644
--- a/app/src/main/resources/ApplicationResources.properties
+++ b/app/src/main/resources/ApplicationResources.properties
@@ -1029,6 +1029,7 @@ memberPermissions.remove=Remove
 
 memberPermissions.noSelfModifications=Only another admin may alter your role.
 memberPermissions.oneAdminRequired=Blog must have at least one admin.
+memberPermissions.frontPageAdminsGlobalOnly=Only a global admin can grant, 
change or remove Admin on the aggregated front-page weblog.
 memberPermissions.membersRemoved=Removed {0} user(s)
 memberPermissions.membersChanged=Changed permission for {0} user(s)
 
diff --git 
a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/editor/FrontPageAdminMembershipTest.java
 
b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/editor/FrontPageAdminMembershipTest.java
new file mode 100644
index 000000000..5850bafab
--- /dev/null
+++ 
b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/editor/FrontPageAdminMembershipTest.java
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.roller.weblogger.ui.struts2.editor;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.roller.weblogger.TestUtils;
+import org.apache.roller.weblogger.business.PropertiesManager;
+import org.apache.roller.weblogger.business.UserManager;
+import org.apache.roller.weblogger.business.WebloggerFactory;
+import org.apache.roller.weblogger.pojos.RuntimeConfigProperty;
+import org.apache.roller.weblogger.pojos.User;
+import org.apache.roller.weblogger.pojos.Weblog;
+import org.apache.roller.weblogger.pojos.WeblogPermission;
+import org.apache.roller.weblogger.ui.struts2.util.UIAction;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.spy;
+
+/**
+ * The aggregated front-page weblog's templates read the whole site, so only
+ * global admins decide who is Admin there.
+ */
+class FrontPageAdminMembershipTest {
+
+    private static final String LOCKED = 
"memberPermissions.frontPageAdminsGlobalOnly";
+
+    private String ownerName;
+    private String memberName;
+    private String weblogId;
+    private String handle;
+    private String savedHandle;
+    private String savedAggregated;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        TestUtils.setupWeblogger();
+        User owner = TestUtils.setupUser("frontpageowner");
+        User member = TestUtils.setupUser("frontpagemember");
+        ownerName = owner.getUserName();
+        memberName = member.getUserName();
+        Weblog weblog = TestUtils.setupWeblog("frontpageadmins", owner);
+        weblogId = weblog.getId();
+        handle = weblog.getHandle();
+        users().grantWeblogPermission(weblog, member, 
List.of(WeblogPermission.POST));
+        // the weblog's Admin is not a global admin
+        if (users().hasRole("admin", owner)) {
+            users().revokeRole("admin", owner);
+        }
+        TestUtils.endSession(true);
+        savedHandle = setProperty("site.frontpage.weblog.handle", handle);
+        savedAggregated = setProperty("site.frontpage.weblog.aggregated", 
"true");
+    }
+
+    @AfterEach
+    void tearDown() throws Exception {
+        setProperty("site.frontpage.weblog.handle", savedHandle);
+        setProperty("site.frontpage.weblog.aggregated", savedAggregated);
+        TestUtils.teardownWeblog(weblogId);
+        TestUtils.teardownUser(ownerName);
+        TestUtils.teardownUser(memberName);
+        TestUtils.endSession(true);
+    }
+
+    @Test
+    void weblogAdminCannotPromoteAMember() throws Exception {
+        Members action = membersSaving(Map.of(
+                ownerName, WeblogPermission.ADMIN,
+                memberName, WeblogPermission.ADMIN));
+        assertEquals(List.of(LOCKED), List.copyOf(action.getActionErrors()));
+        assertEquals(List.of(WeblogPermission.POST), 
permission(memberName).getActionsAsList());
+    }
+
+    @Test
+    void weblogAdminCannotRemoveAnotherAdmin() throws Exception {
+        users().grantWeblogPermission(weblog(), user(memberName), 
List.of(WeblogPermission.ADMIN));
+        TestUtils.endSession(true);
+        Members action = membersSaving(Map.of(
+                ownerName, WeblogPermission.ADMIN,
+                memberName, "-1"));
+        assertEquals(List.of(LOCKED), List.copyOf(action.getActionErrors()));
+        assertTrue(permission(memberName).hasAction(WeblogPermission.ADMIN));
+    }
+
+    @Test
+    void weblogAdminCanStillChangeOtherRoles() throws Exception {
+        Members action = membersSaving(Map.of(
+                ownerName, WeblogPermission.ADMIN,
+                memberName, WeblogPermission.EDIT_DRAFT));
+        assertFalse(action.hasActionErrors(), () -> 
action.getActionErrors().toString());
+        assertEquals(List.of(WeblogPermission.EDIT_DRAFT), 
permission(memberName).getActionsAsList());
+    }
+
+    @Test
+    void globalAdminCanPromoteAMember() throws Exception {
+        users().grantRole("admin", user(ownerName));
+        TestUtils.endSession(true);
+        Members action = membersSaving(Map.of(
+                ownerName, WeblogPermission.ADMIN,
+                memberName, WeblogPermission.ADMIN));
+        assertFalse(action.hasActionErrors(), () -> 
action.getActionErrors().toString());
+        assertTrue(permission(memberName).hasAction(WeblogPermission.ADMIN));
+    }
+
+    @Test
+    void withoutAggregationTheWeblogAdminCanPromote() throws Exception {
+        setProperty("site.frontpage.weblog.aggregated", "false");
+        Members action = membersSaving(Map.of(
+                ownerName, WeblogPermission.ADMIN,
+                memberName, WeblogPermission.ADMIN));
+        assertFalse(action.hasActionErrors(), () -> 
action.getActionErrors().toString());
+        assertTrue(permission(memberName).hasAction(WeblogPermission.ADMIN));
+    }
+
+    @Test
+    void weblogAdminCannotInviteAnAdmin() throws Exception {
+        User invitee = TestUtils.setupUser("frontpageinvitee");
+        TestUtils.endSession(true);
+        try {
+            MembersInvite action = inviting(invitee.getUserName(), 
WeblogPermission.ADMIN);
+            assertEquals(List.of(LOCKED), 
List.copyOf(action.getActionErrors()));
+            assertNull(permission(invitee.getUserName()));
+
+            MembersInvite author = inviting(invitee.getUserName(), 
WeblogPermission.POST);
+            assertFalse(author.hasActionErrors(), () -> 
author.getActionErrors().toString());
+        } finally {
+            // remove the invitation first, so no permission is left without 
its user
+            if (permission(invitee.getUserName()) != null) {
+                users().revokeWeblogPermission(weblog(), 
user(invitee.getUserName()),
+                        WeblogPermission.ALL_ACTIONS);
+                TestUtils.endSession(true);
+            }
+            TestUtils.teardownUser(invitee.getUserName());
+            TestUtils.endSession(true);
+        }
+    }
+
+    private MembersInvite inviting(String name, String permission) throws 
Exception {
+        MembersInvite action = spy(new MembersInvite());
+        stubText(action);
+        action.setAuthenticatedUser(user(ownerName));
+        action.setActionWeblog(weblog());
+        action.setUserName(name);
+        action.setPermissionString(permission);
+        action.save();
+        TestUtils.endSession(true);
+        return action;
+    }
+
+    private Members membersSaving(Map<String, String> choices) throws 
Exception {
+        Members action = spy(new Members());
+        stubText(action);
+        action.setAuthenticatedUser(user(ownerName));
+        action.setActionWeblog(weblog());
+        doAnswer(call -> null).when(action).getParameter(anyString());
+        for (Map.Entry<String, String> choice : choices.entrySet()) {
+            doAnswer(call -> choice.getValue()).when(action)
+                    .getParameter("perm-" + user(choice.getKey()).getId());
+        }
+        action.save();
+        TestUtils.endSession(true);
+        return action;
+    }
+
+    private static String setProperty(String name, String value) throws 
Exception {
+        PropertiesManager mgr = 
WebloggerFactory.getWeblogger().getPropertiesManager();
+        RuntimeConfigProperty prop = mgr.getProperty(name);
+        String old = prop.getValue();
+        prop.setValue(value);
+        mgr.saveProperty(prop);
+        TestUtils.endSession(true);
+        return old;
+    }
+
+    private static void stubText(UIAction action) {
+        doAnswer(call -> 
call.getArgument(0)).when(action).getText(anyString());
+        doAnswer(call -> 
call.getArgument(0)).when(action).getText(anyString(), anyString());
+        doAnswer(call -> 
call.getArgument(0)).when(action).getText(anyString(), anyList());
+        doAnswer(call -> call.getArgument(0)).when(action)
+                .getText(anyString(), anyString(), anyString());
+    }
+
+    private WeblogPermission permission(String name) throws Exception {
+        return users().getWeblogPermissionIncludingPending(weblog(), 
user(name));
+    }
+
+    private static UserManager users() {
+        return WebloggerFactory.getWeblogger().getUserManager();
+    }
+
+    private Weblog weblog() throws Exception {
+        return 
WebloggerFactory.getWeblogger().getWeblogManager().getWeblog(weblogId);
+    }
+
+    private static User user(String name) throws Exception {
+        return users().getUserByUserName(name, null);
+    }
+}

Reply via email to