return true;
$authPermissions = \PFF\Arr($requiredPermissions)
- ->map('sprintf', '%s|%s|%s', get_class($component->app), $component->slug(), \PFF\Symbol::_())
+ ->map('sprintf', '%s|%s|%s', $component->app->slug(), $component->slug(), \PFF\Symbol::_())
->arr();
return $request->user->can($authPermissions);
self::ensureUserIsStaff($request);
$component = self::getComponentBySlugs($request->params[1], $request->params[2]);
+ if (!$component)
+ throw new IPF_HTTP_Error404;
if (!IPF_Admin_App::isAccessible($request, $component, $requiredPermissions))
throw new IPF_Admin_AccessDenied;
foreach (IPF_Project::getInstance()->appList() as $app)
if ($app->slug() == $slug)
return $app;
- throw new IPF_HTTP_Error404;
+ return null;
}
public static function getComponentBySlugs($appSlug, $componentSlug)
{
$app = self::getApplicationBySlug($appSlug);
+ if (!$app)
+ return null;
foreach (self::applicationComponents($app) as $component) {
if ($component->slug() == $componentSlug)
return $component;
}
- throw new IPF_HTTP_Error404;
+ return null;
}
public function commands()
foreach (IPF_Project::getInstance()->appList() as $appname => $app) {
foreach (IPF_Admin_App::applicationComponents($app) as $component) {
foreach ($component->getPerms(null) as $permName) {
- $name = get_class($app).'|'.$component->slug().'|'.$permName;
+ $name = $app->slug().'|'.$component->slug().'|'.$permName;
$permissions[$name] = array($app, $component, $permName);
print ' '.$name."\n";
}
print "\nADDING:\n ".implode("\n ", $toAdd)."\n";
foreach ($toAdd as $name) {
- $app = $permissions[$name][0];
- $component = $permissions[$name][1];
-
\PFF\Container::databaseQuery()
->insertInto('auth_permission')
- ->values(array(
- 'name' => $name,
- 'title' => $app->getTitle().' | '.$component->slug().' | '.ucfirst($permissions[$name][2]),
- ))->execute();
+ ->values(array('name' => $name))
+ ->execute();
}
}
}
<?php
+function permissionChoices()
+{
+ $choices = array();
+ foreach (Permission::query()->fetchAll() as $p) {
+ list($appSlug, $componentSlug, $permission) = explode('|', $p->name);
+ $component = IPF_Admin_App::getComponentBySlugs($appSlug, $componentSlug);
+
+ if ($component)
+ $title = $component->app->getTitle().' | '.$component->verbose_name().' | '.ucfirst($permission);
+ else
+ $title = $p->name;
+
+ $choices[$title] = $p->id;
+ }
+ ksort($choices);
+ return $choices;
+}
+
class IPFAuthAdminUserForm extends IPF_Form
{
private $isAdd;
$this->fields['permissions'] = new IPF_Form_Field_MultipleChoice(array(
'label' => __('Permissions'),
- 'choices' => Permission::query()->fetchPairs('title', 'id'),
+ 'choices' => permissionChoices(),
'widget' => 'IPF_Form_Widget_SelectMultipleInputCheckbox',
'widget_attrs' => array('class' => 'checkgroup'),
));
if (IPF_Auth_App::ArePermissionsEnabled()) {
$this->fields['permissions'] = new IPF_Form_Field_MultipleChoice(array(
- 'label' => __('Permissions'),
- 'choices' => Permission::query()->fetchPairs('title', 'id'),
- 'widget' => 'IPF_Form_Widget_SelectMultipleInputCheckbox',
+ 'label' => __('Permissions'),
+ 'choices' => permissionChoices(),
+ 'widget' => 'IPF_Form_Widget_SelectMultipleInputCheckbox',
'widget_attrs' => array('class' => 'checkgroup'),
));
}
{
$this->connection->exec('CREATE TABLE auth_user (id BIGINT AUTO_INCREMENT, username VARCHAR(32) NOT NULL UNIQUE, password VARCHAR(128) NOT NULL, email VARCHAR(200) NOT NULL UNIQUE, is_staff TINYINT(1) NOT NULL DEFAULT 0, is_active TINYINT(1) NOT NULL DEFAULT 0, is_superuser TINYINT(1) NOT NULL DEFAULT 0, last_login TIMESTAMP, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB');
$this->connection->exec('CREATE TABLE auth_role (id BIGINT AUTO_INCREMENT, name VARCHAR(255) UNIQUE, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB');
- $this->connection->exec('CREATE TABLE auth_permission (id BIGINT AUTO_INCREMENT, name VARCHAR(255) NOT NULL UNIQUE, title VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB');
+ $this->connection->exec('CREATE TABLE auth_permission (id BIGINT AUTO_INCREMENT, name VARCHAR(255) NOT NULL UNIQUE, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB');
$this->connection->exec('CREATE TABLE auth_user_permission (user_id BIGINT, permission_id BIGINT, PRIMARY KEY(user_id, permission_id)) ENGINE = INNODB');
$this->connection->exec('CREATE TABLE auth_user_role (user_id BIGINT, role_id BIGINT, PRIMARY KEY(user_id, role_id)) ENGINE = INNODB');