forked from rocket-rentals/redmine-gitosis
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit db600b3
Showing
57 changed files
with
905 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<h2><%= link_to l(:label_public_keys), public_keys_path %> » <%= 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)) -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<h2><%= link_to l(:label_my_account), :controller => 'my', :action => 'account' %> » <%=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 %> | ||
| ||
|
||
|
||
<% 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)) -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<h2><%= link_to l(:label_public_keys), public_keys_path %> » <%=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)) -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.