Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin fails with post 1.3.0 Redmine: Code included to fix (backward compatible) #136

Open
wants to merge 110 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
98cbb85
Added hooks, policy and rakefile to install selinux policy for this p…
kubitron Nov 24, 2011
33aafdd
Performance fix for redmine_git_hosting.
kubitron Nov 24, 2011
10bfd7d
More performance improvements.
kubitron Nov 26, 2011
db30d7e
Rewrite of primary gitolite interface for better resilience.
kubitron Nov 27, 2011
01e8b32
Missed a performance case/source of recursion complaints in the log.
kubitron Nov 27, 2011
fffa1fd
Update of selinux policy for latest version of selinux package. Also
kubitron Jan 4, 2012
2f1c213
Continuing rewrite of redmine_git_hosting to rationalize path handling.
kubitron Jan 11, 2012
5dfa250
Added code to correct for changes in the Redmine 1.3->1.3.1 transition.
kubitron Jan 9, 2012
00aa93d
Add user-edit screen for public_keys and fix security flaw.
kubitron Jan 13, 2012
0740c23
Repair hook parameters for all projects during :resync_all.
kubitron Jan 16, 2012
2c24a71
Allow repair hook functionality to work with older versions of sudo.
kubitron Jan 24, 2012
a472dbe
Added support for ssh port specification in gitServer. Also clarity f…
kubitron Jan 28, 2012
0758cbb
Fix bugs in error path for repository mirror push. Correct status is …
kubitron Jan 29, 2012
7a8523e
Encode username in HTTP URL bar so that resulting URLS are valid for
kubitron Feb 1, 2012
ba2aad5
Fixes for compatibility with Redmine 1.1
kubitron Feb 12, 2012
b091db4
fixes some stray semicolons that broke ruby 1.9
gcymbalski Feb 17, 2012
aabb9a3
Merge pull request #15 from gcymbalski/chiliproject-and-1.9
kubitron Feb 17, 2012
ab4473c
Make temp and scripts directory configurable. Also, add default
kubitron Mar 4, 2012
6c3359c
Update the installation process to explicitly populate the scripts
kubitron Mar 9, 2012
4598cfc
Make sure that log messages flushed to log for rake tasks. Also, mark
kubitron Mar 17, 2012
e8b0554
Recover gracefully from missing git_repository_extra structure. Did
kubitron Mar 19, 2012
d0a385b
Fixed git-daemon support. Now, the "daemon" key is properly added and
kubitron Mar 20, 2012
55ab631
Better error recovery from failure to pull administrative repo.
kubitron Mar 27, 2012
fef6fda
Fixed slight bug: missed case in which removing user from membership
kubitron Mar 28, 2012
2780e79
Fixed post-receive mirror push so that multiple mirrors will be updated.
kubitron Mar 30, 2012
cc371ec
Fixed language tags on localizations.
kubitron Apr 1, 2012
f2c3b7f
Extra protection when defining backward-compatible versions of
kubitron Apr 1, 2012
f0d5d5d
git_httpd_controller fix to deal with null buf (which is possible).
kubitron Apr 2, 2012
3db41c5
Incremented redmine_git_hosting version from 0.4.3x => 0.4.4x.
kubitron Apr 2, 2012
487e907
Added more explicit instructions for configuring gitolite and generating
kubitron Apr 7, 2012
2e23301
Further Compatibility fixes for Redmine 1.1/backward compatibility
kubitron Apr 7, 2012
50fff4b
Fixed weird race condition with cron cleanup of /tmp (such as tmpwatch).
kubitron Apr 23, 2012
72db56c
Incremented redmine_git_hosting version from 0.4.4x => 0.4.5x
kubitron Apr 23, 2012
1aec254
Fixup key identifiers in (rare) case in which login name changes.
kubitron May 31, 2012
5f22e58
Make sure that reset_identifier works with RAILS 3
kubitron Jul 2, 2012
c80bd8e
Fix bug with display of gitolite_public_keys when failing User valida…
kubitron Jul 2, 2012
b857aef
Fixed two cases where user delete did not update gitolite properly:
kubitron Jul 4, 2012
5d2994e
Properly handle the archiving of projects.
kubitron Jul 4, 2012
ba9b833
Initial post-receive urls implementation
xdissent May 21, 2012
8cf6b0c
Add migrations for post-receive urls
xdissent May 21, 2012
d11be44
Fix typo in post-receive urls controller
xdissent May 21, 2012
2575a9a
Typo in repository partial
xdissent May 21, 2012
a80dc09
Ajaxify post-receive url settings
xdissent May 21, 2012
b50d993
Refactor extracting repo info for hooks
xdissent May 21, 2012
fdf2669
Fill out post-receive url payload
xdissent May 21, 2012
4f79cf9
Only count response code 200 as success in post-receive hook
xdissent May 21, 2012
c30210b
POST to post-receive URLs and add en translations
xdissent May 22, 2012
419c5b4
Adding post-receive URL modes
xdissent May 22, 2012
ac97f06
Add GET style hook and missing translation
xdissent May 22, 2012
44480a0
Merge branch 'post-receive'
kubitron Jul 8, 2012
5f0d622
Some fixes to previous merge
kubitron Jul 9, 2012
ca73c30
Added new parameter 'gitForceHooksUpdate'. When true, will replace
kubitron Jul 9, 2012
12d51e7
Remove control characters from key text.
kubitron Jul 14, 2012
e9f4b29
Updated ModalBox to latest version.
kubitron Jul 16, 2012
468ba97
More flexible repository mirror support.
kubitron Jul 16, 2012
c1aeff6
Fixed bug in post-receive hook which prevented multi-ref notification.
kubitron Jul 27, 2012
e158d6c
Rearrange dependencies to prevent failure in testing.
kubitron Jul 19, 2012
008e029
Added the ability to use an alternate gitolite configuration file.
kubitron Jul 27, 2012
946aafc
Remove dispatcher from init file, since this nolonger exists in Rails…
kubitron Jul 27, 2012
c16bbb3
Fix slight errors on 'my_account' page
kubitron Jul 28, 2012
71a5b20
Removed validation of repository mirror url, but enclose url in quotes
kubitron Aug 1, 2012
7a71a7c
Fixed indentation => 4 spaces (far more readable)
kubitron Aug 17, 2012
b46a84f
First take on implementation of deployment credentials.
kubitron Aug 17, 2012
f0884bd
Fix formatting on "my account" page to match more recent changes.
kubitron Aug 17, 2012
7f766a2
Validate global uniqueness of public keys.
kubitron Aug 19, 2012
44cec8e
Relax public key validation for old (possibly non-conforming) keys.
kubitron Aug 20, 2012
ec01acd
Better handling of projects with a disabled repository module.
kubitron Aug 20, 2012
0776212
Remove excess whitespace before validation.
kubitron Aug 23, 2012
1c770d8
Formatting tweak: bigger key text box.
kubitron Aug 23, 2012
468ae98
Incremented redmine_git_hosting version from 0.4.5x => 0.4.6x
kubitron Aug 23, 2012
d512172
Fixed non-standard condition that tripped-up SQLite3.
kubitron Aug 26, 2012
82ac052
First take at integration (basically works for 1 repo).
kubitron Sep 4, 2012
da53403
Working version of cached_shell_redirector, still with debugging.
kubitron Sep 14, 2012
b454d86
Mostly working integration with 1.4. Still with debugging.
kubitron Sep 20, 2012
19bc2cf
Removed much of the debugging for 1.4 port. Some bug and performance …
kubitron Sep 21, 2012
caaeee7
Moved git_caches.proj_identifier => repo_identifier.
kubitron Sep 22, 2012
0525cdc
Some optimizations, fixes, cosmetic changes. Update README & version …
kubitron Sep 26, 2012
0401d62
Fixed bug in update_repositories
kubitron Sep 26, 2012
f19c4a8
Another bug-- didin't combine credentials correctly
kubitron Sep 26, 2012
b445672
Fix in <1.4 options edit.
kubitron Sep 26, 2012
a8fffbf
Fixed check for repo.ident uniqueness when no repositories.
kubitron Sep 26, 2012
81895d3
Fix for user-filter error.
kubitron Sep 27, 2012
ccc124b
Remove references to unneeded model box file: builder.js
kubitron Sep 27, 2012
2591c8f
More updating of compatibility information in README.
kubitron Sep 27, 2012
71ead6f
Add empty sys_helper.rb to deal with Ruby 1.9.3
kubitron Sep 28, 2012
d2c0029
Switch back to using dispatcher in Rails 2 for patches
kubitron Sep 29, 2012
0a2ad16
More disciplined loading of patch files (well defined order).
kubitron Sep 29, 2012
4bea0ea
Removed constraint on Ruby < 1.9.3 from README
kubitron Oct 2, 2012
d729a6c
Don't index repository identifier if doesn't exist
kubitron Oct 8, 2012
028ee9a
Fix migration/undo migration issues associated with changesets.notifi…
kubitron Oct 9, 2012
36f6047
Don't look at repository identifier unless we are in multi-repo mode.
kubitron Oct 9, 2012
54ff944
Fixed other cases that looked at repo identifiers in single-repo mode
kubitron Oct 9, 2012
eb27400
Fixed problem with pre-1.4 update of members.
kubitron Oct 11, 2012
46e6602
Incremented redmine_git_hosting version from 0.4.6x => 0.5.0x
kubitron Oct 13, 2012
53dfa71
PostReceive hook now handle https URLs properly.
kubitron Oct 13, 2012
a959bce
Fixed bad case for pre-1.4 Redmine edit of Git repo
kubitron Oct 15, 2012
d5c9df4
Fix for Ruby 1.9.x: Handle fact that IO.instance_methods can return e…
kubitron Oct 15, 2012
7f5a814
Patches to aid initial migration, suggested by Greg Thornton
kubitron Oct 16, 2012
ae9c759
Fixed case for Redmine < 1.4 with project having no Git repo.
kubitron Oct 16, 2012
845ae5e
Redo migration to deal with PostGreSQL (no rescue)
kubitron Oct 26, 2012
200e128
Make hook work with Ruby 1.9.x
kubitron Oct 27, 2012
64a8818
Incremented redmine_git_hosting version from 0.5.0x => 0.5.1x
kubitron Oct 31, 2012
27f9bb8
Fix an error that occurs while uninstalling from DB
crocket Nov 21, 2012
c2d0bea
Only create initial repo if project successfully created.
kubitron Dec 15, 2012
5fa0e91
Fix to prevent new repo creation from claiming existing repos.
kubitron Dec 15, 2012
4672de8
Remove unneeded whitespace in gitolite config comment
tomka Dec 21, 2012
cd2c757
Merge pull request #98 from tomka/fix/gitolite-config-comment-cleanup
kubitron Dec 27, 2012
512d66c
Fix for quoting with an old sudo.
kubitron Dec 28, 2012
fba1f7e
Fix to allow unrelated administrative keys in the config file.
kubitron Dec 29, 2012
f87f10d
Let repositories/_navigation partial be handled by Redmine.
kubitron Jan 11, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.*.swp
bin/
selinux/tmp/
429 changes: 361 additions & 68 deletions README.mkd

Large diffs are not rendered by default.

262 changes: 262 additions & 0 deletions app/controllers/deployment_credentials_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
class DeploymentCredentialsController < ApplicationController

before_filter :require_login
before_filter :set_user_variable
before_filter :set_repository_variable
before_filter :set_project_variable

before_filter :can_create_credentials, :only => [:create, :create_with_key]
before_filter :can_edit_credentials, :only => [:edit, :update, :destroy]

before_filter :check_xhr_request
before_filter :find_deployment_credential, :except => [:index, :new, :create, :create_with_key]
before_filter :find_key, :except => [:index, :new, :create, :create_with_key]

helper :gitolite_public_keys
include GitolitePublicKeysHelper

layout Proc.new { |controller| controller.request.xhr? ? 'popup' : 'base' }

def index
render_404
end

def create
render_404
end

def create_with_key
@cred = DeploymentCredential.new(params[:deployment_credentials])
@key = nil
if params[:gitolite_public_key] && params[:gitolite_public_key][:id]
@key = GitolitePublicKey.find_by_id(params[:gitolite_public_key][:id])
if @key && !User.current.admin? && (@key.user != User.current)
# Key not owned by current user -- cannot be used
@key = nil
end
end
@key = GitolitePublicKey.new(params[:gitolite_public_key]) if @key.nil?
if request.get?
# display create_with_key view. Find preexisting keys to offer to user
@user_keys = GitolitePublicKey.active.deploy_key.find_all_by_user_id(User.current.id, :order => "title ASC")
@other_keys = []
if User.current.admin?
# Admin can use other's deploy keys as well
deploy_users = @project.users.find(:all, :order =>"login ASC").select {|x| x != User.current && x.allowed_to?(:create_deployment_keys,@project)}
@other_keys = deploy_users.map {|user| user.gitolite_public_keys.active.deploy_key.find(:all, :order => "title ASC")}.flatten
end
@disabled_keys = @repository.deployment_credentials.active.map(&:gitolite_public_key)
if @key.new_record?
@key.title = suggested_title
end
else
if @key.new_record?
@key.key_type = GitolitePublicKey::KEY_TYPE_DEPLOY
@key.user = User.current
elsif @key.key_type != GitolitePublicKey::KEY_TYPE_DEPLOY
# Should never happen through normal interface...
render_403
return
end
@cred.repository = @repository
# If admin, let credential be owned by owner of key...
if User.current.admin?
@[email protected]
else
@cred.user = User.current
end

# Make sure that cred will validate even if key is new.
@cred.gitolite_public_key = @key

GitHostingObserver.set_update_active(false);
@key.valid? # set error messages on key (in case cred is invalid)
if @cred.valid? && @key.save && @cred.save
flash[:notice] = l(:notice_deployment_credential_added, :title=>keylabel(@key),:perm=>@cred[:perm])

redirect_url = success_url
respond_to do |format|
format.html {
redirect_to redirect_url
}
format.js {
render :update do |page|
page.redirect_to redirect_url
end
}
end
else
respond_to do |format|
format.html {
flash[:error] = l(:error_deployment_credential_create_failed)
render :action => "create_with_key"
}
format.js {
render :action => "form_error"
}
end
end
GitHostingObserver.set_update_active(@project);
end
end

def edit
# Credential should already be set.
end

def update
GitHostingObserver.set_update_active(false);

# Can only alter the permissions
if @cred.update_attributes(params[:deployment_credentials])
flash[:notice] = l(:notice_deployment_credential_updated, :title=>keylabel(@key),:perm=>@cred[:perm])

redirect_url = success_url
respond_to do |format|
format.html {
redirect_to redirect_url
}
format.js {
render :update do |page|
page.redirect_to redirect_url
end
}
end
else
respond_to do |format|
format.html {
flash[:error] = l(:error_deployment_credential_update_failed)
render :action => "edit"
}
format.js {
render :action => "form_error"
}
end
end
GitHostingObserver.set_update_active(@project);
end

def destroy
key = @cred.gitolite_public_key
@will_delete_key = key.deploy_key? && key.delete_when_unused && key.deployment_credentials.count == 1
if request.get?
# display confirmation view
else
GitHostingObserver.set_update_active(false);
if params[:confirm]
key = @cred.gitolite_public_key
@cred.destroy
if @will_delete_key && key.deployment_credentials.empty?
# Key no longer used -- delete it!
key.destroy
flash[:notice] = l(:notice_deployment_credential_deleted_with_key, :title=>keylabel(@key),:perm=>@cred[:perm])
else
flash[:notice] = l(:notice_deployment_credential_deleted, :title=>keylabel(@key),:perm=>@cred[:perm])

end
end
redirect_url = success_url
respond_to do |format|
format.html {redirect_to(redirect_url)}
end
GitHostingObserver.set_update_active(@project);
end
end

def settings
end

protected

# This is a success URL to return to basic listing
def success_url
if GitHosting.multi_repos?
url_for(:controller => 'repositories',
:action => 'edit',
:id => @repository.id)
else
url_for(:controller => 'projects',
:action => 'settings',
:id => @project.id,
:tab => 'repository')
end
end

def can_view_credentials
render_403 unless GitHostingHelper.can_view_deployment_keys(@project)
end

def can_create_credentials
render_403 unless GitHostingHelper.can_create_deployment_keys(@project)
end

def can_edit_credentials
render_403 unless GitHostingHelper.can_edit_deployment_keys(@project)
end

def set_user_variable
@user = User.current
end

def set_repository_variable
@repository = Repository.find_by_id(params[:repository_id])
if !@repository
render_404
end
end

def set_project_variable
@project = @repository.project
if !@project
render_404
end
end

def find_deployment_credential
cred = DeploymentCredential.find_by_id(params[:id])
if cred && cred.user && cred.repository && (User.current.admin? || cred.user == User.current)
@cred = cred
elsif cred
render_403
else
render_404
end
end

def find_key
key = @cred.gitolite_public_key
if key && key.user && (User.current.admin? || key.user == User.current)
@key = key
elsif key
render_403
else
render_404
end
end

# Suggest title for new one-of deployment key
def suggested_title
# Base of suggested title
default_title = "#{@project.name} Deploy Key"

# Find number of keys or max default deploy key that matches
maxnum = @repository.deployment_credentials.map(&:gitolite_public_key).uniq.count
@repository.deployment_credentials.each do |cred|
if matches = cred.gitolite_public_key.title.match(/#{default_title} (\d+)$/)
maxnum = [maxnum,matches[1].to_i].max
end
end
# Also, check for uniqueness for current user
@user.gitolite_public_keys.each do |key|
if matches = key.title.match(/#{default_title} (\d+)$/)
maxnum = [maxnum,matches[1].to_i].max
end
end

"#{default_title} #{maxnum+1}"
end

def check_xhr_request
@is_xhr ||= request.xhr?
end
end
Loading