Skip to content

Commit

Permalink
We only have one channel type in Jonah now.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Dec 20, 2016
1 parent 7a02ac7 commit 2f4ac16
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 48 deletions.
7 changes: 0 additions & 7 deletions jonah/config/conf.xml
Expand Up @@ -4,13 +4,6 @@

<configsection name="news">
<configheader>Feed Settings</configheader>
<configmultienum name="enable" desc="Select which types of feeds to allow.">internal
<values>
<value desc="Local Feed">internal</value>
<value desc="Composite Feed">composite</value>
</values>
</configmultienum>

<configsection name="storage">
<configswitch name="driver" desc="What driver should we use for local feeds?">sql
<case name="sql" desc="SQL">
Expand Down
2 changes: 1 addition & 1 deletion jonah/lib/Api.php
Expand Up @@ -107,7 +107,7 @@ public function publish($channel_id, $story)
$driver = $GLOBALS['injector']->getInstance('Jonah_Driver');
$channel = $driver->getChannel($channel_id);
/* Check permissions. */
if (!Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::EDIT, $channel_id)) {
if (!Jonah::checkPermissions('channels', Horde_Perms::EDIT, $channel_id)) {
throw new Horde_Exception_PermissionDenied(_("You are not authorised for this action."));
}
$story['author'] = $GLOBALS['registry']->getAuth();
Expand Down
20 changes: 8 additions & 12 deletions jonah/lib/Application.php
Expand Up @@ -92,22 +92,18 @@ public function menu($menu)
'text' => _("_Feeds"),
'url' => Horde::url('channels/index.php')
));
$menu->addArray(array(
'icon' => 'new.png',
'text' => _("New Feed"),
'url' => Horde::url('channels/edit.php')
));
}
foreach ($GLOBALS['conf']['news']['enable'] as $channel_type) {
if (Jonah::checkPermissions($channel_type, Horde_Perms::EDIT)) {
$menu->addArray(array(
'icon' => 'new.png',
'text' => _("New Feed"),
'url' => Horde::url('channels/edit.php')
));
break;
}
}

/* If viewing a channel, show new story links if authorized */
if ($channel_id = Horde_Util::getFormData('channel_id')) {
$news = $GLOBALS['injector']->getInstance('Jonah_Driver');
$channel = $news->getChannel($channel_id);
if ($channel['channel_type'] == Jonah::INTERNAL_CHANNEL &&
Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::EDIT, $channel_id)) {
if (Jonah::checkPermissions('channels', Horde_Perms::EDIT, $channel_id)) {
$menu->addArray(array(
'icon' => 'new.png',
'text' => _("_New Story"),
Expand Down
29 changes: 7 additions & 22 deletions jonah/lib/Jonah.php
Expand Up @@ -86,7 +86,9 @@ public static function getChannelTypeLabel($type)
*/
public static function checkPermissions($filter, $permission = Horde_Perms::READ, $in = null)
{
if ($GLOBALS['registry']->isAdmin(array('permission' => 'jonah:admin', 'permlevel' => $permission))) {
global $registry, $injector;

if ($registry->isAdmin(array('permission' => 'jonah:admin', 'permlevel' => $permission))) {
if (empty($in)) {
// Calls with no $in parameter are checking whether this user
// has permission. Since this user is an admin, they always
Expand All @@ -98,37 +100,23 @@ public static function checkPermissions($filter, $permission = Horde_Perms::READ
}
}

$perms = $GLOBALS['injector']->getInstance('Horde_Perms');
$perms = $injector->getInstance('Horde_Perms');

$out = array();

switch ($filter) {
case 'internal_channels':
if (empty($in) || !$perms->exists('jonah:news:' . $filter . ':' . $in)) {
return $perms->hasPermission('jonah:news:' . $filter, $GLOBALS['registry']->getAuth(), $permission);
} elseif (!is_array($in)) {
return $perms->hasPermission('jonah:news:' . $filter . ':' . $in, $GLOBALS['registry']->getAuth(), $permission);
} else {
foreach ($in as $key => $val) {
if ($perms->hasPermission('jonah:news:' . $filter . ':' . $val, $GLOBALS['registry']->getAuth(), $permission)) {
$out[$key] = $val;
}
}
}
break;

case 'channels':
foreach ($in as $key => $val) {
$perm_name = Jonah::typeToPermName($val['channel_type']);
if ($perms->hasPermission('jonah:news:' . $perm_name, $GLOBALS['registry']->getAuth(), $permission) ||
$perms->hasPermission('jonah:news:' . $perm_name . ':' . $val['channel_id'], $GLOBALS['registry']->getAuth(), $permission)) {
if ($perms->hasPermission('jonah:news:' . $perm_name, $registry->getAuth(), $permission) ||
$perms->hasPermission('jonah:news:' . $perm_name . ':' . $val['channel_id'], $registry->getAuth(), $permission)) {
$out[$key] = $in[$key];
}
}
break;

default:
return $perms->hasPermission($filter, $GLOBALS['registry']->getAuth(), Horde_Perms::EDIT);
return $perms->hasPermission($filter, $registry->getAuth(), Horde_Perms::EDIT);
}

return $out;
Expand Down Expand Up @@ -209,9 +197,6 @@ public static function getAvailableTypes()
if (in_array('internal', $GLOBALS['conf']['news']['enable'])) {
$types[Jonah::INTERNAL_CHANNEL] = _("Local Feed");
}
if (in_array('composite', $GLOBALS['conf']['news']['enable'])) {
$types[Jonah::COMPOSITE_CHANNEL] = _("Composite Feed");
}

return $types;
}
Expand Down
2 changes: 1 addition & 1 deletion jonah/lib/View/ChannelDelete.php
Expand Up @@ -43,7 +43,7 @@ public function run()
}

/* Check permissions and deny if not allowed. */
if (!Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::DELETE, $channel_id)) {
if (!Jonah::checkPermissions('channels', Horde_Perms::DELETE, $channel_id)) {
$notification->push(_("You are not authorised for this action."), 'horde.warning');
throw new Horde_Exception_AuthenticationFailure();
}
Expand Down
2 changes: 1 addition & 1 deletion jonah/lib/View/StoryDelete.php
Expand Up @@ -35,7 +35,7 @@ public function run()
}

/* Check permissions. */
if (!Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::DELETE, $channel_id)) {
if (!Jonah::checkPermissions('channels', Horde_Perms::DELETE, $channel_id)) {
$notification->push(_("You are not authorised for this action."), 'horde.warning');
throw new Horde_Exception_AuthenticationFailure();
}
Expand Down
2 changes: 1 addition & 1 deletion jonah/lib/View/StoryEdit.php
Expand Up @@ -42,7 +42,7 @@ public function run()
}

/* Check permissions. */
if (!Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::EDIT, $channel_id)) {
if (!Jonah::checkPermissions('channels', Horde_Perms::EDIT, $channel_id)) {
$notification->push(_("You are not authorised for this action."), 'horde.warning');
throw new Horde_Exception_AuthenticationFailure();
}
Expand Down
4 changes: 2 additions & 2 deletions jonah/lib/View/StoryList.php
Expand Up @@ -28,7 +28,7 @@ public function run()
extract($this->_params, EXTR_REFS);

$channel = $GLOBALS['injector']->getInstance('Jonah_Driver')->getChannel($channel_id);
if (!Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::EDIT, $channel_id)) {
if (!Jonah::checkPermissions('channels', Horde_Perms::EDIT, $channel_id)) {
$notification->push(_("You are not authorised for this action."), 'horde.warning');
throw new Horde_Exception_AuthenticationFailure();
}
Expand Down Expand Up @@ -60,7 +60,7 @@ public function run()
}

/* Get channel details, for title, etc. */
$allow_delete = Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::DELETE, $channel_id);
$allow_delete = Jonah::checkPermissions('channels', Horde_Perms::DELETE, $channel_id);

/* Build story specific fields. */
foreach ($stories as $key => $story) {
Expand Down
2 changes: 1 addition & 1 deletion jonah/lib/View/TagSearchList.php
Expand Up @@ -30,7 +30,7 @@ public function run()
/* Use the passed channel_id, or use all public channels */
if (!is_null($channel_id)) {
$channel = $driver->getChannel($channel_id);
if (!Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::SHOW, $channel_id)) {
if (!Jonah::checkPermissions('channels', Horde_Perms::SHOW, $channel_id)) {
$notification->push(_("You are not authorised for this action."), 'horde.warning');
throw new Horde_Exception_AuthenticationFailure();
}
Expand Down

0 comments on commit 2f4ac16

Please sign in to comment.