From 6bee793704e44dc8084b863edb54c98d2ab931f9 Mon Sep 17 00:00:00 2001 From: Loic d'Anterroches Date: Tue, 25 Nov 2008 09:38:10 +0100 Subject: [PATCH] Added permission at the installation/upgrade for cleaner code. The authorized user permission is added at the installation/upgrade step to remove the code to remove the unncessary logic in the code. --- src/IDF/Form/TabsConf.php | 10 ---------- src/IDF/Migrations/6PrivateProject.php | 9 +++++++++ src/IDF/Migrations/Install.php | 8 ++++++++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/IDF/Form/TabsConf.php b/src/IDF/Form/TabsConf.php index c399b9d..66dde89 100644 --- a/src/IDF/Form/TabsConf.php +++ b/src/IDF/Form/TabsConf.php @@ -78,16 +78,6 @@ class IDF_Form_TabsConf extends Pluf_Form } // remove all the permissions $perm = Pluf_Permission::getFromString('IDF.project-authorized-user'); - if ($perm == false) { - // We do not have this perm for the moment in the system, - // so create it. - $perm = new Pluf_Permission(); - $perm->name = 'Project authorized users'; - $perm->code_name = 'project-authorized-user'; - $perm->description = 'Permission given to users allowed to access a project.'; - $perm->application = 'IDF'; - $perm->create(); - } $cm = $this->project->getMembershipData(); $guser = new Pluf_User(); foreach ($cm['authorized'] as $user) { diff --git a/src/IDF/Migrations/6PrivateProject.php b/src/IDF/Migrations/6PrivateProject.php index 8db71c3..04499f0 100644 --- a/src/IDF/Migrations/6PrivateProject.php +++ b/src/IDF/Migrations/6PrivateProject.php @@ -37,10 +37,18 @@ function IDF_Migrations_6PrivateProject_up($params=null) throw new Exception('SQLite complex migration not supported.'); } $db->execute($sql[$engine]); + $perm = new Pluf_Permission(); + $perm->name = 'Project authorized users'; + $perm->code_name = 'project-authorized-user'; + $perm->description = 'Permission given to users allowed to access a project.'; + $perm->application = 'IDF'; + $perm->create(); } function IDF_Migrations_6PrivateProject_down($params=null) { + $perm = Pluf_Permission::getFromString('IDF.project-authorized-user'); + if ($perm) $perm->delete(); $table = Pluf::factory('IDF_Project')->getSqlTable(); $sql = array(); $sql['PostgreSQL'] = 'ALTER TABLE '.$table.' DROP COLUMN "private"'; @@ -51,4 +59,5 @@ function IDF_Migrations_6PrivateProject_down($params=null) throw new Exception('SQLite complex migration not supported.'); } $db->execute($sql[$engine]); + } \ No newline at end of file diff --git a/src/IDF/Migrations/Install.php b/src/IDF/Migrations/Install.php index 4bfed6c..f855c3f 100644 --- a/src/IDF/Migrations/Install.php +++ b/src/IDF/Migrations/Install.php @@ -62,6 +62,12 @@ function IDF_Migrations_Install_setup($params=null) $perm->description = 'Permission given to project owners.'; $perm->application = 'IDF'; $perm->create(); + $perm = new Pluf_Permission(); + $perm->name = 'Project authorized users'; + $perm->code_name = 'project-authorized-user'; + $perm->description = 'Permission given to users allowed to access a project.'; + $perm->application = 'IDF'; + $perm->create(); } function IDF_Migrations_Install_teardown($params=null) @@ -70,6 +76,8 @@ function IDF_Migrations_Install_teardown($params=null) if ($perm) $perm->delete(); $perm = Pluf_Permission::getFromString('IDF.project-owner'); if ($perm) $perm->delete(); + $perm = Pluf_Permission::getFromString('IDF.project-authorized-user'); + if ($perm) $perm->delete(); $models = array( 'IDF_WikiRevision', 'IDF_WikiPage',