diff --git a/src/IDF/Form/SourceConf.php b/src/IDF/Form/SourceConf.php new file mode 100644 index 0000000..6119233 --- /dev/null +++ b/src/IDF/Form/SourceConf.php @@ -0,0 +1,92 @@ +conf = $extra['conf']; + $this->fields['scm'] = new Pluf_Form_Field_Varchar( + array('required' => true, + 'label' => __('Repository type'), + 'initial' => $this->conf->getVal('scm', 'git'), + 'widget_attrs' => array('choices' => + array( + __('git') => 'git', + __('Subversion') => 'svn', + ) + ), + 'widget' => 'Pluf_Form_Widget_SelectInput', + )); + $this->fields['svn_remote_url'] = new Pluf_Form_Field_Varchar( + array('required' => false, + 'label' => __('Remote Subversion repository'), + 'initial' => $this->conf->getVal('svn_remote_url', ''), + 'widget_attrs' => array('size' => '30'), + )); + + $this->fields['svn_username'] = new Pluf_Form_Field_Varchar( + array('required' => false, + 'label' => __('Repository username'), + 'initial' => $this->conf->getVal('svn_username', ''), + 'widget_attrs' => array('size' => '15'), + )); + + $this->fields['svn_password'] = new Pluf_Form_Field_Varchar( + array('required' => false, + 'label' => __('Repository password'), + 'initial' => $this->conf->getVal('svn_password', ''), + 'widget' => 'Pluf_Form_Widget_PasswordInput', + )); + } + + public function clean_svn_remote_url() + { + $url = trim($this->cleaned_data['svn_remote_url']); + if (strlen($url) == 0) return $url; + // we accept only starting with http(s):// to avoid people + // trying to access the local filesystem. + if (!preg_match('#^(http|https)://#', $url)) { + throw new Pluf_Form_Invalid(__('Only a remote repository available throught http or https are allowed. For example "http://somewhere.com/sv/trunk.')); + } + return $url; + } + + public function clean() + { + if ($this->cleaned_data['scm'] == 'git') { + foreach (array('svn_remote_url', 'svn_username', 'svn_password') + as $key) { + $this->cleaned_data[$key] = ''; + } + } + return $this->cleaned_data; + } +} + + diff --git a/src/IDF/Views/Project.php b/src/IDF/Views/Project.php index 018ea7a..8ba02c9 100644 --- a/src/IDF/Views/Project.php +++ b/src/IDF/Views/Project.php @@ -249,4 +249,49 @@ class IDF_Views_Project ), $request); } + + /** + * Administrate the source control. + */ + public $adminSource_precond = array('IDF_Precondition::projectOwner'); + public function adminSource($request, $match) + { + $prj = $request->project; + $title = sprintf(__('%s Source'), (string) $prj); + $extra = array( + 'conf' => $request->conf, + ); + if ($request->method == 'POST') { + $form = new IDF_Form_SourceConf($request->POST, $extra); + if ($form->isValid()) { + foreach ($form->cleaned_data as $key=>$val) { + $request->conf->setVal($key, $val); + } + $request->user->setMessage(__('The project source configuration has been saved.')); + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Project::adminSource', + array($prj->shortname)); + return new Pluf_HTTP_Response_Redirect($url); + } + } else { + $params = array(); + $keys = array('scm', 'svn_remote_url', + 'svn_username', 'svn_password'); + foreach ($keys as $key) { + $_val = $request->conf->getVal($key, false); + if ($_val !== false) { + $params[$key] = $_val; + } + } + if (count($params) == 0) { + $params = null; //Nothing in the db, so new form. + } + $form = new IDF_Form_SourceConf($params, $extra); + } + return Pluf_Shortcuts_RenderToResponse('admin/source.html', + array( + 'page_title' => $title, + 'form' => $form, + ), + $request); + } } \ No newline at end of file diff --git a/src/IDF/conf/views.php b/src/IDF/conf/views.php index 01ecac1..0c8282b 100644 --- a/src/IDF/conf/views.php +++ b/src/IDF/conf/views.php @@ -242,6 +242,12 @@ $ctl[] = array('regex' => '#^/p/(\w+)/admin/downloads/$#', 'model' => 'IDF_Views_Project', 'method' => 'adminDownloads'); +$ctl[] = array('regex' => '#^/p/(\w+)/admin/source/$#', + 'base' => $base, + 'priority' => 4, + 'model' => 'IDF_Views_Project', + 'method' => 'adminSource'); + $ctl[] = array('regex' => '#^/p/(\w+)/admin/members/$#', 'base' => $base, 'priority' => 4, diff --git a/src/IDF/templates/admin/base.html b/src/IDF/templates/admin/base.html index 501c2cf..27dccb4 100644 --- a/src/IDF/templates/admin/base.html +++ b/src/IDF/templates/admin/base.html @@ -3,9 +3,10 @@ {block subtabs}
{trans 'Project Summary'} | -{trans 'Project Members'} | {trans 'Issue Tracking'} | {trans 'Downloads'} | +{trans 'Source'} | +{trans 'Project Members'} | {trans 'Tabs Access'}
{/block} diff --git a/src/IDF/templates/admin/source.html b/src/IDF/templates/admin/source.html new file mode 100644 index 0000000..aa4d6a2 --- /dev/null +++ b/src/IDF/templates/admin/source.html @@ -0,0 +1,52 @@ +{extends "admin/base.html"} +{block docclass}yui-t1{assign $inSource = true}{/block} +{block body} +{if $form.errors} +
+

{trans 'The form contains some errors. Please correct them to update the source configuration.'}

+{if $form.get_top_errors} +{$form.render_top_errors|unsafe} +{/if} +
+{/if} +
+ + + + + + + + + + + + + + + + + + + + + +
{$form.f.scm.labelTag}:{if $form.f.scm.errors}{$form.f.scm.fieldErrors}{/if} +{$form.f.scm|unsafe} +
{$form.f.svn_remote_url.labelTag}:{if $form.f.svn_remote_url.errors}{$form.f.svn_remote_url.fieldErrors}{/if} +{$form.f.svn_remote_url|unsafe} +
{$form.f.svn_username.labelTag}:{if $form.f.svn_username.errors}{$form.f.svn_username.fieldErrors}{/if} +{$form.f.svn_username|unsafe} +
{$form.f.svn_password.labelTag}:{if $form.f.svn_password.errors}{$form.f.svn_password.fieldErrors}{/if} +{$form.f.svn_password|unsafe} +
  + +
+
+{/block} +{block context} +
+

{trans 'Instructions:'}

+

{blocktrans}You can select the type of repository you want. In the case of subversion, you can use optionally a remote repository instead of the local one.{/blocktrans}

+
+{/block}