Re: [vhffs-dev] Modify Git Repository Description

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Hi François,

On Tue, Apr 17, 2018 at 12:07:28PM +0200, François Mazen wrote:
> Hello,
> 
> following my request in the forum to modify git repository description
> (https://forum.tuxfamily.org/topic/704/probleme-avec-git/), I've
> investigated a way to add this feature.
> 
> I don't know if this is a popular request, but a diff is attached to this
> message. It adds a description field in the git preference panel and commit
> the modification in the git API. Similar code could be added to the other
> source control type (svn, mercurial, bazaar, cvs).
> The code is small and simple but I'm not a PERL developer, so feel free to
> change my contribution :-)

Great!, thank you very much, applied with some changes, see below.

Sylvain


> diff --git a/vhffs-api/src/Vhffs/Panel/Git.pm b/vhffs-api/src/Vhffs/Panel/Git.pm
> index 338bccf1..9b1e2476 100644
> --- a/vhffs-api/src/Vhffs/Panel/Git.pm
> +++ b/vhffs-api/src/Vhffs/Panel/Git.pm
> @@ -211,6 +211,7 @@ sub save_prefs {
>  
>  	my $public = $cgi->param('public');
>  	my $ml_name = $cgi->param('ml_name');
> +	my $description = Encode::decode_utf8( scalar $cgi->param('description') );
>  
>  	unless( $user->can_modify($git) ) {
>  		$panel->add_error( gettext('You\'re not allowed to do this, object is not in active state or you don\'t have enough ACL rights') );
> @@ -231,6 +232,14 @@ sub save_prefs {
>  		$git->set_status(Vhffs::Constants::WAITING_FOR_MODIFICATION);
>  	}
>  
> +	if(defined $description) {
> +		$git->set_description($description);
> +		$git->set_status(Vhffs::Constants::WAITING_FOR_MODIFICATION);
> +	}
> +	else {
> +		$panel->add_error( gettext('You must enter a description') );
> +	}
> +

We can't set object state to WAITING_FOR_MODIFICATION here. If anything 
next fail we must not redirect the user to the group preference page 
with a successful message, which is what actually happen if object state 
is set to WAITING_FOR_MODIFICATION.

Therefore we need to check all user input before trying to set them, and 
we need to set object state to WAITING_FOR_MODIFICATION last.

I agree it was tricky because the previous code was wrong :-)


>  	if($ml_name =~ /^\s*$/ or Vhffs::Functions::valid_mail($ml_name)) {
>  		if($ml_name ne $git->get_ml_name) {
>  			$git->set_ml_name($ml_name);
> diff --git a/vhffs-panel/templates/scm/prefs.tt b/vhffs-panel/templates/scm/prefs.tt
> index 79881d60..38de3a9f 100644
> --- a/vhffs-panel/templates/scm/prefs.tt
> +++ b/vhffs-panel/templates/scm/prefs.tt
> @@ -7,6 +7,9 @@
>  			<option value="0"[% ' selected="selected"' UNLESS repository.is_public %]>[% 'No' | i18n | html %]</option>
>  		</select>
>  	</p>
> +    <p><label for="description" class="description">[% 'Repository description:' | i18n | html %]</label>
> +        <textarea name="description" id="description" class="description" cols="45" rows="1">[% repository.get_description | html %]</textarea></p>
> +
>  [% IF repository.supports_notifications %]
>  <h2>[% 'Options' | i18n | html %]</h2>
>  	<p>

Attachment: signature.asc
Description: Digital signature



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/