259afb61e1beb276913606d206a5228d6764b1ba
Author: gwoo
Date: 2009-02-13 11:53:36 -0800
diff --git a/config/templates/svn/permissions.ini b/config/templates/svn/permissions.ini
index cd817ce..6a1b3f4 100644
--- a/config/templates/svn/permissions.ini
+++ b/config/templates/svn/permissions.ini
@@ -3,3 +3,13 @@
[<?php echo @$repo?>]
<?php echo @$username;?> = rw
+
+[groups]
+<?php
+foreach ((array)$groups as $group => $users) {
+ if (!empty($group)) {
+ echo "{$group} = " . join(",", (array)$users);
+ echo "\n";
+ }
+}
+?>
\ No newline at end of file
diff --git a/models/permission.php b/models/permission.php
index 4d69dd5..960d273 100644
--- a/models/permission.php
+++ b/models/permission.php
@@ -88,6 +88,23 @@ class Permission extends AppModel {
if ($config['repo']['type'] == 'git') {
$repo = 'refs/heads/master';
}
+
+ if ($config['repo']['type'] == 'svn') {
+ $perms = $this->find('all', array(
+ 'fields' => array('Permission.group', 'User.username'),
+ 'conditions' => array('Permission.project_id' => $config['id']),
+ 'recursive' => 0
+ ));
+ $groups = array();
+ if (!empty($perms)) {
+ foreach ($perms as $perm) {
+ $groups[$perm['Permission']['group']][] = $perm['User']['username'];
+ }
+ } else {
+ $groups = array_flip(array_keys($this->Project->groups()));
+ }
+ }
+
$username = $this->data['Permission']['username'];
ob_start();
include(CONFIGS . 'templates' . DS . $config['repo']['type'] . DS . 'permissions.ini');
diff --git a/models/project.php b/models/project.php
index 1e94878..49f64e1 100755
--- a/models/project.php
+++ b/models/project.php
@@ -282,7 +282,7 @@ class Project extends AppModel {
$this->Permission->config($this->config);
if ($this->Permission->fileExists() !== true) {
$this->Permission->saveFile(array('Permission' => array(
- 'username' => @$this->data['Project']['username']
+ 'username' => "@admin"
)));
}
@@ -563,9 +563,12 @@ class Project extends AppModel {
**/
function groups($key = null) {
$Inflector = Inflector::getInstance();
- $groups = explode(',', $this->config['groups']);
- $groups = array_map(array($Inflector, 'slug'), $groups, array_fill(0, count($groups), '-'));
- $result = array_combine($groups, $groups);
+ $result = array();
+ if (!empty($this->config['groups'])) {
+ $groups = explode(',', $this->config['groups']);
+ $groups = array_map(array($Inflector, 'slug'), $groups, array_fill(0, count($groups), '-'));
+ $result = array_combine($groups, $groups);
+ }
if (!isset($result['admin'])) {
$result['admin'] = 'admin';
}
diff --git a/plugins/repo/models/git.php b/plugins/repo/models/git.php
index 50b572d..e2d3529 100644
--- a/plugins/repo/models/git.php
+++ b/plugins/repo/models/git.php
@@ -125,7 +125,7 @@ class Git extends Repo {
$Fork = new Folder($userDir, true, $chmod);
}
- $this->clone(array('--bare', $this->path, $this->working));
+ $this->clone(array('--mirror', $this->path, $this->working));
if (is_dir($this->working)) {
if (!empty($options['remote'])) {
@@ -140,7 +140,7 @@ class Git extends Repo {
));
//$this->remote(array('add', 'origin', "{$remote}:forks/{$user}/{$project}"));
$this->pull();
- $this->merge($project);
+ //$this->merge($project);
}
if (is_dir($this->path) && is_dir($this->working)) {
diff --git a/tests/cases/models/permission.test.php b/tests/cases/models/permission.test.php
index b165cab..b44e76d 100644
--- a/tests/cases/models/permission.test.php
+++ b/tests/cases/models/permission.test.php
@@ -52,7 +52,17 @@ class PermissionTest extends CakeTestCase {
'path' => TMP . 'tests' . DS . 'git' . DS . 'repo' . DS . 'forks' . DS . 'bob' . DS . 'project_two.git',
'working' => TMP . 'tests' . DS . 'git' .DS . 'working' . DS . 'forks' . DS . 'bob' . DS . 'project_two'
)
- )
+ ),
+ 'Svn' => array(
+ 'id' => 3,
+ 'url' => 'project_svn',
+ 'groups' => 'user, docs, team, admin',
+ 'repo' => array(
+ 'type' => 'svn',
+ 'path' => TMP . 'tests' . DS . 'svn' . DS . 'repo' . DS . 'project_svn',
+ 'working' => TMP . 'tests' . DS . 'svn' .DS . 'working' . DS . 'project_svn'
+ )
+ ),
);
}
@@ -398,5 +408,44 @@ class PermissionTest extends CakeTestCase {
$result = $Permission->group(1, 2);
$this->assertEqual($result, 'admin');
}
+
+ function testSvnPermissionSave() {
+ Configure::write('Project', $this->__projects['Svn']);
+ $Permission = new TestPermission();
+ $Permission->User->create();
+ $Permission->User->save(array('username' => 'gwoo', 'email' => 'gwoo@test.org'));
+ $Permission->User->create();
+ $Permission->User->save(array('username' => 'bob', 'email' => 'bob@test.org'));
+ $Permission->User->create();
+ $Permission->User->save(array('username' => 'jim', 'email' => 'jim@test.org'));
+
+ $Permission->Project->id = Configure::read('Project.id');
+ $Permission->Project->permit(array(
+ 'user' => 'gwoo', 'group' => 'admin',
+ ));
+ $Permission->Project->permit(array(
+ 'user' => 'bob', 'group' => 'admin',
+ ));
+ $Permission->Project->permit(array(
+ 'user' => 'jim', 'group' => 'user',
+ ));
+ $Permission->config();
+ $Permission->saveFile(array(
+ 'Permission' => array('username' => '@admin'
+ )));
+
+
+ $result = $Permission->groups();
+ $this->assertEqual($result, array(
+ array('Group' => array(
+ 'name' => 'admin',
+ 'users' => array('gwoo', 'bob')
+ )),
+ array('Group' => array(
+ 'name' => 'user',
+ 'users' => array('jim')
+ ))
+ ));
+ }
}
?>
\ No newline at end of file
diff --git a/tests/cases/models/project.test.php b/tests/cases/models/project.test.php
index a48f15a..7ba1882 100644
--- a/tests/cases/models/project.test.php
+++ b/tests/cases/models/project.test.php
@@ -16,7 +16,8 @@ class ProjectTestCase extends CakeTestCase {
'svn' => TMP . 'tests' . DS . 'svn' . DS ,
));
Configure::write('Project', array(
- 'id' => 0
+ 'id' => 0,
+ 'remote' => 'git@git.chaw'
));
$this->Project = ClassRegistry::init('Project');
}
@@ -157,8 +158,6 @@ class ProjectTestCase extends CakeTestCase {
$this->assertTrue($this->Project->save($data));
$this->assertTrue(file_exists($this->Project->Repo->path));
-
-
}
function testProjectFork() {
@@ -189,7 +188,7 @@ class ProjectTestCase extends CakeTestCase {
$this->assertTrue(file_exists($this->Project->Repo->path . DS . 'hooks' . DS . 'post-receive'));
$result = file_get_contents($path . 'permissions.ini');
- $expected = "[admin]\ngwoo = crud\n\n[refs/heads/master]\ngwoo = rw";
+ $expected = "[admin]\n@admin = crud\n\n[refs/heads/master]\n@admin = rw";
$this->assertEqual($result, $expected);
$results = $this->Project->Permission->find('all', array('conditions' => array('Permission.project_id' => 1)));
@@ -261,6 +260,8 @@ class ProjectTestCase extends CakeTestCase {
$this->assertTrue($this->Project->save($data));
$this->Project->id = 1;
+ $this->Project->initialize(array('project' => 'original_project'));
+ $this->Project->set($this->Project->config);
$result = $this->Project->save(array('active' => 1));
$this->assertTrue($result);
@@ -284,6 +285,8 @@ class ProjectTestCase extends CakeTestCase {
$this->assertTrue($this->Project->save($data));
$this->Project->id = 2;
+ $this->Project->initialize(array('project' => 'another_project'));
+ $this->Project->set($this->Project->config);
$result = $this->Project->save(array('active' => 1));
$this->assertTrue($result);
}
@@ -401,10 +404,6 @@ class ProjectTestCase extends CakeTestCase {
}
- function getTests() {
- return array('start', 'startTest', 'testProjectUsers', 'endTest', 'end');
- }
-
function testProjectUsers() {
$this->Project->User->create(array('username' => 'gwoo', 'email' => 'gwoo@test.org'));
$this->assertTrue($this->Project->User->save());
@@ -461,6 +460,39 @@ class ProjectTestCase extends CakeTestCase {
$this->assertEqual($results, array('1'=> 'gwoo', '2' => 'bob'));
}
+ function testApprovedProjectPermissionsCreate() {
+ $data = array('Project' =>array(
+ 'id' => 2,
+ 'name' => 'original project',
+ 'user_id' => 1,
+ 'username' => 'gwoo',
+ 'repo_type' => 'Git',
+ 'private' => 0,
+ 'groups' => 'user, docs team, developer, admin',
+ 'ticket_types' => 'rfc, bug, enhancement',
+ 'ticket_statuses' => 'open, fixed, invalid, needmoreinfo, wontfix',
+ 'ticket_priorities' => 'low, normal, high',
+ 'description' => 'this is a test project',
+ 'active' => 1,
+ 'approved' => 0,
+ 'remote' => 'git@git.chaw'
+ ));
+
+ $this->assertTrue($this->Project->save($data));
+ $path = Configure::read('Content.base');
+ $this->assertFalse(file_exists($path . 'permissions.ini'));
+
+ $project = 'new_project';
+ $this->Project->initialize(compact('project'));
+ $this->assertTrue($this->Project->set($this->Project->config));
+ $this->assertTrue($this->Project->save(array('approved' => 1)));
+ $this->assertTrue(file_exists($this->Project->Repo->path . DS . 'permissions.ini'));
+ }
+
+ function igetTests() {
+ return array('start', 'startTest', 'testApprovedProjectPermissionsCreate', 'endTest', 'end');
+ }
+
function __cleanUp() {
$path = Configure::read('Content.base');
$Cleanup = new Folder(TMP . 'tests/git');
