From bff62615fac8455833dc34bfffec8add2f32dab7 Mon Sep 17 00:00:00 2001 From: Varakh Date: Fri, 6 Apr 2018 12:09:29 +0200 Subject: [PATCH] Add server groups and channel groups create and copy --- README.md | 5 ++- config/ACL.php | 2 ++ config/routes.php | 10 ++++++ data/locale/en.yml | 7 ++++ .../Actions/ChannelGroupCreateAction.php | 30 ++++++++++++++++ src/Control/Actions/GroupsAction.php | 19 ++++++++-- .../Actions/ServerGroupCreateAction.php | 30 ++++++++++++++++ src/Util/TSInstance.php | 13 +++++++ src/View/material/form.twig | 6 ++++ src/View/material/groups.twig | 35 +++++++++++++++++++ 10 files changed, 152 insertions(+), 5 deletions(-) create mode 100644 src/Control/Actions/ChannelGroupCreateAction.php create mode 100644 src/Control/Actions/ServerGroupCreateAction.php diff --git a/README.md b/README.md index fde8772..53edca5 100755 --- a/README.md +++ b/README.md @@ -9,11 +9,10 @@ This webinterface aims to be as simple as possible. It does not provide complex If you like to help (to translate or implement missing features), open an issue before. Then create a pull request. You should use existing code to implement new features. PRs will be merged after a code review. Things you **cannot** do: -- Server Groups create, edit -- Channel Groups create, edit - Channels create -- Permissions add, edit, delete (server, channel, client) +- Permissions add, edit, delete (servergroups, channelgroups, client) - File management (create, download, delete) +- Move online users - features which are not *explicitly* supported Things you **can** do: diff --git a/config/ACL.php b/config/ACL.php index 287d8fe..20098f6 100644 --- a/config/ACL.php +++ b/config/ACL.php @@ -67,12 +67,14 @@ class ACL extends \Zend\Permissions\Acl\Acl '/groups/{sid}', '/servergroups/{sid}/{sgid}', + '/servergroups/create/{sid}', '/servergroups/delete/{sid}/{sgid}', '/servergroups/rename/{sid}/{sgid}', '/servergroups/remove/{sid}/{sgid}/{cldbid}', '/servergroups/add/{sid}/{sgid}', '/channelgroups/{sid}/{cgid}', + '/channelgroups/create/{sid}', '/channelgroups/delete/{sid}/{cgid}', '/channelgroups/rename/{sid}/{cgid}', diff --git a/config/routes.php b/config/routes.php index 5e0fb06..f093e24 100644 --- a/config/routes.php +++ b/config/routes.php @@ -210,6 +210,11 @@ $container[ServerGroupRenameAction::class] = function ($container) { }; $app->post('/servergroups/rename/{sid}/{sgid}', ServerGroupRenameAction::class); +$container[ServerGroupCreateAction::class] = function ($container) { + return new ServerGroupCreateAction($container); +}; +$app->post('/servergroups/create/{sid}', ServerGroupCreateAction::class); + // channel group $container[ChannelGroupInfoAction::class] = function ($container) { @@ -227,6 +232,11 @@ $container[ChannelGroupRenameAction::class] = function ($container) { }; $app->post('/channelgroups/rename/{sid}/{cgid}', ChannelGroupRenameAction::class); +$container[ChannelGroupCreateAction::class] = function ($container) { + return new ChannelGroupCreateAction($container); +}; +$app->post('/channelgroups/create/{sid}', ChannelGroupCreateAction::class); + // ban $container[BansAction::class] = function ($container) { return new BansAction($container); diff --git a/data/locale/en.yml b/data/locale/en.yml index 76e2c67..e03fbbc 100644 --- a/data/locale/en.yml +++ b/data/locale/en.yml @@ -148,6 +148,13 @@ groups.delete: "Delete" groups.h.servergroups: "Server Groups" groups.h.channelgroups: "Channel Groups" +# groups create/copy +groups.create: "Create or copy" +groups.create.name: "Name" +groups.create.type: "Type" +groups.create.copy: "Copy? If checked, select a template." +groups.create.template: "Template" + # channelgroups channelgroups.delete: "Delete" diff --git a/src/Control/Actions/ChannelGroupCreateAction.php b/src/Control/Actions/ChannelGroupCreateAction.php new file mode 100644 index 0000000..b266dff --- /dev/null +++ b/src/Control/Actions/ChannelGroupCreateAction.php @@ -0,0 +1,30 @@ +getParsedBody(); + $type = $body['type']; + $name = $body['name']; + $copy = $body['copy']; + $template = $body['template']; + + $this->logger->debug('Body', $body); + + $this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']); + $selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId'); + + if ($copy) $groupCreateResult = $this->ts->getInstance()->channelGroupAdd($name, $type); + else $groupCreateResult = $this->ts->getInstance()->channelGroupCopy($template, 0, $name, $type); + + $this->flash->addMessage('success', $this->translator->trans('done')); + + return $response->withRedirect('/groups/' . $sid); + } +} \ No newline at end of file diff --git a/src/Control/Actions/GroupsAction.php b/src/Control/Actions/GroupsAction.php index 7fc6d38..0271616 100644 --- a/src/Control/Actions/GroupsAction.php +++ b/src/Control/Actions/GroupsAction.php @@ -13,14 +13,29 @@ final class GroupsAction extends AbstractAction $selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId'); $serverGroupsResult = $this->ts->getInstance()->serverGroupList(); + $serverGroups = $this->ts->getInstance()->getElement('data', $serverGroupsResult); + $serverGroupsTemplate = []; + + foreach ($serverGroups as $serverGroup) { + $serverGroupsTemplate[$serverGroup['name']] = $serverGroup['sgid']; + } $channelGroupsResult = $this->ts->getInstance()->channelGroupList(); + $channelGroups = $this->ts->getInstance()->getElement('data', $channelGroupsResult); + $channelGroupsTemplate = []; + + foreach ($channelGroups as $channelGroup) { + $channelGroupsTemplate[$channelGroup['name']] = $channelGroup['cgid']; + } // render GET $this->view->render($response, 'groups.twig', [ 'title' => $this->translator->trans('groups.title'), - 'serverGroups' => $this->ts->getInstance()->getElement('data', $serverGroupsResult), - 'channelGroups' => $this->ts->getInstance()->getElement('data', $channelGroupsResult), + 'serverGroups' => $serverGroups, + 'serverGroupsTemplate' => $serverGroupsTemplate, + 'channelGroups' => $channelGroups, + 'channelGroupsTemplate' => $channelGroupsTemplate, + 'groupTypes' => TSInstance::getGroupTypes(), 'sid' => $sid ]); } diff --git a/src/Control/Actions/ServerGroupCreateAction.php b/src/Control/Actions/ServerGroupCreateAction.php new file mode 100644 index 0000000..f931d3c --- /dev/null +++ b/src/Control/Actions/ServerGroupCreateAction.php @@ -0,0 +1,30 @@ +getParsedBody(); + $type = $body['type']; + $name = $body['name']; + $copy = $body['copy']; + $template = $body['template']; + + $this->logger->debug('Body', $body); + + $this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']); + $selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId'); + + if ($copy) $groupCreateResult = $this->ts->getInstance()->serverGroupAdd($name, $type); + else $groupCreateResult = $this->ts->getInstance()->serverGroupCopy($template, 0, $name, $type); + + $this->flash->addMessage('success', $this->translator->trans('done')); + + return $response->withRedirect('/groups/' . $sid); + } +} \ No newline at end of file diff --git a/src/Util/TSInstance.php b/src/Util/TSInstance.php index 73ee346..86ea888 100644 --- a/src/Util/TSInstance.php +++ b/src/Util/TSInstance.php @@ -205,4 +205,17 @@ class TSInstance return $arr; } + + /** + * @return array + */ + public static function getGroupTypes() + { + $arr = []; + $arr['RegularGroup'] = 1; + $arr['GlobalQueryGroup'] = 2; + $arr['TemplateGroup'] = 0; + + return $arr; + } } \ No newline at end of file diff --git a/src/View/material/form.twig b/src/View/material/form.twig index 85a7be7..e59ccc7 100644 --- a/src/View/material/form.twig +++ b/src/View/material/form.twig @@ -26,6 +26,12 @@ {% endfor %} + {% elseif field.type == 'checkbox' %} + + + {% else %} {{ title }}

{% trans %}groups.h.servergroups{% endtrans %}

+ + {% include 'form.twig' with { + 'fields': [ + { + 'header_label': 'groups.create'|trans, + 'label': 'check_circle', + 'uri': '/servergroups/create/' ~ sid, + 'uri_method': 'post', + 'fields': [ + {'type': 'text', 'key': 'name', 'label': 'groups.create.name'|trans}, + {'type': 'select', 'key': 'type', 'options': groupTypes, 'label': 'groups.create.type'|trans}, + {'type': 'checkbox', 'key': 'copy', 'label': 'groups.create.copy'|trans}, + {'type': 'select', 'key': 'template', 'options': serverGroupsTemplate, 'label': 'groups.create.template'|trans} + ] + }, + ] + } %} + {% if serverGroups|length > 0 %} {% include 'table.twig' with {'data': serverGroups, 'links': [{'key': 'sgid', 'uri': '/servergroups/' ~ sid}], @@ -33,6 +51,23 @@

{% trans %}groups.h.channelgroups{% endtrans %}

+ {% include 'form.twig' with { + 'fields': [ + { + 'header_label': 'groups.create'|trans, + 'label': 'check_circle', + 'uri': '/channelgroups/create/' ~ sid, + 'uri_method': 'post', + 'fields': [ + {'type': 'text', 'key': 'name', 'label': 'groups.create.name'|trans}, + {'type': 'select', 'key': 'type', 'options': groupTypes, 'label': 'groups.create.type'|trans}, + {'type': 'checkbox', 'key': 'copy', 'label': 'groups.create.copy'|trans}, + {'type': 'select', 'key': 'template', 'options': channelGroupsTemplate, 'label': 'groups.create.template'|trans} + ] + }, + ] + } %} + {% if channelGroups|length > 0 %} {% include 'table.twig' with {'data': channelGroups, 'links': [{'key': 'cgid', 'uri': '/channelgroups/' ~ sid}],