]> git.andy128k.dev Git - ipf.git/commitdiff
no title for permission
authorAndrey Kutejko <andy128k@gmail.com>
Fri, 29 Aug 2014 04:35:19 +0000 (07:35 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Fri, 29 Aug 2014 04:35:19 +0000 (07:35 +0300)
ipf/admin/app.php
ipf/admin/commands/syncperms.php
ipf/auth/admin.php
ipf/auth/migrations/20140102000000_create_auth_tables.php

index 802e0e806c855a47b289c6f61ab0205f1ce832b0..b87d0e3646ca43ae56678ceb16cd3f8a54d7f4c5 100644 (file)
@@ -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()
index 5d468b6e16cae066ed7ea84774e7896a46c43f2e..6c724662e21e1864bcf0634735a36e748543ddcd 100644 (file)
@@ -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();
             }
         }
     }
index c34c882decc927eda5c064755f252c8b5fbdcf40..55d1bdcdab2b13d60335113065abfcd33c6b6a22 100644 (file)
@@ -1,5 +1,23 @@
 <?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;
@@ -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'),
             ));
         }
index e3e953a8edd2ce1da5e6a3dccdb8dc7436fc82c3..5eb1394e9ff027fda071ba5d43ff401086e9331c 100644 (file)
@@ -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');