$this->_addHook('scm_admin_form');
$this->_addHook('scm_add_repo');
$this->_addHook('scm_delete_repo');
+ $this->_addHook('get_scm_repo_list');
$this->_addHook('widget_instance', 'myPageBox', false);
$this->_addHook('widgets', 'widgets', false);
$this->_addHook('activity');
}
return $commits;
}
+
+
+ function get_scm_repo_list(&$params) {
+ $protocol = forge_get_config('use_ssl', 'scmgit')? 'https' : 'http';
+ if (session_loggedin()) {
+ $u = user_get_object(user_getid());
+ $d = $u->getUnixName();
+ }
+
+ $results = array();
+ $res = db_query_params("SELECT unix_group_name, groups.group_id FROM groups
+ JOIN group_plugin ON (groups.group_id=group_plugin.group_id)
+ WHERE groups.status=$1 AND group_plugin.plugin_id=$2
+ ORDER BY unix_group_name", array('A', $this->getID()));
+ while ($arr = db_fetch_array($res)) {
+ if (!forge_check_perm('scm', $arr['group_id'], 'read')) {
+ continue;
+ }
+ $urls = array();
+ if (forge_get_config('use_smarthttp', 'scmgit')) {
+ $urls[] = $protocol.'://'.forge_get_config('scm_host').'/anonscm/git/'.$arr['unix_group_name'].'/'.$arr['unix_group_name'].'.git';
+ }
+ if (session_loggedin()) {
+ if (forge_get_config('use_ssh', 'scmgit')) {
+ $urls[] = 'git+ssh://'.$d.'@' . forge_get_config('scm_host') . forge_get_config('repos_path', 'scmgit') .'/'. $arr['unix_group_name'] .'/'. $arr['unix_group_name'] .'.git';
+ }
+ if (forge_get_config('use_smarthttp', 'scmgit')) {
+ $urls[] = $protocol.'://'.$d.'@'.forge_get_config('scm_host').'/authscm/'.$d.'/git/'.$arr['unix_group_name'].'/'.$arr['unix_group_name'].'.git';
+ }
+ }
+ $results[] = array('group_id' => $arr['group_id'],
+ 'repository_type' => 'git',
+ 'repository_id' => $arr['unix_group_name'].'/git/'.$arr['unix_group_name'],
+ 'repository_urls' => $urls,
+ );
+ }
+ $res = db_query_params("SELECT unix_group_name, groups.group_id, repo_name
+ FROM groups
+ JOIN group_plugin ON (groups.group_id=group_plugin.group_id)
+ JOIN scm_secondary_repos ON (groups.group_id=scm_secondary_repos.group_id)
+ WHERE groups.status=$1 AND group_plugin.plugin_id=$2
+ ORDER BY unix_group_name, repo_name", array('A', $this->getID()));
+ while ($arr = db_fetch_array($res)) {
+ if (!forge_check_perm('scm', $arr['group_id'], 'read')) {
+ continue;
+ }
+ $urls = array();
+ if (forge_get_config('use_smarthttp', 'scmgit')) {
+ $urls[] = $protocol.'://'.forge_get_config('scm_host').'/anonscm/git/'.$arr['unix_group_name'].'/'.$arr['repo_name'].'.git';
+ }
+ if (session_loggedin()) {
+ if (forge_get_config('use_ssh', 'scmgit')) {
+ $urls[] = 'git+ssh://'.$d.'@' . forge_get_config('scm_host') . forge_get_config('repos_path', 'scmgit') .'/'. $arr['unix_group_name'] .'/'. $arr['repo_name'] .'.git';
+ }
+ if (forge_get_config('use_smarthttp', 'scmgit')) {
+ $urls[] = $protocol.'://'.$d.'@'.forge_get_config('scm_host').'/authscm/'.$d.'/git/'.$arr['unix_group_name'].'/'.$arr['repo_name'].'.git';
+ }
+ }
+ $results[] = array('group_id' => $arr['group_id'],
+ 'repository_type' => 'git',
+ 'repository_id' => $arr['unix_group_name'].'/git/'.$arr['repo_name'],
+ 'repository_urls' => $urls,
+ );
+ }
+ $res = db_query_params("SELECT unix_group_name, groups.group_id, user_name
+ FROM groups
+ JOIN group_plugin ON (groups.group_id=group_plugin.group_id)
+ JOIN scm_personal_repos ON (groups.group_id=scm_personal_repos.group_id)
+ JOIN users ON (scm_personal_repos.user_id=users.user_id)
+ WHERE groups.status=$1 AND group_plugin.plugin_id=$2 AND users.status=$3
+ ORDER BY unix_group_name, user_name", array('A', $this->getID(), 'A'));
+ while ($arr = db_fetch_array($res)) {
+ if (!forge_check_perm('scm', $arr['group_id'], 'read')) {
+ continue;
+ }
+ $urls = array();
+ if (forge_get_config('use_smarthttp', 'scmgit')) {
+ $urls[] = $protocol.'://'.forge_get_config('scm_host').'/anonscm/git/'.$arr['unix_group_name'].'/users/'.$arr['user_name'].'.git';
+ }
+ if (session_loggedin()) {
+ if (forge_get_config('use_ssh', 'scmgit')) {
+ $urls[] = 'git+ssh://'.$d.'@' . forge_get_config('scm_host') . forge_get_config('repos_path', 'scmgit') .'/'. $arr['unix_group_name'] .'/users/'. $arr['user_name'] .'.git';
+ }
+ if (forge_get_config('use_smarthttp', 'scmgit')) {
+ $urls[] = $protocol.'://'.$d.'@'.forge_get_config('scm_host').'/authscm/'.$d.'/git/'.$arr['unix_group_name'].'/users/'.$arr['user_name'].'.git';
+ }
+ }
+ $results[] = array('group_id' => $arr['group_id'],
+ 'repository_type' => 'git',
+ 'repository_id' => $arr['unix_group_name'].'/git/users/'.$arr['user_name'],
+ 'repository_urls' => $urls,
+ );
+ }
+
+ foreach ($results as $res) {
+ $params['results'][] = $res;
+ }
+ }
}
// Local Variables:
$this->Plugin($id) ;
$this->name = "softwareheritage";
$this->text = "Software Heritage"; // To show in the tabs, use...
+ $this->_addHook('register_soap');
}
public function register_soap(&$params) {
$uri = 'http://'.forge_get_config('web_host');
$server->wsdl->addComplexType(
- 'SoftwareheritageEntry',
+ 'SoftwareheritageRepositoryInfo',
'complexType',
'struct',
'sequence',
'',
array(
'group_id' => array('name'=>'group_id', 'type' => 'xsd:int'),
- 'section' => array('name'=>'section', 'type' => 'xsd:string'),
- 'ref_id' => array('name'=>'ref_id', 'type' => 'xsd:string'),
- 'subref_id' => array('name'=>'subref_id', 'type' => 'xsd:string'),
- 'description' => array('name'=>'description', 'type' => 'xsd:string'),
- 'activity_date' => array('name'=>'activity_date', 'type' => 'xsd:int')
+ 'repository_id' => array('name'=>'repository_id', 'type' => 'xsd:string'),
+ 'repository_urls' => array('name'=>'repository_urls', 'type' => 'tns:ArrayOfstring'),
+ 'repository_type' => array('name'=>'repository_type', 'type' => 'xsd:string'),
)
);
$server->wsdl->addComplexType(
- 'ArrayOfSoftwareheritageEntry',
+ 'ArrayOfSoftwareheritageRepositoryInfo',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
- array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:SoftwareheritageEntry[]')),
- 'tns:SoftwareheritageEntry');
+ array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:SoftwareheritageRepositoryInfo[]')),
+ 'tns:SoftwareheritageRepositoryInfo');
$server->register(
- 'softwareheritage_getActivity',
- array('session_ser'=>'xsd:string',
- 'begin'=>'xsd:int',
- 'end'=>'xsd:int',
- 'show'=>'tns:ArrayOfstring',),
- array('return'=>'tns:ArrayOfSoftwareheritageEntry'),
+ 'softwareheritage_repositoryList',
+ array('session_ser'=>'xsd:string'),
+ array('return'=>'tns:ArrayOfSoftwareheritageRepositoryInfo'),
$uri,
- $uri.'#softwareheritage_getActivity','rpc','encoded');
+ $uri.'#softwareheritage_repositoryList','rpc','encoded');
}
- function &softwareheritage_getActivity($session_ser,$begin,$end,$show=array()) {
- continue_session($session_ser);
-
- $plugin = plugin_get_object('softwareheritage');
- if (!forge_get_config('use_activity')
- || !$plugin) {
- return new soap_fault ('','softwareheritage_getActivity','Software Heritage not available','Software Heritage not available');
- }
+}
- $ids = array();
- $texts = array();
-
- $results = $plugin->getData($begin,$end,$show,$ids,$texts);
+function &softwareheritage_repositoryList($session_ser) {
+ continue_session($session_ser);
- $keys = array(
- 'group_id',
- 'section',
- 'ref_id',
- 'subref_id',
- 'description',
- 'activity_date',
- );
+ $results = array();
+ $params['results'] = &$results;
+ plugin_hook('get_scm_repo_list',$params);
+ error_log(print_r($params,true));
- $res2 = array();
- foreach ($results as $res) {
- $r = array();
-
- foreach ($keys as $k) {
- $r[$k] = $res[$k];
- }
- $res2[] = $r;
+ $res2 = array();
+ foreach ($results as $res) {
+ if (forge_check_perm('scm',$res['group_id'],'read')) {
+ $res2[] = $res;
}
-
- return $res2;
}
+
+ return $res2;
}
// Local Variables:
--- /dev/null
+<?php
+/**
+ * Copyright 2011, Roland Mas
+ * Copyright 2013, Franck Villaume - TrivialDev
+ * Copyright (C) 2015 Inria (Sylvain Beucler)
+ *
+ * This file is part of FusionForge.
+ *
+ * FusionForge is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ *
+ * FusionForge is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+require_once dirname(dirname(__FILE__)).'/SeleniumForge.php';
+
+class SoftwareHeritage extends FForge_SeleniumTestCase
+{
+ public $fixture = 'projecta';
+
+ function testSoftwareHeritage()
+ {
+ $this->loadAndCacheFixture();
+
+ $this->activatePlugin('softwareheritage');
+ $this->activatePlugin('scmgit');
+
+ $this->open(ROOT);
+ $this->clickAndWait("link=ProjectA");
+ $this->clickAndWait("link=Admin");
+ $this->clickAndWait("link=Tools");
+ $this->clickAndWait("link=Source Code Admin");
+ $this->check("//input[@name='scmengine[]' and @value='scmgit']");
+ $this->clickAndWait("submit");
+
+ $this->type("//input[@name='repo_name']", "other-repo");
+ $this->type("//input[@name='description']", "Description for second repository");
+ $this->clickAndWait("//input[@value='Submit']");
+ $this->assertTextPresent("New repository other-repo registered");
+
+ $this->open(ROOT);
+ $this->clickAndWait("link=ProjectA");
+ $this->clickAndWait("link=SCM");
+ $this->assertTextPresent("other-repo");
+
+ $this->assertTextPresent("Anonymous Access");
+ $this->clickAndWait("link=Request a personal repository");
+ $this->assertTextPresent("You have now requested a personal Git repository");
+
+ // Run the cronjob to create repositories
+ $this->waitSystasks();
+
+
+ // Check SOAP
+
+ $soapclient = new SoapClient(WSDL_URL,
+ array('cache_wsdl' => WSDL_CACHE_NONE,
+ 'trace' => true));
+ $this->assertNotNull($soapclient);
+
+ $userid = FORGE_ADMIN_USERNAME;
+ $passwd = FORGE_ADMIN_PASSWORD;
+
+ $response = $soapclient->login($userid, $passwd);
+ $session = $response;
+ $this->assertNotEquals($session,"");
+
+ // Get repository list as admin
+ $response = $soapclient->softwareheritage_repositoryList($session);
+ $repos = array();
+ foreach ($response as $data) {
+ $repos[$data->repository_id] = $data;
+ }
+ $this->assertTrue(array_key_exists('projecta/git/projecta',$repos));
+ $this->assertEquals(3,count($repos['projecta/git/projecta']->repository_urls));
+ $this->assertTrue(array_key_exists('projecta/git/other-repo',$repos));
+ $this->assertTrue(array_key_exists('projecta/git/users/admin',$repos));
+
+ // Get repository list as anonymous
+ $response = $soapclient->softwareheritage_repositoryList('');
+ $repos = array();
+ foreach ($response as $data) {
+ $repos[$data->repository_id] = $data;
+ }
+ $this->assertTrue(array_key_exists('projecta/git/projecta',$repos));
+ $this->assertEquals(1,count($repos['projecta/git/projecta']->repository_urls));
+ $this->assertTrue(array_key_exists('projecta/git/other-repo',$repos));
+ $this->assertTrue(array_key_exists('projecta/git/users/admin',$repos));
+ }
+}