From: Andrey Kutejko Date: Fri, 29 Aug 2014 04:35:19 +0000 (+0300) Subject: no title for permission X-Git-Tag: 0.6~155 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=398dd3952d3eb281b5c04d425ac2fa605a63f1e7;p=ipf.git no title for permission --- diff --git a/ipf/admin/app.php b/ipf/admin/app.php index 802e0e8..b87d0e3 100644 --- a/ipf/admin/app.php +++ b/ipf/admin/app.php @@ -76,7 +76,7 @@ class IPF_Admin_App extends IPF_Application 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); @@ -87,6 +87,8 @@ class IPF_Admin_App extends IPF_Application 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; @@ -100,17 +102,19 @@ class IPF_Admin_App extends IPF_Application 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() diff --git a/ipf/admin/commands/syncperms.php b/ipf/admin/commands/syncperms.php index 5d468b6..6c72466 100644 --- a/ipf/admin/commands/syncperms.php +++ b/ipf/admin/commands/syncperms.php @@ -14,7 +14,7 @@ class IPF_Admin_Command_SyncPerms 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"; } @@ -44,15 +44,10 @@ class IPF_Admin_Command_SyncPerms 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(); } } } diff --git a/ipf/auth/admin.php b/ipf/auth/admin.php index c34c882..55d1bdc 100644 --- a/ipf/auth/admin.php +++ b/ipf/auth/admin.php @@ -1,5 +1,23 @@ 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; @@ -58,7 +76,7 @@ class IPFAuthAdminUserForm extends IPF_Form $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'), )); @@ -239,9 +257,9 @@ class IPFAdminRoleForm extends IPF_Form 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'), )); } diff --git a/ipf/auth/migrations/20140102000000_create_auth_tables.php b/ipf/auth/migrations/20140102000000_create_auth_tables.php index e3e953a..5eb1394 100644 --- a/ipf/auth/migrations/20140102000000_create_auth_tables.php +++ b/ipf/auth/migrations/20140102000000_create_auth_tables.php @@ -6,7 +6,7 @@ class Migration_20140102000000 extends \PFF\Migrations\Migration { $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');