From 5f68ad40e34ab7b3e9432bff2788f2aefc47fd0e Mon Sep 17 00:00:00 2001 From: Tomas Srna Date: Wed, 13 Mar 2013 18:59:36 +0100 Subject: [PATCH 1/8] Fixed the code to be compatible with ruby 1.9.3 and Chiliproject 3.7.0 --- lib/git_adapter_hooks.rb | 4 ++-- lib/git_hosting.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/git_adapter_hooks.rb b/lib/git_adapter_hooks.rb index 0288f122b..85066b61c 100755 --- a/lib/git_adapter_hooks.rb +++ b/lib/git_adapter_hooks.rb @@ -8,7 +8,7 @@ class GitAdapterHooks @@check_hooks_installed_cached = nil def self.check_hooks_installed - if not @@check_hooks_installed_cached.nil? and (Time.new - @@check_hooks_installed_stamp <= 0.5): + if not @@check_hooks_installed_cached.nil? and (Time.new - @@check_hooks_installed_stamp <= 0.5) return @@check_hooks_installed_cached end @@ -22,7 +22,7 @@ def self.check_hooks_installed if (!post_receive_exists) || post_receive_length_is_zero logger.info "\"post-receive\" not handled by gitolite, installing it..." install_hook("post-receive.redmine_gitolite.rb") - logger.info "\"post-receive.redmine_gitolite\ installed" + logger.info "\"post-receive.redmine_gitolite\" installed" logger.info "Running \"gl-setup\" on the gitolite install..." %x[#{GitHosting.git_user_runner} gl-setup] update_global_hook_params diff --git a/lib/git_hosting.rb b/lib/git_hosting.rb index 8bcea3432..adaaef8d0 100755 --- a/lib/git_hosting.rb +++ b/lib/git_hosting.rb @@ -59,7 +59,7 @@ def self.mirror_push_public_key @@sudo_git_to_web_user_stamp = nil @@sudo_git_to_web_user_cached = nil def self.sudo_git_to_web_user - if not @@sudo_git_to_web_user_cached.nil? and (Time.new - @@sudo_git_to_web_user_stamp <= 0.5): + if not @@sudo_git_to_web_user_cached.nil? and (Time.new - @@sudo_git_to_web_user_stamp <= 0.5) return @@sudo_git_to_web_user_cached end logger.info "Testing if git user(\"#{git_user}\") can sudo to web user(\"#{web_user}\")" @@ -83,7 +83,7 @@ def self.sudo_git_to_web_user @@sudo_web_to_git_user_stamp = nil @@sudo_web_to_git_user_cached = nil def self.sudo_web_to_git_user - if not @@sudo_web_to_git_user_cached.nil? and (Time.new - @@sudo_web_to_git_user_stamp <= 0.5): + if not @@sudo_web_to_git_user_cached.nil? and (Time.new - @@sudo_web_to_git_user_stamp <= 0.5) return @@sudo_web_to_git_user_cached end logger.info "Testing if web user(\"#{web_user}\") can sudo to git user(\"#{git_user}\")" From 7a4125bb32f138bd1dda7c56ad1a36de2fb7ac05 Mon Sep 17 00:00:00 2001 From: Tomas Srna Date: Sat, 30 Mar 2013 21:45:06 +0100 Subject: [PATCH 2/8] Tomas Srna: Delayed Jobs + ACL visualization --- Gemfile | 10 ++- README.mkd | 5 ++ Rakefile | 9 +- app/controllers/git_http_controller.rb | 3 +- app/models/git_hosting_observer.rb | 11 ++- app/views/projects/_git_urls.erb | 85 +++++++++---------- app/views/repositories/_git_urls.erb | 22 +++-- assets/javascripts/git_url_display.js | 5 +- assets/stylesheets/git_url_display.css | 2 +- .../20130328000000_repository_update_time.rb | 12 +++ init.rb | 18 ++-- lib/git_hosting.rb | 36 ++++++-- lib/git_hosting/patches/git_adapter_patch.rb | 2 +- {tasks => lib/tasks}/gitolite.rake | 0 14 files changed, 142 insertions(+), 78 deletions(-) create mode 100644 db/migrate/20130328000000_repository_update_time.rb rename {tasks => lib/tasks}/gitolite.rake (100%) diff --git a/Gemfile b/Gemfile index 7d87e7a5a..4d483df2e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,6 @@ -source :rubygems -gem "inifile", "~>0.4.1" -gem "lockfile", "~>1.4.3" -gem "net-ssh", "~>2.1.4" +source 'https://rubygems.org' +gem 'inifile', '~>0.4.1' +gem 'lockfile', '~>1.4.3' +gem 'net-ssh', '~>2.1.4' +gem 'delayed_job', '=2.0.4' + diff --git a/README.mkd b/README.mkd index 945b9cf82..6f8c0b31b 100755 --- a/README.mkd +++ b/README.mkd @@ -1,3 +1,8 @@ +# Redmine Git Hosting Plugin with Delayed Jobs (v0.5.0) + +Added support for delayed_jobs ACL update and improved visualization of access rights. +-- Tomas Srna + # Redmine Git Hosting Plugin (v0.4.2) A ChiliProject / Redmine plugin which makes configuring your own git hosting easy. This plugin allows straightforward management diff --git a/Rakefile b/Rakefile index 57de66cb6..510d4ef4e 100644 --- a/Rakefile +++ b/Rakefile @@ -3,5 +3,12 @@ begin require 'lockfile' require 'net/ssh' rescue - puts "need to install tmpdir lockfile and net/ssh gems" + puts 'need to install tmpdir lockfile and net/ssh gems' +end + +begin + gem 'delayed_job', '~>2.0.4' + require 'delayed/tasks' +rescue LoadError + STDERR.puts 'Run `rake gems:install` to install delayed_job' end diff --git a/app/controllers/git_http_controller.rb b/app/controllers/git_http_controller.rb index b5faaba1a..bf2d41fcf 100644 --- a/app/controllers/git_http_controller.rb +++ b/app/controllers/git_http_controller.rb @@ -10,7 +10,6 @@ class GitHttpController < ApplicationController before_filter :authenticate - def index p1 = params[:p1] p2 = params[:p2] @@ -241,7 +240,7 @@ def update_server_info end def git_command(command) - return "#{run_git_prefix()} env GL_BYPASS_UPDATE_HOOK=true git #{command} '" + return "#{run_git_prefix()} GL_BYPASS_UPDATE_HOOK=true GL_LIBDIR=\"/etc/perl\" git #{command} '" end diff --git a/app/models/git_hosting_observer.rb b/app/models/git_hosting_observer.rb index 8b8de5462..defcbc2b2 100644 --- a/app/models/git_hosting_observer.rb +++ b/app/models/git_hosting_observer.rb @@ -75,7 +75,16 @@ def update_repositories(object) end if(projects.length > 0) if (@@updating_active) - GitHosting::update_repositories(projects, false) + #GitHosting::update_repositories(projects, false) + project_pids = projects.collect {|p| p.id} + projects.each do |p| + p.repository.update_requested = Time.new + ua = @@updating_active + @@updating_active = false + p.repository.save + @@updating_active = ua + end + GitHosting.delay.update_repositories_pid(project_pids, false) else @@cached_project_updates.concat(projects) end diff --git a/app/views/projects/_git_urls.erb b/app/views/projects/_git_urls.erb index be2121e58..dabdb863b 100644 --- a/app/views/projects/_git_urls.erb +++ b/app/views/projects/_git_urls.erb @@ -1,53 +1,52 @@ <% if @project.repository && @project.repository.is_a?(Repository::Git) %> <% content_for :header_tags do %> - <%= stylesheet_link_tag('git_url_display', :plugin => 'redmine_git_hosting') %> - <%= javascript_include_tag('git_url_display', :plugin => 'redmine_git_hosting') %> - - <%= stylesheet_link_tag('zero_clipboard', :plugin => 'redmine_git_hosting') %> - <%= javascript_include_tag('ZeroClipboard', :plugin => 'redmine_git_hosting') %> - <%= javascript_include_tag('zero_clipboard_setup', :plugin => 'redmine_git_hosting') %> - - - + <%= stylesheet_link_tag('git_url_display', :plugin => 'redmine_git_hosting') %> + <%= javascript_include_tag('git_url_display', :plugin => 'redmine_git_hosting') %> + + <%= stylesheet_link_tag('zero_clipboard', :plugin => 'redmine_git_hosting') %> + <%= javascript_include_tag('ZeroClipboard', :plugin => 'redmine_git_hosting') %> + <%= javascript_include_tag('zero_clipboard_setup', :plugin => 'redmine_git_hosting') %> + + + <% end %> <% if (project.module_enabled?(:repository) && Setting.plugin_redmine_git_hosting['gitRepositoriesShowUrl'].to_s != "false" ) && ((!User.current.anonymous?) || project.repository.extra[:git_http].to_s != "0" || (project.is_public && project.repository.extra[:git_daemon].to_s != "0" )) %> -
+

Git Repository

-
-
    - <% if !User.current.anonymous? %> -
  • SSH
  • - <% end %> - <% if project.repository.extra[:git_http].to_s != "0" %> -
  • HTTP
  • - <% end %> - <% if project.is_public && project.repository.extra[:git_daemon].to_s != "0" %> -
  • Git
  • - <% end %> -
- - - This URL has Read-Only access. -
+
+
    + <% if !User.current.anonymous? && project.members.find_by_user_id(User.current.id) != nil %> +
  • SSH
  • + <% end %> + <% if project.is_public %> +
  • HTTP Anonymous
  • + <% else %> +
  • HTTP Authenticated
  • + <% end %> +
+ + + This URL has Read-Only access. +
<% end %> <% end %> diff --git a/app/views/repositories/_git_urls.erb b/app/views/repositories/_git_urls.erb index 2bc194b0b..a47468e27 100644 --- a/app/views/repositories/_git_urls.erb +++ b/app/views/repositories/_git_urls.erb @@ -27,18 +27,28 @@ <% end %> + <% + pc = 0 + User.current.gitolite_public_keys.each { |p| pc = pc+1 if p.active == 1 } + flash.now[:warning] = "You have no public key in your profile. SSH protocol will not work." if pc < 1 + + if project.repository.update_finished.nil? || + project.repository.update_requested > project.repository.update_finished + flash.now[:warning] = "Repository access control is being updated. Update requested: " + project.repository.update_requested.to_s + end + %> + <% if (!User.current.anonymous?) || project.repository.extra[:git_http].to_s != "0" || (project.is_public && project.repository.extra[:git_daemon].to_s != "0" ) %>
    - <% if !User.current.anonymous? %> + <% if !User.current.anonymous? && project.members.find_by_user_id(User.current.id) != nil %>
  • SSH
  • <% end %> - <% if project.repository.extra[:git_http].to_s != "0" %> -
  • HTTP
  • + <% if project.is_public %> +
  • HTTP Anonymous
  • + <% else %> +
  • HTTP Authenticated
  • <% end %> - <% if project.is_public && project.repository.extra[:git_daemon].to_s != "0" %> -
  • Git
  • - <% end %>

<% end %> diff --git a/config/locales/cs.yml b/config/locales/cs.yml index 2ce8a4693..ace8fa046 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -1,75 +1,75 @@ -'en': - label_all_git: Automatically Initialize Git Repositories For New Projects - label_delete_git_repositories: Delete Git Repository When Project is Deleted - label_git_server: Gitolite Server Domain - label_http_server: HTTP Server Domain (for git http urls) - label_git_user: Git Username - label_gitolite_identity_public_key_file: Gitolite SSH Identity File (Public Key) - label_gitolite_identity_file: Gitolite SSH Identity File (Private Key) +'cs': + label_all_git: Automaticky inicializovat úložiště pro nové projekty + label_delete_git_repositories: Smazat Git úložiště při smazání projektu + label_git_server: Doména Gitolite Serveru + label_http_server: Doména HTTP Serveru (pro HTTP Git) + label_git_user: Git uživatel + label_gitolite_identity_public_key_file: Gitolite SSH Identity File (veřejný klíč) + label_gitolite_identity_file: Gitolite SSH Identity File (privátní klíč) label_git_repository_base_path: Git Repository Base Path (Relative to git user home) field_git_daemon: Git Daemon field_git_http: Git Smart HTTP - field_notify_cia: Notify CIA.vc + field_notify_cia: Notifikace CIA.vc - label_git_show_urls: "Show checkout URL's" - label_enabled: Enabled - label_disabled: Disabled - label_https_only: HTTPS Only - label_https_and_http: HTTPS and HTTP + label_git_show_urls: "Zobrazit checkout URL" + label_enabled: Povoleno + label_disabled: Zakázáno + label_https_only: Pouze HTTPS + label_https_and_http: HTTPS a HTTP - label_permissions_header: Required Permissions - label_sudo_web_to_git_user: Web user is able to sudo to Git user? - label_sudo_git_to_web_user: Git user is able to sudo to Web user? + label_permissions_header: Potrebná oprávnění + label_sudo_web_to_git_user: Web uživatel může sudo na Git uživatele? + label_sudo_git_to_web_user: Git uživatel může sudo na Web uživatele? - label_copy_to_clipboard: "Copy to clipboard" + label_copy_to_clipboard: "Kopírovat do schránky" label_git_hook_header: Repository Hooks - label_git_hook_debug: Run hooks in Debug mode - label_git_hooks_are_asynchronous: Run hooks asynchronously - label_hook_installed: Hook installed - - label_public_keys: Public keys - label_public_key_new: New public key - field_public_key: Key - notice_public_key_updated: Public key was successfully updated. - notice_public_key_added: Public key was successfully added. - label_key_cannot_be_changed_please_create_new_key: 'The key cannot be altered anymore. However, you can deactivate it and create a new one.' + label_git_hook_debug: Spouštět hooks v Debug módu + label_git_hooks_are_asynchronous: Spouštět hooks asynchronně + label_hook_installed: Hook nainstalován + + label_public_keys: Veřejné klíče + label_public_key_new: Nový veřejný klíč + field_public_key: Klíč + notice_public_key_updated: Veřejný klíč byl aktualizován. + notice_public_key_added: Veřejný klíč byl úspěšně přidán. + label_key_cannot_be_changed_please_create_new_key: 'Klíč není možné měnit. Můžete ho ale deaktivovat a přidat nový.' activerecord: errors: messages: - 'may not be changed': 'may not be changed' + 'may not be changed': 'se nedá měnit' label_git_cache_max_time: Max Cache Time label_git_cache_max_elements: Max Cache Elements label_git_cache_max_size: Max Cache Element Size label_git_cache_parameters: Git Cache Parameters - label_no_public_keys: No Public Keys Defined + label_no_public_keys: Žádné veřejné klíče - project_not_found: 'No project was found with the identifier "%{identifier}"' + project_not_found: 'Žádný projekt s identifikátorem "%{identifier}"' cia_not_enough_permissions: You don't have the required permissions to test CIA.vc notifications. field_notify_cia_test: Test Notification cia_notification_ok: Notification to CIA.vc sent. - label_update_all_hooks: Update ALL repositories hook settings + label_update_all_hooks: Aktualizovat hooks pro všechny projekty - field_private_key: Private Key - field_private_key_warning: "Do not use your own Private Key!
Please generate a new one and upload it to the mirror server." - label_mirror_create: Create Repository Mirror - label_mirror_delete: Delete Repository Mirror - label_mirror_edit: Edit Repository Mirror - mirror_notice_deleted: Mirror was successfully deleted - mirror_notice_created: Mirror was successfully created - mirror_notice_updated: Mirror was successfully updated - mirror_notice_create_failed: Failed to create mirror + field_private_key: Soukromý klíč + field_private_key_warning: "Nepoužívejte soukromý klíč!
Vygenerujte nový a použijte ho na mirror server." + label_mirror_create: Vytvořit mirror úložiště + label_mirror_delete: Smazat mirror úložiště + label_mirror_edit: Upravit mirror úložiště + mirror_notice_deleted: Mirror byl úspěšně smazán + mirror_notice_created: Mirror byl úspěšně vytvořen + mirror_notice_updated: Mirror byl úspěšně aktualizován + mirror_notice_create_failed: Nepodařilo se vytvořit mirror button_push: Push button_push_title: "Push To Mirror" @@ -77,3 +77,10 @@ mirror_push_output_label: 'Output:' mirror_push_sucess: Success. mirror_push_fail: Failed! + + this_url_has: 'Tato adresa má' + access: 'oprávnění' + no_public_key: "Nemáte veřejný klíč v profilu. SSH protokol nebude fungovat." + update_pending: "Oprávnění pro úložiště jsou právě aktualizována. Aktualizace žádána: " + http_auth: 'HTTP Autentifikované' + http_anon: 'HTTP Anonymní' \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 2ce8a4693..be432f8cc 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -77,3 +77,10 @@ mirror_push_output_label: 'Output:' mirror_push_sucess: Success. mirror_push_fail: Failed! + + this_url_has: 'This URL has' + acccess: 'access' + no_public_key: "You have no public key in your profile. SSH protocol will not work." + update_pending: "Repository access control is being updated. Update requested: " + http_auth: 'HTTP Authenticated' + http_anon: 'HTTP Anonymous' From 74d34fbfd2796682f1f59b51741c5dba26846f1a Mon Sep 17 00:00:00 2001 From: Tomas Srna Date: Mon, 1 Apr 2013 21:18:13 +0200 Subject: [PATCH 4/8] A lot of bugfixes --- app/models/cia_notification_mailer.rb | 2 +- app/models/git_hosting_observer.rb | 5 +++- app/models/git_hosting_settings_observer.rb | 2 +- app/views/projects/_git_urls.erb | 11 +++++-- app/views/repositories/_git_urls.erb | 11 +++++-- .../repositories/git_instructions.html.erb | 7 +++++ .../settings/_redmine_git_hosting.html.erb | 1 - assets/javascripts/git_url_display.js | 3 +- config/locales/cs.yml | 4 ++- config/locales/en.yml | 2 ++ ...1081300000_create_git_repository_extras.rb | 2 +- init.rb | 13 ++++---- lib/git_adapter_hooks.rb | 6 +++- lib/git_hosting.rb | 24 +++++++-------- lib/git_hosting/patches/project_patch.rb | 9 ++++++ .../patches/projects_controller_patch.rb | 30 ++----------------- .../patches/repositories_controller_patch.rb | 9 +++--- lib/tasks/gitolite.rake | 12 +++++++- 18 files changed, 87 insertions(+), 66 deletions(-) mode change 100755 => 100644 lib/git_adapter_hooks.rb create mode 100644 lib/git_hosting/patches/project_patch.rb diff --git a/app/models/cia_notification_mailer.rb b/app/models/cia_notification_mailer.rb index eb763b85c..24f2b4fe9 100644 --- a/app/models/cia_notification_mailer.rb +++ b/app/models/cia_notification_mailer.rb @@ -34,7 +34,7 @@ def deliver!(mail = @mail) begin ok, result = rpc_server.call2("hub.deliver", @body) - if ok: + if ok GitHosting.logger.info "RPC Called. OK => #{ok} Result => #{result}" return false end diff --git a/app/models/git_hosting_observer.rb b/app/models/git_hosting_observer.rb index defcbc2b2..49dadbc9f 100644 --- a/app/models/git_hosting_observer.rb +++ b/app/models/git_hosting_observer.rb @@ -71,18 +71,21 @@ def update_repositories(object) when User then projects = object.projects unless is_login_save?(object) when GitolitePublicKey then projects = object.user.projects when Member then projects.push(object.project) - when Role then projects = object.members.map(&:project).flatten.uniq.compact + when Role then projects = object.members.map(&:project).flatten.uniq.compact + when Project then projects.push(object) end if(projects.length > 0) if (@@updating_active) #GitHosting::update_repositories(projects, false) project_pids = projects.collect {|p| p.id} projects.each do |p| + unless p.repository.nil? p.repository.update_requested = Time.new ua = @@updating_active @@updating_active = false p.repository.save @@updating_active = ua + end end GitHosting.delay.update_repositories_pid(project_pids, false) else diff --git a/app/models/git_hosting_settings_observer.rb b/app/models/git_hosting_settings_observer.rb index fee8d8a3f..6d465ddaa 100644 --- a/app/models/git_hosting_settings_observer.rb +++ b/app/models/git_hosting_settings_observer.rb @@ -27,7 +27,7 @@ def after_save(object) all_projects.each do |p| if p.repository.is_a?(Repository::Git) r = p.repository - repo_name= p.parent ? File.join(GitHosting::get_full_parent_path(p, true),p.identifier) : p.identifier + repo_name = p.identifier r.url = File.join(object.value['gitRepositoryBasePath'], "#{repo_name}.git") r.root_url = r.url r.save diff --git a/app/views/projects/_git_urls.erb b/app/views/projects/_git_urls.erb index 433017916..1ac76cf29 100644 --- a/app/views/projects/_git_urls.erb +++ b/app/views/projects/_git_urls.erb @@ -11,7 +11,7 @@