Skip to content

Commit

Permalink
Request: 13049 Add permission for resource_management.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Apr 2, 2014
1 parent be6ca5b commit afb578f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 52 deletions.
98 changes: 51 additions & 47 deletions kronolith/lib/Application.php
Expand Up @@ -98,7 +98,10 @@ public function perms()
'max_events' => array(
'title' => _("Maximum Number of Events"),
'type' => 'int'
)
),
'resource_management' => array(
'title' => _("Resource Management"),
'type' => 'boolean')
);
}

Expand Down Expand Up @@ -250,55 +253,56 @@ public function sidebar($sidebar)
);
$sidebar->addRow($row, 'system');
}
}
if (!empty($GLOBALS['conf']['resource']['driver']) &&
($GLOBALS['registry']->isAdmin() || $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('resource_management'))) {

if (!empty($GLOBALS['conf']['resource']['driver'])) {
$sidebar->containers['groups'] = array(
'header' => array(
'id' => 'kronolith-toggle-groups',
'label' => _("Resource Groups"),
'collapsed' => true,
'add' => array(
'url' => Horde::url('resources/groups/create.php'),
'label' => _("Create a new Resource Group"),
),
$sidebar->containers['groups'] = array(
'header' => array(
'id' => 'kronolith-toggle-groups',
'label' => _("Resource Groups"),
'collapsed' => true,
'add' => array(
'url' => Horde::url('resources/groups/create.php'),
'label' => _("Create a new Resource Group"),
),
);
$editGroups = Horde::url('resources/groups/edit.php');
$sidebar->containers['resources'] = array(
'header' => array(
'id' => 'kronolith-toggle-resources',
'label' => _("Resources"),
'collapsed' => true,
'add' => array(
'url' => Horde::url('resources/create.php'),
'label' => _("Create a new Resource"),
),
),
);
$editGroups = Horde::url('resources/groups/edit.php');
$sidebar->containers['resources'] = array(
'header' => array(
'id' => 'kronolith-toggle-resources',
'label' => _("Resources"),
'collapsed' => true,
'add' => array(
'url' => Horde::url('resources/create.php'),
'label' => _("Create a new Resource"),
),
);
$edit = Horde::url('resources/edit.php');
foreach (Kronolith::getDriver('Resource')->listResources() as $resource) {
if ($resource->get('type') == Kronolith_Resource::TYPE_GROUP) {
$row = array(
'label' => $resource->get('name'),
'color' => '#dddddd',
'edit' => $editGroups->add('c', $resource->getId()),
'type' => 'radiobox',
);
$sidebar->addRow($row, 'groups');
} else {
$calendar = new Kronolith_Calendar_Resource(array(
'resource' => $resource
));
$row = array(
'selected' => in_array($resource->get('calendar'), $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_RESOURCE_CALENDARS)),
'url' => $url->copy()->add('toggle_calendar', 'resource_' . $resource->get('calendar')),
'label' => $calendar->name(),
'color' => $calendar->background(),
'edit' => $edit->add('c', $resource->getId()),
'type' => 'checkbox',
);
$sidebar->addRow($row, 'resources');
}
),
);
$edit = Horde::url('resources/edit.php');
foreach (Kronolith::getDriver('Resource')->listResources() as $resource) {
if ($resource->get('type') == Kronolith_Resource::TYPE_GROUP) {
$row = array(
'label' => $resource->get('name'),
'color' => '#dddddd',
'edit' => $editGroups->add('c', $resource->getId()),
'type' => 'radiobox',
);
$sidebar->addRow($row, 'groups');
} else {
$calendar = new Kronolith_Calendar_Resource(array(
'resource' => $resource
));
$row = array(
'selected' => in_array($resource->get('calendar'), $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_RESOURCE_CALENDARS)),
'url' => $url->copy()->add('toggle_calendar', 'resource_' . $resource->get('calendar')),
'label' => $calendar->name(),
'color' => $calendar->background(),
'edit' => $edit->add('c', $resource->getId()),
'type' => 'checkbox',
);
$sidebar->addRow($row, 'resources');
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions kronolith/lib/Driver/Resource/Sql.php
Expand Up @@ -225,10 +225,14 @@ public function deleteEvent($eventId, $silent = false)
* @param Kronolith_Resource_Base $resource
*
* @return Kronolith_Resource object
* @throws Kronolith_Exception
* @throws Kronolith_Exception, Horde_Exception_PermissionDenied
*/
public function save(Kronolith_Resource_Base $resource)
{
if (!$GLOBALS['registry']->isAdmin() &&
!$GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('resource_management')) {
throw new Horde_Exception_PermissionDenied();
}
if ($resource->getId()) {
$query = 'UPDATE ' . $this->_params['table'] . ' SET resource_name = ?, '
. 'resource_calendar = ? , resource_description = ?, '
Expand Down Expand Up @@ -279,10 +283,15 @@ public function save(Kronolith_Resource_Base $resource)
*
* @param Kronolith_Resource_Base $resource The kronolith resource to remove
*
* @throws Kronolith_Exception
* @throws Kronolith_Exception, Horde_Exception_PermissionDenied
*/
public function delete($resource)
{
if (!$GLOBALS['registry']->isAdmin() &&
!$GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('resource_management')) {
throw new Horde_Exception_PermissionDenied();
}

if (!$resource->getId()) {
throw new Kronolith_Exception(_("Resource not valid."));
}
Expand Down
2 changes: 1 addition & 1 deletion kronolith/lib/View/Sidebar.php
Expand Up @@ -58,7 +58,7 @@ public function __construct($config = array())
/* Calendars. */
$sidebar->newShares = $registry->getAuth() &&
!$prefs->isLocked('default_share');
$sidebar->isAdmin = $registry->isAdmin();
$sidebar->resourceAdmin = $registry->isAdmin() || $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('resource_management');
$sidebar->resources = $GLOBALS['conf']['resource']['driver'] == 'sql';

$this->content = $sidebar->render('dynamic/sidebar');
Expand Down
4 changes: 2 additions & 2 deletions kronolith/templates/dynamic/sidebar.html.php
Expand Up @@ -83,7 +83,7 @@
<div class="horde-sidebar-split"></div>
<div>
<h3>
<?php if ($this->isAdmin): ?>
<?php if ($this->resourceAdmin): ?>
<a href="#" id="kronolithAddresource" class="horde-add" title="<?php echo _("Add Resource") ?>">+</a>
<?php endif; ?>
<span class="horde-expand" title="<?php echo _("Expand") ?>"><?php echo _("Resources") ?></span>
Expand All @@ -98,7 +98,7 @@
<div class="horde-sidebar-split"></div>
<div>
<h3>
<?php if ($this->isAdmin): ?>
<?php if ($this->resourceAdmin): ?>
<a href="#" id="kronolithAddresourcegroup" class="horde-add" title="<?php echo _("Add Resource Group") ?>">+</a>
<?php endif; ?>
<span class="horde-expand" title="<?php echo _("Expand") ?>"><?php echo _("Resource Groups") ?></span>
Expand Down

0 comments on commit afb578f

Please sign in to comment.