Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit db600b30cdd2398d577eb827ce4fd3c1efa09bc1 @yeah yeah committed Jan 24, 2010
Showing with 905 additions and 0 deletions.
  1. +9 −0 README.rdoc
  2. +74 −0 app/controllers/gitosis_public_keys_controller.rb
  3. +9 −0 app/helpers/gitosis_public_keys_helper.rb
  4. +29 −0 app/models/gitosis_observer.rb
  5. +32 −0 app/models/gitosis_public_key.rb
  6. +9 −0 app/views/gitosis_public_keys/_form.html.erb
  7. +17 −0 app/views/gitosis_public_keys/edit.html.erb
  8. +38 −0 app/views/gitosis_public_keys/index.html.erb
  9. +17 −0 app/views/gitosis_public_keys/new.html.erb
  10. +3 −0 app/views/repositories/git_instructions.html.erb
  11. +13 −0 config/locales/bg.yml
  12. +13 −0 config/locales/bs.yml
  13. +13 −0 config/locales/ca.yml
  14. +13 −0 config/locales/cs.yml
  15. +13 −0 config/locales/da.yml
  16. +15 −0 config/locales/de.yml
  17. +13 −0 config/locales/el.yml
  18. +13 −0 config/locales/en.yml
  19. +13 −0 config/locales/es.yml
  20. +13 −0 config/locales/fi.yml
  21. +13 −0 config/locales/fr.yml
  22. +13 −0 config/locales/gl.yml
  23. +13 −0 config/locales/he.yml
  24. +13 −0 config/locales/hu.yml
  25. +13 −0 config/locales/id.yml
  26. +13 −0 config/locales/it.yml
  27. +13 −0 config/locales/ja.yml
  28. +13 −0 config/locales/ko.yml
  29. +13 −0 config/locales/lt.yml
  30. +13 −0 config/locales/nl.yml
  31. +13 −0 config/locales/no.yml
  32. +13 −0 config/locales/pl.yml
  33. +13 −0 config/locales/pt-BR.yml
  34. +13 −0 config/locales/pt.yml
  35. +13 −0 config/locales/ro.yml
  36. +13 −0 config/locales/ru.yml
  37. +13 −0 config/locales/sk.yml
  38. +13 −0 config/locales/sl.yml
  39. +13 −0 config/locales/sr.yml
  40. +13 −0 config/locales/sv.yml
  41. +13 −0 config/locales/th.yml
  42. +13 −0 config/locales/tr.yml
  43. +13 −0 config/locales/uk.yml
  44. +13 −0 config/locales/vi.yml
  45. +13 −0 config/locales/zh-TW.yml
  46. +13 −0 config/locales/zh.yml
  47. +3 −0 config/routes.rb
  48. +17 −0 db/migrate/20091119162427_create_gitosis_public_keys.rb
  49. +1 −0 extra/ssh/private_key
  50. +2 −0 extra/ssh_with_identity_file.sh
  51. +24 −0 init.rb
  52. +79 −0 lib/gitosis.rb
  53. +31 −0 lib/gitosis/patches/repositories_controller_patch.rb
  54. +17 −0 lib/gitosis/patches/repositories_helper_patch.rb
  55. +9 −0 test/fixtures/gitosis_public_keys.yml
  56. +5 −0 test/test_helper.rb
  57. +10 −0 test/unit/gitosis_public_key_test.rb
@@ -0,0 +1,9 @@
+= Redmine Gitosis
+
+A Redmine plugin which manages your gitosis configuration based on your projects and memberships in Redmine. Includes Public Key management views (extracted from http://plan.io).
+
+This plugin is provided as is and experimental. It works great in production for http://plan.io, but we don't guarantee it will work for you.
+
+== Copyright & License
+
+Copyright (c) 2009-2010 Jan Schulz-Hofen, ROCKET RENTALS GmbH (http://www.rocket-rentals.de). MIT License.
@@ -0,0 +1,74 @@
+class GitosisPublicKeysController < ApplicationController
+
+ before_filter :require_login
+ before_filter :set_user_variable
+ before_filter :find_gitosis_public_key, :except => [:index, :new, :create]
+
+ def index
+ @status = if (session[:gitosis_public_key_filter_status]=params[:status]).nil?
+ GitosisPublicKey::STATUS_ACTIVE
+ elsif params[:status].blank?
+ nil
+ else
+ params[:status].to_i
+ end
+ c = ARCondition.new(@status ? ["active=?", @status] : nil)
+
+ @gitosis_public_keys = @user.gitosis_public_keys.all(:order => 'active DESC, created_at DESC', :conditions => c.conditions)
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render :json => @gitosis_public_keys }
+ end
+ end
+
+ def edit
+ end
+
+ def update
+ if @gitosis_public_key.update_attributes(params[:public_key])
+ flash[:notice] = l(:notice_public_key_updated)
+ redirect_to url_for(:action => 'index', :status => session[:gitosis_public_key_filter_status])
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def new
+ @gitosis_public_key = GitosisPublicKey.new(:user => @user)
+ end
+
+ def create
+ @gitosis_public_key = GitosisPublicKey.new(params[:public_key].merge(:user => @user))
+ if @gitosis_public_key.save
+ flash[:notice] = l(:notice_public_key_added)
+ redirect_to url_for(:action => 'index', :status => session[:gitosis_public_key_filter_status])
+ else
+ render :action => 'new'
+ end
+ end
+
+ def show
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render :json => @gitosis_public_key }
+ end
+ end
+
+ protected
+
+ def set_user_variable
+ @user = User.current
+ end
+
+ def find_gitosis_public_key
+ key = GitosisPublicKey.find_by_id(params[:id])
+ if key and key.user == @user
+ @gitosis_public_key = key
+ elsif key
+ render_403
+ else
+ render_404
+ end
+ end
+
+end
@@ -0,0 +1,9 @@
+module GitosisPublicKeysHelper
+ def gitosis_public_keys_status_options_for_select(user, selected)
+ key_count_by_active = user.gitosis_public_keys.count(:group => 'active').to_hash
+ options_for_select([[l(:label_all), nil],
+ ["#{l(:status_active)} (#{key_count_by_active[true].to_i})", GitosisPublicKey::STATUS_ACTIVE],
+ ["#{l(:status_locked)} (#{key_count_by_active[false].to_i})", GitosisPublicKey::STATUS_LOCKED]], selected)
+ end
+
+end
@@ -0,0 +1,29 @@
+class GitosisObserver < ActiveRecord::Observer
+ observe :project, :user, :gitosis_public_key, :member, :role, :repository
+
+
+ def before_create(object)
+ if object.is_a?(Project)
+ repo = Repository::Git.new
+ repo.url = repo.root_url = File.join(Gitosis::GITOSIS_BASE_PATH,"#{object.identifier}.git")
+ object.repository = repo
+ end
+ end
+
+ def after_save(object) ; update_repositories(object) ; end
+ def after_destroy(object) ; update_repositories(object) ; end
+
+ protected
+
+ def update_repositories(object)
+ case object
+ when Project: Gitosis::update_repositories(object)
+ when Repository: Gitosis::update_repositories(object.project)
+ when User: Gitosis::update_repositories(object.projects)
+ when GitosisPublicKey: Gitosis::update_repositories(object.user.projects)
+ when Member: Gitosis::update_repositories(object.project)
+ when Role: Gitosis::update_repositories(object.members.map(&:project).uniq.compact)
+ end
+ end
+
+end
@@ -0,0 +1,32 @@
+class GitosisPublicKey < ActiveRecord::Base
+
+ STATUS_ACTIVE = 1
+ STATUS_LOCKED = 0
+
+ belongs_to :user
+ validates_uniqueness_of :title, :scope => :user_id
+ validates_uniqueness_of :identifier, :score => :user_id
+ validates_presence_of :title, :key, :identifier
+
+ named_scope :active, {:conditions => {:active => GitosisPublicKey::STATUS_ACTIVE}}
+ named_scope :inactive, {:conditions => {:active => GitosisPublicKey::STATUS_LOCKED}}
+
+ validate :has_not_been_changed
+
+ before_validation :set_identifier
+
+ def has_not_been_changed
+ unless new_record?
+ %w(identifier key user_id).each do |attribute|
+ errors.add(attribute, 'may not be changed') unless changes[attribute].blank?
+ end
+ end
+ end
+
+ def set_identifier
+ self.identifier ||= "#{self.user.login.underscore}-#{self.title.underscore}-#{self.id}".gsub(/[^0-9a-zA-Z-_]/,'_')
+ end
+
+ def to_s ; title ; end
+
+end
@@ -0,0 +1,9 @@
+<div class="box tabular">
+ <p><%= f.text_field :title, :required => true %></p>
+ <p><%= f.text_area :key, :required => true, :disabled => !@gitosis_public_key.new_record?, :style => 'width:99%;height:140px;' %>
+ <% if !@gitosis_public_key.new_record?%>
+ <br/><em><%= l(:label_key_cannot_be_changed_please_create_new_key) %></em>
+ <% end %>
+ </p>
+ <p><%= f.check_box :active %></p>
+</div>
@@ -0,0 +1,17 @@
+<h2><%= link_to l(:label_public_keys), public_keys_path %> &#187; <%= h @gitosis_public_key %></h2>
+
+<%= error_messages_for :gitosis_public_key %>
+
+<% form_for :public_key, @gitosis_public_key, :url => { :action => "update" }, :html => { :method => :put},
+ :builder => TabularFormBuilder,
+ :lang => current_language do |f| %>
+
+ <%= render :partial => 'form', :locals => { :f => f } %>
+ <%= submit_tag l(:button_save) %>
+<% end %>
+
+<% content_for :sidebar do %>
+ <%= render :partial => 'my/sidebar' %>
+<% end %>
+
+<% html_title(l(:label_public_keys)) -%>
@@ -0,0 +1,38 @@
+<h2><%= link_to l(:label_my_account), :controller => 'my', :action => 'account' %> &#187; <%=l(:label_public_keys)%></h2>
+
+<% form_tag({}, :method => :get) do %>
+<fieldset><legend><%= l(:label_filter_plural) %></legend>
+<label><%= l(:field_status) %>:</label>
+<%= select_tag 'status', gitosis_public_keys_status_options_for_select(@user, @status), :class => "small", :onchange => "this.form.submit(); return false;" %>
+<%= submit_tag l(:button_apply), :class => "small", :name => nil %>
+</fieldset>
+<% end %>
+&nbsp;
+
+
+<% if @gitosis_public_keys.any? %>
+
+ <table class="list">
+ <tr>
+ <th><%= l(:field_name) %></th>
+ <th><%= l(:field_created_on) %></th>
+ <th style="width:15%;"><%= l(:field_active) %></th>
+ <th align="center" style="width:10%;"> </th>
+ </tr>
+ <% @gitosis_public_keys.each do |key| %>
+ <tr class="<%= cycle('odd', 'even') %>">
+ <td><%= link_to h(key), :action => 'edit', :id => key %></td>
+ <td><%= format_time(key.created_at) %></td>
+ <td class="center" style="width:15%;"><%= image_tag('true.png') if key.active? %></td>
+ <td class="buttons">
+ <%= link_to l(key.active? ? :button_lock : :button_unlock), public_key_path(key, :public_key => {:active => key.active? ? GitosisPublicKey::STATUS_LOCKED : GitosisPublicKey::STATUS_ACTIVE}), :method => :put, :class => "icon #{key.active? ? 'icon-lock' : 'icon-unlock'}" %>
+ </td>
+ </tr>
+ <% end %>
+ </table>
+
+<% end %>
+
+<p><%= link_to l(:label_enumeration_new), { :action => 'new'} %></p>
+
+<% html_title(l(:label_public_keys)) -%>
@@ -0,0 +1,17 @@
+<h2><%= link_to l(:label_public_keys), public_keys_path %> &#187; <%=l(:label_public_key_new)%></h2>
+
+<%= error_messages_for :gitosis_public_key %>
+
+<% form_for :public_key, @gitosis_public_key, :url => { :action => "create" },
+ :builder => TabularFormBuilder,
+ :lang => current_language do |f| %>
+
+ <%= render :partial => 'form', :locals => { :f => f } %>
+ <%= submit_tag l(:button_create) %>
+<% end %>
+
+<% content_for :sidebar do %>
+ <%= render :partial => 'my/sidebar' %>
+<% end %>
+
+<% html_title(l(:label_public_keys)) -%>
@@ -0,0 +1,3 @@
+<h2><%= l(:label_repository)%></h2>
+<%# This can be used to display basic git setup instructions, like on github... %>
+<% html_title(l(:label_repository)) -%>
@@ -0,0 +1,13 @@
+'bg':
+ label_public_keys: Public keys
+ label_public_key_new: New public key
+ field_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.'
+
+ activerecord:
+ errors:
+ messages:
+ 'may not be changed': 'may not be changed'
@@ -0,0 +1,13 @@
+'bs':
+ label_public_keys: Public keys
+ label_public_key_new: New public key
+ field_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.'
+
+ activerecord:
+ errors:
+ messages:
+ 'may not be changed': 'may not be changed'
@@ -0,0 +1,13 @@
+'ca':
+ label_public_keys: Public keys
+ label_public_key_new: New public key
+ field_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.'
+
+ activerecord:
+ errors:
+ messages:
+ 'may not be changed': 'may not be changed'
@@ -0,0 +1,13 @@
+'cs':
+ label_public_keys: Public keys
+ label_public_key_new: New public key
+ field_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.'
+
+ activerecord:
+ errors:
+ messages:
+ 'may not be changed': 'may not be changed'
@@ -0,0 +1,13 @@
+'da':
+ label_public_keys: Public keys
+ label_public_key_new: New public key
+ field_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.'
+
+ activerecord:
+ errors:
+ messages:
+ 'may not be changed': 'may not be changed'
@@ -0,0 +1,15 @@
+'de':
+ label_public_keys: Öffentliche Schlüssel
+ label_public_key_new: Neuer öffentlicher Schlüssel
+ field_key: Schlüssel
+ notice_public_key_updated: Öffentlicher Schlüssel wurde erfolgreich aktualisiert.
+ notice_public_key_added: Öffentlicher Schlüssel wurde erfolgreich hinzugefügt.
+
+ label_key_cannot_be_changed_please_create_new_key: 'Der Schlüssel kann nicht mehr verändert werden. Sie können jedoch diesen Schlüssel deaktivieren und einen neuen anlegen.'
+
+ activerecord:
+ errors:
+ messages:
+ 'may not be changed': "darf nicht verändert werden"
+
+
@@ -0,0 +1,13 @@
+'el':
+ label_public_keys: Public keys
+ label_public_key_new: New public key
+ field_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.'
+
+ activerecord:
+ errors:
+ messages:
+ 'may not be changed': 'may not be changed'
@@ -0,0 +1,13 @@
+en:
+ label_public_keys: Public keys
+ label_public_key_new: New public key
+ field_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.'
+
+ activerecord:
+ errors:
+ messages:
+ 'may not be changed': 'may not be changed'
@@ -0,0 +1,13 @@
+'es':
+ label_public_keys: Public keys
+ label_public_key_new: New public key
+ field_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.'
+
+ activerecord:
+ errors:
+ messages:
+ 'may not be changed': 'may not be changed'
@@ -0,0 +1,13 @@
+'fi':
+ label_public_keys: Public keys
+ label_public_key_new: New public key
+ field_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.'
+
+ activerecord:
+ errors:
+ messages:
+ 'may not be changed': 'may not be changed'
Oops, something went wrong.

0 comments on commit db600b3

Please sign in to comment.