From: Alexander Ebert Date: Thu, 11 Apr 2019 11:12:42 +0000 (+0200) Subject: Promote a group to be the owner group X-Git-Tag: 5.2.0_Alpha_1~136^2~8 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=46fb6cfd6fd280596b5ca6740fcab53459525570;p=GitHub%2FWoltLab%2FWCF.git Promote a group to be the owner group We cannot reliably determine the owner group during the upgrade, therefore it is up to an administrator to make the choice. The notice is designed to be annoying and is present on all pages, however it does not prevent the user from carrying out tasks, e. g. setting up a proper group before promoting it to be the owner group. --- diff --git a/wcfsetup/install/files/acp/style/layout.scss b/wcfsetup/install/files/acp/style/layout.scss index 4244f7f7d4..81b75e6a8d 100644 --- a/wcfsetup/install/files/acp/style/layout.scss +++ b/wcfsetup/install/files/acp/style/layout.scss @@ -441,3 +441,26 @@ $wcfAcpSubMenuWidth: 300px; width: 100% !important; } } + +/* Owner Group */ +#wscMissingOwnerGroup { + background-color: rgb(248, 215, 218); + border-top: 5px solid red; + bottom: 0; + color: rgb(114, 28, 36); + left: 0; + padding: 10px; + position: fixed; + text-align: center; + right: 0; + z-index: 9999; + + @include screen-md-up { + padding: 20px; + } + + > a { + color: inherit; + text-decoration: underline; + } +} diff --git a/wcfsetup/install/files/acp/templates/footer.tpl b/wcfsetup/install/files/acp/templates/footer.tpl index da3b6ece2c..b348d669dc 100644 --- a/wcfsetup/install/files/acp/templates/footer.tpl +++ b/wcfsetup/install/files/acp/templates/footer.tpl @@ -8,6 +8,10 @@ {if $__isRescueMode|empty}{include file='pageMenuMobile'}{/if} +{if !$__wscMissingOwnerGroup|empty} + +{/if} + {event name='footer'} diff --git a/wcfsetup/install/files/acp/templates/userGroupPromoteOwner.tpl b/wcfsetup/install/files/acp/templates/userGroupPromoteOwner.tpl new file mode 100644 index 0000000000..a1eebfba78 --- /dev/null +++ b/wcfsetup/install/files/acp/templates/userGroupPromoteOwner.tpl @@ -0,0 +1,13 @@ +{include file='header' pageTitle='wcf.acp.group.promoteOwner'} + +
+
+

{lang}wcf.acp.group.promoteOwner{/lang}

+
+
+ +
{lang}wcf.acp.group.promoteOwner.warning{/lang}
+ +{@$form->getHtml()} + +{include file='footer'} diff --git a/wcfsetup/install/files/lib/acp/form/UserGroupEditForm.class.php b/wcfsetup/install/files/lib/acp/form/UserGroupEditForm.class.php index d3cdf40c2f..d0bb4e032e 100755 --- a/wcfsetup/install/files/lib/acp/form/UserGroupEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserGroupEditForm.class.php @@ -122,8 +122,6 @@ class UserGroupEditForm extends UserGroupAddForm { $ownerGroupPermissions[] = 'admin.user.accessibleGroups'; } - $ownerGroup = UserGroup::getGroupByType(UserGroup::OWNER); - WCF::getTPL()->assign([ 'groupID' => $this->group->groupID, 'group' => $this->group, @@ -135,7 +133,7 @@ class UserGroupEditForm extends UserGroupAddForm { 'groupIsOwner' => $this->group->isOwner(), 'isUnmentionableGroup' => $this->isUnmentionableGroup ? 1 : 0, 'ownerGroupPermissions' => $ownerGroupPermissions, - 'ownerGroupID' => $ownerGroup ? $ownerGroup->groupID : null, + 'ownerGroupID' => UserGroup::getOwnerGroupID(), ]); // add warning when the initiator is in the group diff --git a/wcfsetup/install/files/lib/acp/form/UserGroupPromoteOwnerForm.class.php b/wcfsetup/install/files/lib/acp/form/UserGroupPromoteOwnerForm.class.php new file mode 100644 index 0000000000..ddbd167769 --- /dev/null +++ b/wcfsetup/install/files/lib/acp/form/UserGroupPromoteOwnerForm.class.php @@ -0,0 +1,119 @@ + + * @package WoltLabSuite\Core\Acp\Form + * @since 5.2 + */ +class UserGroupPromoteOwnerForm extends AbstractForm { + /** + * @inheritDoc + */ + public $activeMenuItem = 'wcf.acp.menu.link.group.list'; + + /** + * @var IFormDocument + */ + public $form; + + /** + * @var UserGroup + */ + public $groups = []; + + /** + * @inheritDoc + */ + public $neededPermissions = ['admin.configuration.package.canInstallPackage']; + + /** + * @inheritDoc + */ + public function readParameters() { + parent::readParameters(); + + $this->groups = UserGroup::getGroupsByType([UserGroup::OTHER]); + $this->groups = array_filter($this->groups, function (UserGroup $group) { + return $group->isAdminGroup(); + }); + uasort($this->groups, function(UserGroup $a, UserGroup $b) { + return $a->getName() <=> $b->getName(); + }); + + $this->form = FormDocument::create('promoteGroup') + ->appendChild( + FormContainer::create('groupSection') + ->appendChild( + RadioButtonFormField::create('groupID') + ->label('wcf.acp.group.promoteOwner.group') + ->required() + ->options($this->groups) + ) + ); + $this->form->action(LinkHandler::getInstance()->getLink('UserGroupPromoteOwner')); + $this->form->build(); + } + + /** + * @inheritDoc + */ + public function readFormParameters() { + parent::readFormParameters(); + + $this->form->readValues(); + } + + /** + * @inheritDoc + */ + public function validate() { + parent::validate(); + + $this->form->validate(); + } + + /** + * @inheritDoc + */ + public function save() { + parent::save(); + + $groupID = $this->form->getData()['data']['groupID']; + + $this->objectAction = new UserGroupAction([$this->groups[$groupID]], 'promoteOwner'); + $this->objectAction->executeAction(); + + $this->saved(); + + HeaderUtil::redirect(LinkHandler::getInstance()->getLink()); + exit; + } + + /** + * @inheritDoc + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign([ + 'form' => $this->form, + // Hide the notice on this page only. + '__wscMissingOwnerGroup' => false, + ]); + } +} diff --git a/wcfsetup/install/files/lib/data/user/group/UserGroupAction.class.php b/wcfsetup/install/files/lib/data/user/group/UserGroupAction.class.php index 3de57bf699..62e3614e06 100644 --- a/wcfsetup/install/files/lib/data/user/group/UserGroupAction.class.php +++ b/wcfsetup/install/files/lib/data/user/group/UserGroupAction.class.php @@ -212,4 +212,20 @@ class UserGroupAction extends AbstractDatabaseObjectAction { ]) ]; } + + public function promoteOwner() { + if (UserGroup::getOwnerGroupID() !== null) { + throw new \LogicException('There is already an owner group.'); + } + else if (count($this->objects) !== 1) { + throw new \InvalidArgumentException('Only a single group can be promoted to be the owner group.'); + } + + $groupEditor = reset($this->objects); + $groupEditor->update([ + 'groupType' => UserGroup::OWNER, + ]); + + UserGroupEditor::resetCache(); + } } diff --git a/wcfsetup/install/files/lib/system/WCFACP.class.php b/wcfsetup/install/files/lib/system/WCFACP.class.php index efc5c42559..accd8f1810 100644 --- a/wcfsetup/install/files/lib/system/WCFACP.class.php +++ b/wcfsetup/install/files/lib/system/WCFACP.class.php @@ -4,6 +4,7 @@ use wcf\acp\form\MasterPasswordForm; use wcf\acp\form\MasterPasswordInitForm; use wcf\data\menu\Menu; use wcf\data\menu\MenuCache; +use wcf\data\user\group\UserGroup; use wcf\system\application\ApplicationHandler; use wcf\system\cache\builder\ACPSearchProviderCacheBuilder; use wcf\system\event\EventHandler; @@ -176,6 +177,10 @@ class WCFACP extends WCF { self::$overrideDebugMode = true; } } + + if (PACKAGE_ID && WCF::getUser()->userID && WCF::getSession()->getPermission('admin.configuration.package.canInstallPackage') && UserGroup::getOwnerGroupID() === null) { + self::getTPL()->assign(['__wscMissingOwnerGroup' => true]); + } } /** diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index c144dadd23..90a61965fe 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -883,6 +883,10 @@ Das Fehlerprotokoll enthält {$data[count]} neue Einträge. Die ersten drei, in + bitte {if LANGUAGE_USE_INFORMAL_VARIANT}lege{else}legen Sie{/if} diese umgehend fest.]]> + + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 2e154db23a..b4c53fcc58 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -860,6 +860,11 @@ This protocol file contains {$data[count]} new entries. The first three error me + + please set it up now.]]> + + +