Added feature #13170: Workspace Owners should be manageable with groups as well ...
authorBenni Mack <benni.mack@typo3.org>
Sat, 13 Nov 2010 16:36:51 +0000 (16:36 +0000)
committerBenni Mack <benni.mack@typo3.org>
Sat, 13 Nov 2010 16:36:51 +0000 (16:36 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@9366 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_userauthgroup.php
t3lib/stddb/tables.sql
typo3/sysext/install/updates/class.tx_coreupdates_migrateworkspaces.php
typo3/sysext/version/tca.php

index ff9c32b..bd5448d 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-11-13  Benjamin Mack  <benni@typo3.org>
+
+       * Added feature #13170: Workspace Owners should be manageable with groups as well (Thanks to Tolleiv Nietsch)
+
 2010-11-12  Steffen Kamper  <steffen@typo3.org>
 
        * Added feature #16315: New extension manager part 1: splitting classes
index cb54eff..ed093e0 100644 (file)
@@ -1622,9 +1622,15 @@ class t3lib_userAuthGroup extends t3lib_userAuth {
                                        break;
                                        default:
                                                        // Checking if the guy is admin:
-                                               if (t3lib_div::inList($wsRec['adminusers'],$this->user['uid'])) {
+                                               if (t3lib_div::inList($wsRec['adminusers'], 'be_users_' . $this->user['uid'])) {
                                                        return array_merge($wsRec, array('_ACCESS' => 'owner'));
                                                }
+                                                       // Checking if he is owner through a user group of his:
+                                               foreach ($this->userGroupsUID as $groupUid) {
+                                                       if (t3lib_div::inList($wsRec['adminusers'], 'be_groups_' . $groupUid)) {
+                                                               return array_merge($wsRec, array('_ACCESS' => 'owner'));
+                                                       }
+                                               }
                                                        // Checking if he is reviewer user:
                                                if (t3lib_div::inList($wsRec['reviewers'],'be_users_'.$this->user['uid']))      {
                                                        return array_merge($wsRec, array('_ACCESS' => 'reviewer'));
@@ -1872,4 +1878,4 @@ if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_userauthgroup.php']);
 }
 
-?>
\ No newline at end of file
+?>
index 2226032..f538a67 100644 (file)
@@ -309,7 +309,7 @@ CREATE TABLE sys_workspace (
   deleted tinyint(1) DEFAULT '0' NOT NULL,
   title varchar(30) DEFAULT '' NOT NULL,
   description varchar(255) DEFAULT '' NOT NULL,
-  adminusers varchar(255) DEFAULT '' NOT NULL,
+  adminusers text,
   members text,
   reviewers text,
   db_mountpoints varchar(255) DEFAULT '' NOT NULL,
index a3ac9b6..b297c95 100644 (file)
@@ -52,12 +52,20 @@ class tx_coreupdates_migrateworkspaces extends tx_coreupdates_installsysexts {
         */
        public function checkForUpdate(&$description) {
                $result = FALSE;
-               $description = 'Migrates the old hardcoded draft workspace to be a real workspace element';
+               $description = 'Migrates the old hardcoded draft workspace to be a real workspace element and update workspace owner fields  to support either users or groups.';
 
                        // TYPO3 version 4.5 and above
                if ($this->versionNumber >= 4005000) {
-                       $this->includeTCA();
-                       $result = $this->isDraftWorkspaceUsed();
+                       $tables = array_keys($GLOBALS['TYPO3_DB']->admin_get_tables());
+                               // sys_workspace table might not exists if version extension was never installed
+                       if (in_array('sys_workspace', $tables)) {
+                               $result = $this->isOldStyleAdminFieldUsed();
+                       }
+
+                       if (!$result) {
+                               $this->includeTCA();
+                               $result = $this->isDraftWorkspaceUsed();
+                       }
                }
 
                return $result;
@@ -97,6 +105,11 @@ class tx_coreupdates_migrateworkspaces extends tx_coreupdates_installsysexts {
                        // install version extension (especially when updating from very old TYPO3 versions
                $this->installExtensions(array('version'));
 
+                       // migrate all workspaces to support groups and be_users
+               if ($this->isOldStyleAdminFieldUsed()) {
+                       $this->migrateAdminFieldToNewStyle();
+               }
+
                        // create a new dedicated "Draft" workspace and move all records to that new workspace
                if ($this->isDraftWorkspaceUsed()) {
                        $draftWorkspaceId = $this->createWorkspace();
@@ -155,6 +168,17 @@ class tx_coreupdates_migrateworkspaces extends tx_coreupdates_installsysexts {
        }
 
        /**
+        * Check if there's any workspace which doesn't support the new admin-field format yet
+        * @return bool
+        */
+       protected function isOldStyleAdminFieldUsed() {
+               $where = 'adminusers != "" AND adminusers NOT LIKE "%be_users%" AND adminusers NOT LIKE "%be_groups%" AND deleted=0';
+               $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid', 'sys_workspace', $where);
+               $this->sqlQueries[] =  $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
+               return $count > 0;
+       }
+
+       /**
         * Create a real workspace named "Draft"
         *
         * @return integer
@@ -192,6 +216,30 @@ class tx_coreupdates_migrateworkspaces extends tx_coreupdates_installsysexts {
        }
 
        /**
+        * Migrate all workspace adminusers fields to support groups aswell,
+        * this means that the old comma separated list of uids (referring to be_users)
+        * is updated to be a list of uids with the tablename as prefix
+        *
+        * @return void
+        */
+       protected function migrateAdminFieldToNewStyle() {
+               $where = 'adminusers != "" AND adminusers NOT LIKE "%be_users%" AND adminusers NOT LIKE "%be_groups%" AND deleted=0';
+               $workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid, adminusers', 'sys_workspace', $where);
+               $this->sqlQueries[] =  $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
+               foreach ($workspaces as $workspace) {
+                       $updateArray = array(
+                               'adminusers' => 'be_users_' . implode(',be_users_', t3lib_div::trimExplode(',', $workspace['adminusers'], TRUE)),
+                       );
+                       $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
+                               'sys_workspace',
+                               'uid = "' . $workspace['uid'] . '"',
+                               $updateArray
+                       );
+                       $this->sqlQueries[] =  $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
+               }
+       }
+
+       /**
         * Includes the TCA definition of installed extensions.
         *
         * This method is used because usually the TCA is included within the init.php script, this doesn't happen
index 744446a..45eef65 100644 (file)
@@ -27,7 +27,8 @@ $TCA['sys_workspace'] = array(
                        'config' => array(
                                'type' => 'group',
                                'internal_type' => 'db',
-                               'allowed' => 'be_users',
+                               'allowed' => 'be_users,be_groups',
+                               'prepend_tname' => 1,
                                'size' => '3',
                                'maxitems' => '10',
                                'autoSizeMax' => 10,