Jonah::checkPermissions PHP Method

checkPermissions() public static method

public static checkPermissions ( string $filter, integer $permission = Horde_Perms::READ, mixed $in = null ) : mixed
$filter string The type of channel
$permission integer Horde_Perms:: constant
$in mixed ??
return mixed An array of results or a single boolean?
    public static function checkPermissions($filter, $permission = Horde_Perms::READ, $in = null)
    {
        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
                // have permission.  If the $in parameter is an empty array,
                // the method is expected to return an array too.
                return is_array($in) ? array() : true;
            } else {
                return $in;
            }
        }
        $perms = $injector->getInstance('Horde_Perms');
        $out = array();
        switch ($filter) {
            case 'channels':
                foreach ($in as $key => $val) {
                    if ($perms->hasPermission('jonah:news', $registry->getAuth(), $permission) || $perms->hasPermission('jonah:news:' . $val['channel_id'], $registry->getAuth(), $permission)) {
                        $out[$key] = $in[$key];
                    }
                }
                break;
            default:
                return $perms->hasPermission($filter, $registry->getAuth(), Horde_Perms::EDIT);
        }
        return $out;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Expects:
  *   $vars
  *   $registry
  *   $notification
  */
 public function run()
 {
     extract($this->_params, EXTR_REFS);
     /* Set up the form variables and the form. */
     $form_submit = $vars->get('submitbutton');
     $channel_id = $vars->get('channel_id');
     try {
         $channel = $GLOBALS['injector']->getInstance('Jonah_Driver')->getChannel($channel_id);
     } catch (Exception $e) {
         Horde::log($e, 'ERR');
         $notification->push(_("Invalid channel specified for deletion."), 'horde.message');
         Horde::url('channels')->redirect();
         exit;
     }
     /* If not yet submitted set up the form vars from the fetched channel. */
     if (empty($form_submit)) {
         $vars = new Horde_Variables($channel);
     }
     /* Check permissions and deny if not allowed. */
     if (!Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::DELETE, $channel_id)) {
         $notification->push(_("You are not authorised for this action."), 'horde.warning');
         throw new Horde_Exception_AuthenticationFailure();
     }
     $title = sprintf(_("Delete News Channel \"%s\"?"), $vars->get('channel_name'));
     $form = new Horde_Form($vars, $title);
     $form->setButtons(array(_("Delete"), _("Do not delete")));
     $form->addHidden('', 'channel_id', 'int', true, true);
     $msg = _("Really delete this News Channel? All stories created in this channel will be lost!");
     $form->addVariable($msg, 'confirm', 'description', false);
     if ($form_submit == _("Delete")) {
         if ($form->validate($vars)) {
             $form->getInfo($vars, $info);
             try {
                 $delete = $GLOBALS['injector']->getInstance('Jonah_Driver')->deleteChannel($info);
                 $notification->push(_("The channel has been deleted."), 'horde.success');
                 Horde::url('channels')->redirect();
                 exit;
             } catch (Exception $e) {
                 $notification->push(sprintf(_("There was an error deleting the channel: %s"), $e->getMessage()), 'horde.error');
             }
         }
     } elseif (!empty($form_submit)) {
         $notification->push(_("Channel has not been deleted."), 'horde.message');
         Horde::url('channels')->redirect();
         exit;
     }
     $GLOBALS['page_output']->header(array('title' => $title));
     $notification->notify(array('listeners' => 'status'));
     $form->renderActive(null, $vars, Horde::selfUrl(), 'post');
     $GLOBALS['page_output']->footer();
 }
All Usage Examples Of Jonah::checkPermissions