chg: migrate sharing_views/view/[id] to factory

pull/7641/head
Luciano Righetti 2021-08-11 10:50:47 +02:00
parent 559e11acab
commit 8cd5953d39
3 changed files with 124 additions and 107 deletions

View File

@ -53,13 +53,13 @@ class SharingGroupsController extends AppController
$id = $this->SharingGroup->captureSG($this->request->data, $this->Auth->user()); $id = $this->SharingGroup->captureSG($this->request->data, $this->Auth->user());
if ($id) { if ($id) {
if (empty($sg['roaming']) && empty($sg['SharingGroupServer'])) { if (empty($sg['roaming']) && empty($sg['SharingGroupServer'])) {
$this->SharingGroup->SharingGroupServer->create(); $this->SharingGroup->SharingGroupServer->create();
$this->SharingGroup->SharingGroupServer->save(array( $this->SharingGroup->SharingGroupServer->save(array(
'sharing_group_id' => $this->SharingGroup->id, 'sharing_group_id' => $this->SharingGroup->id,
'server_id' => 0, 'server_id' => 0,
'all_orgs' => 0 'all_orgs' => 0
)); ));
} }
$sg = $this->SharingGroup->fetchAllAuthorised($this->Auth->user(), 'simplified', false, $id); $sg = $this->SharingGroup->fetchAllAuthorised($this->Auth->user(), 'simplified', false, $id);
if (!empty($sg)) { if (!empty($sg)) {
$sg = empty($sg) ? array() : $sg[0]; $sg = empty($sg) ? array() : $sg[0];
@ -90,9 +90,9 @@ class SharingGroupsController extends AppController
foreach ($sg['Organisation'] as $org) { foreach ($sg['Organisation'] as $org) {
$this->SharingGroup->SharingGroupOrg->create(); $this->SharingGroup->SharingGroupOrg->create();
$this->SharingGroup->SharingGroupOrg->save(array( $this->SharingGroup->SharingGroupOrg->save(array(
'sharing_group_id' => $this->SharingGroup->id, 'sharing_group_id' => $this->SharingGroup->id,
'org_id' => $org['id'], 'org_id' => $org['id'],
'extend' => $org['extend'] 'extend' => $org['extend']
)); ));
} }
} }
@ -100,9 +100,9 @@ class SharingGroupsController extends AppController
foreach ($sg['Server'] as $server) { foreach ($sg['Server'] as $server) {
$this->SharingGroup->SharingGroupServer->create(); $this->SharingGroup->SharingGroupServer->create();
$this->SharingGroup->SharingGroupServer->save(array( $this->SharingGroup->SharingGroupServer->save(array(
'sharing_group_id' => $this->SharingGroup->id, 'sharing_group_id' => $this->SharingGroup->id,
'server_id' => $server['id'], 'server_id' => $server['id'],
'all_orgs' => $server['all_orgs'] 'all_orgs' => $server['all_orgs']
)); ));
} }
} }
@ -124,7 +124,7 @@ class SharingGroupsController extends AppController
} elseif ($this->_isRest()) { } elseif ($this->_isRest()) {
return $this->RestResponse->describe('SharingGroup', 'add', false, $this->response->type()); return $this->RestResponse->describe('SharingGroup', 'add', false, $this->response->type());
} }
$orgs = $this->SharingGroup->Organisation->find('all', array( $orgs = $this->SharingGroup->Organisation->find('all', array(
'conditions' => array('local' => 1), 'conditions' => array('local' => 1),
'recursive' => -1, 'recursive' => -1,
@ -135,7 +135,7 @@ class SharingGroupsController extends AppController
// We just pass true and allow the user to edit, since he/she is just about to create the SG. This is needed to reuse the view for the edit // We just pass true and allow the user to edit, since he/she is just about to create the SG. This is needed to reuse the view for the edit
$this->set('user', $this->Auth->user()); $this->set('user', $this->Auth->user());
} }
public function edit($id = false) public function edit($id = false)
{ {
if (!$this->userRole['perm_sharing_group']) { if (!$this->userRole['perm_sharing_group']) {
@ -144,7 +144,7 @@ class SharingGroupsController extends AppController
if (empty($id)) { if (empty($id)) {
throw new NotFoundException('Invalid sharing group.'); throw new NotFoundException('Invalid sharing group.');
} }
// check if the user is eligible to edit the SG (original creator or extend) // check if the user is eligible to edit the SG (original creator or extend)
$sharingGroup = $this->SharingGroup->find('first', array( $sharingGroup = $this->SharingGroup->find('first', array(
'conditions' => Validation::uuid($id) ? ['SharingGroup.uuid' => $id] : ['SharingGroup.id' => $id], 'conditions' => Validation::uuid($id) ? ['SharingGroup.uuid' => $id] : ['SharingGroup.id' => $id],
@ -441,7 +441,7 @@ class SharingGroupsController extends AppController
$this->set('mayModify', $this->SharingGroup->checkIfAuthorisedExtend($this->Auth->user(), $sg['SharingGroup']['id'])); $this->set('mayModify', $this->SharingGroup->checkIfAuthorisedExtend($this->Auth->user(), $sg['SharingGroup']['id']));
$this->set('id', $sg['SharingGroup']['id']); $this->set('id', $sg['SharingGroup']['id']);
$this->set('sg', $sg); $this->set('sg', $sg);
$this->set('title_for_layout', __('Sharing Group %s', $sg['SharingGroup']['name'])); $this->set('menuData', ['menuList' => 'globalActions', 'menuItem' => 'viewSG']);
} }
private function __initialiseSGQuickEdit($id, $request) private function __initialiseSGQuickEdit($id, $request)

View File

@ -0,0 +1,3 @@
<?php
echo isset($data['Organisation']['id']) ? $this->OrgImg->getNameWithImg($data) : __('Unknown');

View File

@ -1,92 +1,106 @@
<div class="roles view">
<h2><?= __('Sharing Group %s', h($sg['SharingGroup']['name']));?></h2>
<div class="row-fluid"><div class="span8" style="margin:0">
<?php <?php
$tableData = [
['key' => __('ID'), 'value' => $sg['SharingGroup']['id']], echo $this->element(
['key' => __('UUID'), 'value' => $sg['SharingGroup']['uuid'], 'value_class' => 'quickSelect'], 'genericElements/SingleViews/single_view',
['key' => __('Name'), 'value' => $sg['SharingGroup']['name']],
['key' => __('Releasability'), 'value' => $sg['SharingGroup']['releasability']],
['key' => __('Description'), 'value' => $sg['SharingGroup']['description']],
['key' => __('Selectable'), 'boolean' => $sg['SharingGroup']['active']],
[ [
'key' => __('Created by'), 'title' => __('Sharing Group %s', $sg['SharingGroup']['name']),
'html' => isset($sg['Organisation']['id']) ? $this->OrgImg->getNameWithImg($sg) : __('Unknown'), 'data' => $sg,
], 'fields' => [
]; [
if ($sg['SharingGroup']['sync_user_id']) { 'key' => __('ID'),
$tableData[] = [ 'path' => 'SharingGroup.id'
'key' => __('Synced by'), ],
'html' => isset($sg['SharingGroup']['sync_org']) ? $this->OrgImg->getNameWithImg($sg['SharingGroup']['sync_org']) : __('Unknown'), [
]; 'key' => __('UUID'),
} 'path' => 'SharingGroup.uuid'
$eventsLink = $baseurl . '/events/index/searchsharinggroup:' . $sg['SharingGroup']['id']; ],
$tableData[] = [ [
'key' => __('Events'), 'key' => __('Name'),
'html' => '<a href="' . $eventsLink . '">' . __n('%s event', '%s events', $sg['SharingGroup']['event_count'], $sg['SharingGroup']['event_count']) . '</a>', 'path' => 'SharingGroup.name'
]; ],
if (isset($sg['SharingGroup']['org_count'])) { [
$tableData[] = [ 'key' => __('Releasability'),
'key' => __('Organisations'), 'path' => 'SharingGroup.releasability'
'html' => __n('%s organisation', '%s organisations', $sg['SharingGroup']['org_count'], $sg['SharingGroup']['org_count']), ],
]; [
} 'key' => __('Description'),
echo $this->element('genericElements/viewMetaTable', ['table_data' => $tableData]); 'path' => 'SharingGroup.description'
?> ],
</div></div> [
<br /> 'key' => __('Selectable'),
<div class="row" style="width:100%;"> 'path' => 'SharingGroup.active',
<?php 'type' => 'boolean'
if (isset($sg['SharingGroupOrg'])): ],
?> [
<div class="span6"> 'key' => __('Created by'),
<b><?php echo __('Organisations');?></b> 'path' => 'Organisation',
<table class="table table-striped table-hover table-condensed"> 'type' => 'org'
<tr> ],
<th><?= __('Name') ?></th> [
<th><?= __('Is local') ?></th> 'key' => __('Synced by'),
<th><?= __('Can extend') ?></th> 'path' => 'SharingGroup.sync_org',
</tr> 'type' => 'org',
<?php 'requirement' => isset($sg['SharingGroup']['sync_org'])
foreach ($sg['SharingGroupOrg'] as $sgo): ],
?> [
<tr> 'key' => __('Events'),
<td><?= $this->OrgImg->getNameWithImg($sgo) ?></td> 'raw' => __n('%s event', '%s events', $sg['SharingGroup']['event_count'], $sg['SharingGroup']['event_count']),
<td><span class="<?= $sgo['Organisation']['local'] ? 'fas fa-check' : 'fas fa-times' ?>"></span></td> 'url' => sprintf('/events/index/searchsharinggroup:%s', h($sg['SharingGroup']['id']))
<td><span class="<?= $sgo['extend'] ? 'fas fa-check' : 'fas fa-times' ?>"></span></td> ],
</tr> [
<?php 'key' => __('Organisations'),
endforeach; 'type' => 'custom',
?> 'function' => function ($sharingGroup) {
</table> echo sprintf(
</div> '<div class="span6">
<?php <table class="table table-striped table-hover table-condensed">
endif; <tr>
if (!$sg['SharingGroup']['roaming'] && isset($sg['SharingGroupServer'])): <th>%s</th>
?> <th>%s</th>
<div class="span6"> <th>%s</th>
<b>Instances</b> </tr>',
<table class="table table-striped table-hover table-condensed"> __('Name'),
<tr> __('Is local'),
<th><?= __('Name') ?></th> __('Can extend')
<th><?= __('URL') ?></th> );
<th><?= __('All orgs') ?></th> foreach ($sharingGroup['SharingGroupOrg'] as $sgo) {
</tr> echo '<tr>';
<?php echo sprintf('<td>%s</td>', $this->OrgImg->getNameWithImg($sgo));
foreach ($sg['SharingGroupServer'] as $sgs): ?> echo sprintf('<td><span class="%s"></span></td>', $sgo['Organisation']['local'] ? 'fas fa-check' : 'fas fa-times');
<tr> echo sprintf('<td><span class="%s"></span></td>', $sgo['extend'] ? 'fas fa-check' : 'fas fa-times');
<td><?= h($sgs['Server']['name']) ?></td> echo '</tr>';
<td><?= h($sgs['Server']['url']) ?></td> }
<td><span class="<?= $sgs['all_orgs'] ? 'fas fa-check' : 'fas fa-times' ?>"></span></td> echo '</table>
</tr> </div>';
<?php }
endforeach; ],
?> [
</table> 'key' => __('Instances'),
</div> 'type' => 'custom',
<?php 'function' => function ($sharingGroup) {
endif; echo sprintf(
?> '<div class="span6">
</div> <table class="table table-striped table-hover table-condensed">
</div> <tr>
<?= $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'globalActions', 'menuItem' => 'viewSG')); <th>%s</th>
<th>%s</th>
<th>%s</th>
</tr>',
__('Name'),
__('URL'),
__('All orgs')
);
foreach ($sharingGroup['SharingGroupServer'] as $sgs) {
echo '<tr>';
echo sprintf('<td>%s</td>', h($sgs['Server']['name']));
echo sprintf('<td>%s</td>', h($sgs['Server']['url']));
echo sprintf('<td><span class="%s"></span></td>', $sgs['all_orgs'] ? 'fas fa-check' : 'fas fa-times');
echo '</tr>';
}
echo '</table>
</div>';
}
]
]
]
);