]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Fix for ticket #2845: singleuser nickname configuration was being overridden by site...
authorBrion Vibber <brion@pobox.com>
Wed, 20 Oct 2010 21:34:25 +0000 (14:34 -0700)
committerBrion Vibber <brion@pobox.com>
Wed, 20 Oct 2010 21:34:25 +0000 (14:34 -0700)
I've consolidated the checks for which user to use for single-user mode into User::singleUser(), which now uses the configured nickname by preference, falling back to the site owner if it's unset.
This is now called consistently from the places that needed to use the primary user's nickname in routing setup.

Setting $config['singleuser']['nickname'] should now work again as expected.

README
classes/User.php
lib/action.php
lib/router.php
lib/util.php

diff --git a/README b/README
index 26a9fe4ecb69500225954fd71229274cede831ae..43a9bb5e959d683230b07a3cd54afe72c8b1e572 100644 (file)
--- a/README
+++ b/README
@@ -1486,7 +1486,8 @@ If an installation has only one user, this can simplify a lot of the
 interface. It also makes the user's profile the root URL.
 
 enabled: Whether to run in "single user mode". Default false.
-nickname: nickname of the single user.
+nickname: nickname of the single user. If no nickname is specified,
+          the site owner account will be used (if present).
 
 robotstxt
 ---------
index e784fd9e9a7278ec8c49955bcdeb5ad94588facc..c68be223de29d599eff219f0ce37c58373ce794f 100644 (file)
@@ -875,4 +875,33 @@ class User extends Memcached_DataObject
 
         return $owner;
     }
+
+    /**
+     * Pull the primary site account to use in single-user mode.
+     * If a valid user nickname is listed in 'singleuser':'nickname'
+     * in the config, this will be used; otherwise the site owner
+     * account is taken by default.
+     *
+     * @return User
+     * @throws ServerException if no valid single user account is present
+     * @throws ServerException if called when not in single-user mode
+     */
+    static function singleUser()
+    {
+        if (common_config('singleuser', 'enabled')) {
+            $nickname = common_config('singleuser', 'nickname');
+            if ($nickname) {
+                $user = User::staticGet('nickname', $nickname);
+            } else {
+                $user = User::siteOwner();
+            }
+            if ($user) {
+                return $user;
+            } else {
+                throw new ServerException(_("No single user defined for single-user mode."));
+            }
+        } else {
+            throw new ServerException(_('Single-user mode code called when not enabled.'));
+        }
+    }
 }
index 55ee83bde6d5bc9d32ed89a76e80e773f094b083..e273b5d04013552745801d7b3a16b296b5424eec 100644 (file)
@@ -419,8 +419,9 @@ class Action extends HTMLOutputter // lawsuit
                                              'class' => 'vcard'));
         if (Event::handle('StartAddressData', array($this))) {
             if (common_config('singleuser', 'enabled')) {
+                $user = User::singleUser();
                 $url = common_local_url('showstream',
-                                        array('nickname' => common_config('singleuser', 'nickname')));
+                                        array('nickname' => $user->nickname));
             } else {
                 $url = common_local_url('public');
             }
index b1cc8d52941347bec09400c38c7affdba68a1ed2..8c682cefa905deaf4ec79d6d608d0000d17bc718 100644 (file)
@@ -701,16 +701,8 @@ class Router
 
             if (common_config('singleuser', 'enabled')) {
 
-                $user = User::siteOwner();
-
-                if (!empty($user)) {
-                    $nickname = $user->nickname;
-                } else {
-                    $nickname = common_config('singleuser', 'nickname');
-                    if (empty($nickname)) {
-                        throw new ServerException(_("No single user defined for single-user mode."));
-                    }
-                }
+                $user = User::singleUser();
+                $nickname = $user->nickname;
 
                 foreach (array('subscriptions', 'subscribers',
                                'all', 'foaf', 'xrds',
index 5a94182bda6d8fd48214636d34cae7845bf3835f..86380af281712ae77c1208cc0d4b3639e75985d3 100644 (file)
@@ -974,8 +974,9 @@ function common_tag_link($tag)
     $canonical = common_canonical_tag($tag);
     if (common_config('singleuser', 'enabled')) {
         // regular TagAction isn't set up in 1user mode
+        $user = User::singleUser();
         $url = common_local_url('showstream',
-                                array('nickname' => common_config('singleuser', 'nickname'),
+                                array('nickname' => $user->nickname,
                                       'tag' => $canonical));
     } else {
         $url = common_local_url('tag', array('tag' => $canonical));