diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-09-13 16:31:11 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-09-13 16:31:11 +0000 |
commit | cc643ce932b2abdc56c4d1933c02806ca57ddefa (patch) | |
tree | eeaaba02f0eee8ce2d06a10609ccffebdfb1ee4d /extra | |
parent | 6ef6459630cfd8fd5af31d527c0043243ef2cb09 (diff) | |
download | redmine-cc643ce932b2abdc56c4d1933c02806ca57ddefa.tar.gz redmine-cc643ce932b2abdc56c4d1933c02806ca57ddefa.zip |
Merged nbc branch @ r1812 (commit access permission and reposman improvements).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1814 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'extra')
-rw-r--r-- | extra/svn/Redmine.pm | 15 | ||||
-rwxr-xr-x | extra/svn/reposman.pl | 142 | ||||
-rwxr-xr-x | extra/svn/reposman.rb | 109 |
3 files changed, 74 insertions, 192 deletions
diff --git a/extra/svn/Redmine.pm b/extra/svn/Redmine.pm index 2619196c7..a15b482e8 100644 --- a/extra/svn/Redmine.pm +++ b/extra/svn/Redmine.pm @@ -148,11 +148,12 @@ sub RedmineDSN { my ($self, $parms, $arg) = @_; $self->{RedmineDSN} = $arg; my $query = "SELECT - hashed_password, auth_source_id - FROM members, projects, users + hashed_password, auth_source_id, permissions + FROM members, projects, users, roles WHERE projects.id=members.project_id AND users.id=members.user_id + AND roles.id=members.role_id AND users.status=1 AND login=? AND identifier=? "; @@ -277,9 +278,11 @@ sub is_member { $sth->execute($redmine_user, $project_id); my $ret; - while (my @row = $sth->fetchrow_array) { - unless ($row[1]) { - if ($row[0] eq $pass_digest) { + while (my ($hashed_password, $auth_source_id, $permissions) = $sth->fetchrow_array) { + + unless ($auth_source_id) { + my $method = $r->method; + if ($hashed_password eq $pass_digest && (defined $read_only_methods{$method} || $permissions =~ /:commit_access/) ) { $ret = 1; last; } @@ -287,7 +290,7 @@ sub is_member { my $sthldap = $dbh->prepare( "SELECT host,port,tls,account,account_password,base_dn,attr_login from auth_sources WHERE id = ?;" ); - $sthldap->execute($row[1]); + $sthldap->execute($auth_source_id); while (my @rowldap = $sthldap->fetchrow_array) { my $ldap = Authen::Simple::LDAP->new( host => ($rowldap[2] == 1 || $rowldap[2] eq "t") ? "ldaps://$rowldap[0]" : $rowldap[0], diff --git a/extra/svn/reposman.pl b/extra/svn/reposman.pl deleted file mode 100755 index b8ce8f8af..000000000 --- a/extra/svn/reposman.pl +++ /dev/null @@ -1,142 +0,0 @@ -#!/usr/bin/perl -# -# redMine 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. -# -# This program 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. - -use strict; -use SOAP::Lite; -use Getopt::Long; -Getopt::Long::Configure ("bundling", "no_auto_abbrev", "no_ignore_case"); -use Pod::Usage; -use vars qw/$VERSION/; - -$VERSION = "1.0"; - -my $warning = "This program is now deprecated. Use the reposman.rb for new features"; -print STDERR "*" x length($warning), "\n", - $warning, "\n", - "*" x length($warning), "\n\n"; - -my %opts = (verbose => 0); -GetOptions(\%opts, 'verbose|v+', 'version|V', 'help|h', 'man|m', 'quiet|q', 'svn-dir|s=s', 'redmine-host|r=s') or pod2usage(2); - -die "$VERSION\n" if $opts{version}; -pod2usage(1) if $opts{help}; -pod2usage( -verbose => 2 ) if $opts{man}; - -my $repos_base = $opts{'svn-dir'}; -my $redmine_host = $opts{'redmine-host'}; - -pod2usage(2) unless $repos_base and $redmine_host; - -unless (-d $repos_base) { - Log(text => "$repos_base doesn't exist", exit => 1); -} - -Log(level => 1, text => "querying redMine for projects..."); -my $wdsl = "http://$redmine_host/sys/service.wsdl"; -my $service = SOAP::Lite->service($wdsl); - -my $projects = $service->Projects(''); -my $project_count = @{$projects}; -Log(level => 1, text => "retrieved $project_count projects"); - -foreach my $project (@{$projects}) { - Log(level => 1, text => "treating project $project->{name}"); - my $repos_name = $project->{identifier}; - - if ($repos_name eq "") { - Log(text => "\tno identifier for project $project->{name}"); - next; - } - - unless ($repos_name =~ /^[a-z0-9\-]+$/) { - Log(text => "\tinvalid identifier for project $project->{name}"); - next; - } - - my $repos_path = "$repos_base/$repos_name"; - - if (-e $repos_path) { - # check unix right and change them if needed - my $other_read = (stat($repos_path))[2] & 00007; - my $right; - - if ($project->{is_public} and not $other_read) { - $right = "0775"; - } elsif (not $project->{is_public} and $other_read) { - $right = "0770"; - } else { - next; - } - - # change mode - system('chmod', '-R', $right, $repos_path) == 0 or - warn("\tunable to change mode on $repos_path : $?\n"), next; - - Log(text => "\tmode change on $repos_path"); - - } else { - # change umask to suit the repository's privacy - $project->{is_public} ? umask 0002 : umask 0007; - - # create the repository - system('svnadmin', 'create', $repos_path) == 0 or - warn("\tsystem svnadmin failed unable to create $repos_path\n"), next; - - # set the group owner - system('chown', '-R', "root:$repos_name", $repos_path) == 0 or - warn("\tunable to create $repos_path : $?\n"), next; - - Log(text => "\trepository $repos_path created"); - } -} - - -sub Log { - my %args = (level => 0, text => '', @_); - - my $level = delete $args{level}; - my $text = delete $args{text}; - return unless $level <= $opts{verbose}; - return if $opts{quiet}; - print "$text\n"; - - exit $args{exit} - if defined $args{exit}; -} - - -__END__ - -=head1 NAME - - reposman - manages your svn repositories with redMine - -=head1 SYNOPSIS - - reposman [options] arguments - example: reposman --svn-dir=/var/svn --redmine-host=redmine.mydomain.foo - reposman -s /var/svn -r redmine.mydomain.foo - -=head1 ARGUMENTS - - -s, --svn-dir=DIR use DIR as base directory for svn repositories - -r, --redmine-host=HOST assume redMine is hosted on HOST - -=head1 OPTIONS - - -v verbose - -V print version and exit - diff --git a/extra/svn/reposman.rb b/extra/svn/reposman.rb index 0b476cdc4..76804d650 100755 --- a/extra/svn/reposman.rb +++ b/extra/svn/reposman.rb @@ -6,52 +6,49 @@ # # == Usage # -# reposman [ -h | --help ] [ -v | --verbose ] [ -V | --version ] [ -q | --quiet ] -s /var/svn -r redmine.host.org -# example: reposman --svn-dir=/var/svn --redmine-host=redmine.mydomain.foo -# reposman -s /var/svn -r redmine.mydomain.foo +# reposman [OPTIONS...] -s [DIR] -r [HOST] +# +# Examples: +# reposman --svn-dir=/var/svn --redmine-host=redmine.example.net +# reposman -s /var/svn -r redmine.example.net -u http://svn.example.net # # == Arguments (mandatory) -# -# -s, --svn-dir=DIR -# use DIR as base directory for svn repositories # -# -r, --redmine-host=HOST -# assume Redmine is hosted on HOST. -# you can use : -# * -r redmine.mydomain.foo (will add http://) -# * -r http://redmine.mydomain.foo -# * -r https://mydomain.foo/redmine +# -s, --svn-dir=DIR use DIR as base directory for svn repositories +# -r, --redmine-host=HOST assume Redmine is hosted on HOST. Examples: +# -r redmine.example.net +# -r http://redmine.example.net +# -r https://example.net/redmine # # == Options # -# -o, --owner=OWNER -# owner of the repository. using the rails login allow user to browse -# the repository in Redmine even for private project -# -# -u, --url=URL -# the base url Redmine will use to access your repositories. This -# will be used to register the repository in Redmine so that user -# doesn't need to do anything. reposman will add the identifier to this url : -# -# -u https://my.svn.server/my/reposity/root # if the repository can be access by http -# -u file:///var/svn/ # if the repository is local -# if this option isn't set, reposman won't register the repository -# -# -t, --test -# only show what should be done -# -# -h, --help: -# show help and exit -# -# -v, --verbose -# verbose -# -# -V, --version -# print version and exit -# -# -q, --quiet -# no log -# +# -o, --owner=OWNER owner of the repository. using the rails login +# allow user to browse the repository within +# Redmine even for private project +# -u, --url=URL the base url Redmine will use to access your +# repositories. This option is used to automatically +# register the repositories in Redmine. The project +# identifier will be appended to this url. Examples: +# -u https://example.net/svn +# -u file:///var/svn/ +# if this option isn't set, reposman won't register +# the repositories in Redmine +# -c, --command=COMMAND use this command instead of "svnadmin create" to +# create a repository. This option can be used to +# create non-subversion repositories +# --scm SCM vendor used to register the repository in +# Redmine (default: Subversion). Can be one of the +# other supported SCM: Bazaar, Darcs, Filesystem, +# Git, Mercurial (case sensitive). +# This option should be used when both options --url +# and --command are used. +# -f, --force force repository creation even if the project +# repository is already declared in Redmine +# -t, --test only show what should be done +# -h, --help show help and exit +# -v, --verbose verbose +# -V, --version print version and exit +# -q, --quiet no log require 'getoptlong' require 'rdoc/usage' @@ -59,14 +56,18 @@ require 'soap/wsdlDriver' require 'find' require 'etc' -Version = "1.0" +Version = "1.1" +SUPPORTED_SCM = %w( Subversion Darcs Mercurial Bazaar Git Filesystem ) opts = GetoptLong.new( ['--svn-dir', '-s', GetoptLong::REQUIRED_ARGUMENT], ['--redmine-host', '-r', GetoptLong::REQUIRED_ARGUMENT], ['--owner', '-o', GetoptLong::REQUIRED_ARGUMENT], ['--url', '-u', GetoptLong::REQUIRED_ARGUMENT], + ['--command' , '-c', GetoptLong::REQUIRED_ARGUMENT], + ['--scm', GetoptLong::REQUIRED_ARGUMENT], ['--test', '-t', GetoptLong::NO_ARGUMENT], + ['--force', '-f', GetoptLong::NO_ARGUMENT], ['--verbose', '-v', GetoptLong::NO_ARGUMENT], ['--version', '-V', GetoptLong::NO_ARGUMENT], ['--help' , '-h', GetoptLong::NO_ARGUMENT], @@ -81,6 +82,9 @@ $svn_owner = 'root' $use_groupid = true $svn_url = false $test = false +$command = "svnadmin create" +$force = false +$scm = 'Subversion' def log(text,level=0, exit=false) return if $quiet or level > $verbose @@ -95,8 +99,11 @@ begin when '--redmine-host'; $redmine_host = arg.dup when '--owner'; $svn_owner = arg.dup; $use_groupid = false; when '--url'; $svn_url = arg.dup + when '--scm'; $scm = arg.dup; log("Invalid SCM: #{$scm}", 0, true) unless SUPPORTED_SCM.include?($scm) + when '--command'; $command = arg.dup when '--verbose'; $verbose += 1 when '--test'; $test = true + when '--force'; $force = true when '--version'; puts Version; exit when '--help'; RDoc::usage when '--quiet'; $quiet = true @@ -110,6 +117,12 @@ if $test log("running in test mode") end +# Make sure command is overridden if SCM vendor is not Subversion +if $scm != 'Subversion' && $command == 'svnadmin create' + log("Please use --command option to specify how to create a #{$scm} repository.", 0, true) +end + + $svn_url += "/" if $svn_url and not $svn_url.match(/\/$/) if ($redmine_host.empty? or $repos_base.empty?) @@ -133,7 +146,7 @@ rescue => e log("Unable to connect to #{wsdl_url} : #{e}", 0, true) end -projects = soap.Projects +projects = soap.ProjectsWithRepositoryEnabled if projects.nil? log('no project found, perhaps you forgot to "Enable WS for repository management"', 0, true) @@ -201,6 +214,13 @@ projects.each do |project| log("\tmode change on #{repos_path}"); else + # if repository is already declared in redmine, we don't create + # unless user use -f with reposman + if $force == false and not project.repository.nil? + log("\trepository for project #{project.identifier} already exists in Redmine", 1) + next + end + project.is_public ? File.umask(0002) : File.umask(0007) if $test @@ -211,7 +231,8 @@ projects.each do |project| begin set_owner_and_rights(project, repos_path) do - raise "svnadmin create #{repos_path} failed" unless system("svnadmin", "create", repos_path) + command = "#{$command} #{repos_path}" + raise "#{command} failed" unless system( command ) end rescue => e log("\tunable to create #{repos_path} : #{e}\n") @@ -219,7 +240,7 @@ projects.each do |project| end if $svn_url - ret = soap.RepositoryCreated project.identifier, "#{$svn_url}#{project.identifier}" + ret = soap.RepositoryCreated project.identifier, $scm, "#{$svn_url}#{project.identifier}" if ret > 0 log("\trepository #{repos_path} registered in Redmine with url #{$svn_url}#{project.identifier}"); else |