Archived
1
0
Fork 0

Add server groups and channel groups create and copy

This commit is contained in:
Varakh 2018-04-06 12:09:29 +02:00
parent 4cb1aa0056
commit bff62615fa
10 changed files with 152 additions and 5 deletions

View file

@ -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:

View file

@ -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}',

View file

@ -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);

View file

@ -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"

View file

@ -0,0 +1,30 @@
<?php
use Slim\Http\Request;
use Slim\Http\Response;
final class ChannelGroupCreateAction extends AbstractAction
{
public function __invoke(Request $request, Response $response, $args)
{
$sid = $args['sid'];
$body = $request->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);
}
}

View file

@ -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
]);
}

View file

@ -0,0 +1,30 @@
<?php
use Slim\Http\Request;
use Slim\Http\Response;
final class ServerGroupCreateAction extends AbstractAction
{
public function __invoke(Request $request, Response $response, $args)
{
$sid = $args['sid'];
$body = $request->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);
}
}

View file

@ -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;
}
}

View file

@ -26,6 +26,12 @@
{% endfor %}
</select>
{% elseif field.type == 'checkbox' %}
<input class="form-control" type="hidden" name="{{ field.key }}"
id="{{ editable.key }}" value="0" />
<input class="form-control" type="checkbox" name="{{ field.key }}"
id="{{ field.key }}" value="1" />
{% else %}
<input
class="form-control"

View file

@ -4,6 +4,24 @@
<h1 class="header">{{ title }}</h1>
<h2 class="header">{% trans %}groups.h.servergroups{% endtrans %}</h2>
{% include 'form.twig' with {
'fields': [
{
'header_label': 'groups.create'|trans,
'label': '<i class="material-icons">check_circle</i>',
'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 @@
<h2 class="header">{% trans %}groups.h.channelgroups{% endtrans %}</h2>
{% include 'form.twig' with {
'fields': [
{
'header_label': 'groups.create'|trans,
'label': '<i class="material-icons">check_circle</i>',
'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}],