]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #3165 new admin users all get admin widgets
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 23 Mar 2011 01:55:47 +0000 (01:55 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 23 Mar 2011 01:55:47 +0000 (01:55 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@8823 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/admin.php
engine/lib/users.php
install/ElggInstaller.php

index 71bf8fe124ea5a0095ee87a8d428b90f6f3313cf..876af307bdb8b31d5aaa8fbbc978b1940e0c6bc6 100644 (file)
@@ -278,6 +278,9 @@ function admin_init() {
                );
        }
 
+       // automatic adding of widgets for admin
+       elgg_register_event_handler('make_admin', 'user', 'elgg_add_admin_widgets');
+
        elgg_register_page_handler('admin', 'admin_settings_page_handler');
        elgg_register_page_handler('admin_plugin_screenshot', 'admin_plugin_screenshot_page_handler');
 }
@@ -459,5 +462,34 @@ function admin_plugin_screenshot_page_handler($pages) {
        return true;
 }
 
+/**
+ * Adds default admin widgets to the admin dashboard.
+ */
+function elgg_add_admin_widgets($event, $type, $user) {
+       elgg_set_ignore_access(true);
+
+       // check if the user already has widgets
+       if (elgg_get_widgets($user->getGUID(), 'admin')) {
+               return true;
+       }
+
+       // In the form column => array of handlers in order, top to bottom
+       $adminWidgets = array(
+               1 => array('online_users', 'new_users', 'content_stats'),
+               2 => array('admin_welcome'),
+       );
+       
+       foreach ($adminWidgets as $column => $handlers) {
+               foreach ($handlers as $position => $handler) {
+                       $guid = elgg_create_widget($user->getGUID(), $handler, 'admin');
+                       if ($guid) {
+                               $widget = get_entity($guid);
+                               $widget->move($column, $position);
+                       }
+               }
+       }
+       elgg_set_ignore_access(false);
+}
+
 elgg_register_event_handler('init', 'system', 'admin_init');
 elgg_register_event_handler('pagesetup', 'system', 'admin_pagesetup', 1000);
index 55bacdcb2a3a15d6429c8dd0d416008bb3db5d82..6733c9d3ec0576fec53fae6be1da2af5097b2c11 100644 (file)
@@ -1001,22 +1001,6 @@ $allow_multiple_emails = false, $friend_guid = 0, $invitecode = '') {
                }
        }
 
-       // Check to see if we've registered the first admin yet.
-       // If not, this is the first admin user!
-       $have_admin = datalist_get('admin_registered');
-
-       if (!$have_admin) {
-               // makeAdmin() calls ElggUser::canEdit().
-               // right now no one is logged in and so canEdit() returns false.
-               // instead of making an override for this one instance that is called on every
-               // canEdit() call, just override the access system to set the first admin user.
-               // @todo remove this when Cash merges in the new installer
-               $ia = elgg_set_ignore_access(TRUE);
-               $user->makeAdmin();
-               datalist_set('admin_registered', 1);
-               elgg_set_ignore_access($ia);
-       }
-
        // Turn on email notifications by default
        set_user_notification_setting($user->getGUID(), 'email', true);
 
index a62ba2bc42911fd0b1ef41b1d70c1a4e0818450a..6e946f0d03c610e03c4d81f6ae8af3b33a0046ca 100644 (file)
@@ -28,16 +28,6 @@ class ElggInstaller {
 
        protected $autoLogin = TRUE;
 
-       /**
-        * @var array An array of widgets to add to the admin dashboard.
-        *
-        * In the form column => array of handlers in order, top to bottom
-        */
-       protected $adminWidgets = array(
-               1 => array('online_users', 'new_users', 'content_stats'),
-               2 => array('admin_welcome'),
-       );
-
        /**
         * Constructor bootstraps the Elgg engine
         */
@@ -178,8 +168,6 @@ class ElggInstaller {
                if (!$this->createAdminAccount($params)) {
                        throw new InstallationException(elgg_echo('install:admin:cannot_create'));
                }
-
-               $this->addAdminWidgets();
        }
 
        /**
@@ -496,7 +484,6 @@ class ElggInstaller {
         * @return void
         */
        protected function complete() {
-               $this->addAdminWidgets();
 
                $params = array();
                if ($this->autoLogin) {
@@ -746,7 +733,8 @@ class ElggInstaller {
                                'private_settings.php', 'relationships.php', 'river.php',
                                'sites.php', 'statistics.php', 'tags.php', 'user_settings.php',
                                'users.php', 'version.php', 'web_services.php',
-                               'widgets.php', 'xml.php', 'xml-rpc.php'
+                               'widgets.php', 'xml.php', 'xml-rpc.php', 'deprecated-1.7.php',
+                               'deprecated-1.8.php',
                        );
 
                        foreach ($lib_files as $file) {
@@ -1364,39 +1352,6 @@ class ElggInstaller {
                }
        }
 
-       /**
-        * Adds default admin widgets to the admin dashboard.
-        *
-        * @return bool
-        */
-       protected function addAdminWidgets() {
-               elgg_set_ignore_access(true);
-               // should only be one.
-               $users = elgg_get_entities(array(
-                       'type' => 'user',
-                       'limit' => 1,
-               ));
-
-               if ($users) {
-                       if ($users[0]->isAdmin()) {
-                               $admin = $users[0];
-                       }
-               } else {
-                       return false;
-               }
-
-               foreach ($this->adminWidgets as $column => $handlers) {
-                       foreach ($handlers as $position => $handler) {
-                               $guid = elgg_create_widget($admin->getGUID(), $handler, 'admin');
-                               if ($guid) {
-                                       $widget = get_entity($guid);
-                                       $widget->move($column, $position);
-                               }
-                       }
-               }
-               elgg_set_ignore_access(false);
-       }
-
        /**
         * Admin account support methods
         */
@@ -1477,6 +1432,8 @@ class ElggInstaller {
                elgg_set_ignore_access(TRUE);
                if ($user->makeAdmin() == FALSE) {
                        register_error(elgg_echo('install:error:adminaccess'));
+               } else {
+                       datalist_set('admin_registered', 1);
                }
                elgg_set_ignore_access(FALSE);