Skip to content

Commit 7b7e458

Browse files
author
root
committed
Handle Gitolite 'option' directive.
This will permit users to add "option deny-rules = 1" and "option mirror.master" to Gitolite config.
1 parent 0b07e3e commit 7b7e458

File tree

15 files changed

+141
-40
lines changed

15 files changed

+141
-40
lines changed

Diff for: app/controllers/repository_git_config_keys_controller.rb

+16-3
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@ class RepositoryGitConfigKeysController < RedmineGitHostingController
99

1010
def index
1111
@repository_git_config_keys = @repository.git_config_keys.all
12+
@repository_git_option_keys = @repository.git_option_keys.all
1213
render_with_api
1314
end
1415

1516

1617
def new
17-
@git_config_key = @repository.git_config_keys.new
18+
@git_config_key = @repository.git_keys.new
1819
end
1920

2021

2122
def create
22-
@git_config_key = @repository.git_config_keys.new(params[:repository_git_config_key])
23+
@git_config_key = @repository.send(key_type).new(params[:repository_git_config_key])
2324
if @git_config_key.save
2425
flash[:notice] = l(:notice_git_config_key_created)
2526
call_use_case_and_redirect
@@ -48,13 +49,25 @@ def destroy
4849
private
4950

5051

52+
def key_type
53+
case params[:repository_git_config_key][:type]
54+
when 'RepositoryGitConfigKey::Config'
55+
:git_config_keys
56+
when 'RepositoryGitConfigKey::Option'
57+
:git_option_keys
58+
else
59+
:git_keys
60+
end
61+
end
62+
63+
5164
def set_current_tab
5265
@tab = 'repository_git_config_keys'
5366
end
5467

5568

5669
def find_repository_git_config_key
57-
@git_config_key = @repository.git_config_keys.find(params[:id])
70+
@git_config_key = @repository.git_keys.find(params[:id])
5871
rescue ActiveRecord::RecordNotFound => e
5972
render_404
6073
end

Diff for: app/helpers/repository_git_config_keys_helper.rb

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module RepositoryGitConfigKeysHelper
2+
3+
def git_config_key_options
4+
[
5+
[l(:label_git_key_type_config), 'RepositoryGitConfigKey::Config'],
6+
[l(:label_git_key_type_option), 'RepositoryGitConfigKey::Option']
7+
]
8+
end
9+
10+
end

Diff for: app/models/concerns/gitolitable/config.rb

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Gitolitable
22
module Config
33
extend ActiveSupport::Concern
44

5-
def gitolite_config
5+
def git_config
66
repo_conf = {}
77

88
# This is needed for all Redmine repositories
@@ -38,5 +38,16 @@ def gitolite_config
3838
repo_conf
3939
end
4040

41+
42+
def gitolite_options
43+
repo_conf = {}
44+
45+
git_option_keys.each do |option|
46+
repo_conf[option.key] = option.value
47+
end if git_option_keys.any?
48+
49+
repo_conf
50+
end
51+
4152
end
4253
end

Diff for: app/models/repository/xitolite.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ class Repository::Xitolite < Repository::Git
1919
has_many :mirrors, dependent: :destroy, foreign_key: 'repository_id', class_name: 'RepositoryMirror'
2020
has_many :post_receive_urls, dependent: :destroy, foreign_key: 'repository_id', class_name: 'RepositoryPostReceiveUrl'
2121
has_many :deployment_credentials, dependent: :destroy, foreign_key: 'repository_id', class_name: 'RepositoryDeploymentCredential'
22-
has_many :git_config_keys, dependent: :destroy, foreign_key: 'repository_id', class_name: 'RepositoryGitConfigKey'
22+
has_many :git_keys, dependent: :destroy, foreign_key: 'repository_id', class_name: 'RepositoryGitConfigKey'
23+
has_many :git_config_keys, dependent: :destroy, foreign_key: 'repository_id', class_name: 'RepositoryGitConfigKey::Config'
24+
has_many :git_option_keys, dependent: :destroy, foreign_key: 'repository_id', class_name: 'RepositoryGitConfigKey::Option'
2325
has_many :protected_branches, dependent: :destroy, foreign_key: 'repository_id', class_name: 'RepositoryProtectedBranche'
2426

2527
# Additionnal validations

Diff for: app/models/repository_git_config_key.rb

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
class RepositoryGitConfigKey < ActiveRecord::Base
22
unloadable
33

4-
VALID_CONFIG_KEY_REGEX = /\A[a-zA-Z0-9]+\.[a-zA-Z0-9.]+\z/
5-
64
## Attributes
7-
attr_accessible :key, :value
5+
attr_accessible :type, :key, :value
86

97
## Relations
108
belongs_to :repository
119

1210
## Validations
1311
validates :repository_id, presence: true
14-
15-
validates :key, presence: true,
16-
uniqueness: { case_sensitive: false, scope: :repository_id },
17-
format: { with: VALID_CONFIG_KEY_REGEX }
18-
19-
validates :value, presence: true
12+
validates :type, presence: true, inclusion: { in: ['RepositoryGitConfigKey::Config', 'RepositoryGitConfigKey::Option'] }
13+
validates :value, presence: true
2014

2115
## Callbacks
2216
after_save :check_if_key_changed

Diff for: app/models/repository_git_config_key/config.rb

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class RepositoryGitConfigKey::Config < RepositoryGitConfigKey
2+
unloadable
3+
4+
VALID_CONFIG_KEY_REGEX = /\A[a-zA-Z0-9]+\.[a-zA-Z0-9.]+\z/
5+
6+
validates :key, presence: true,
7+
uniqueness: { case_sensitive: false, scope: [:type, :repository_id] },
8+
format: { with: VALID_CONFIG_KEY_REGEX }
9+
10+
end

Diff for: app/models/repository_git_config_key/option.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class RepositoryGitConfigKey::Option < RepositoryGitConfigKey
2+
unloadable
3+
4+
validates :key, presence: true,
5+
uniqueness: { case_sensitive: false, scope: [:type, :repository_id] }
6+
7+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
- if git_config_keys.any?
2+
3+
%table{ class: 'table table-hover' }
4+
%thead
5+
%tr
6+
%th= l(:label_key)
7+
%th= l(:label_value)
8+
%th
9+
10+
%tbody
11+
- git_config_keys.each do |git_config_key|
12+
%tr
13+
%td
14+
%span{ class: 'label label-info' }= git_config_key.key
15+
16+
%td
17+
%span{ class: 'label label-success' }= git_config_key.value
18+
19+
%td{ class: 'buttons' }
20+
- if User.current.git_allowed_to?(:edit_repository_git_config_keys, @repository)
21+
= link_to l(:button_edit), edit_repository_git_config_key_path(@repository, git_config_key), class: 'icon icon-edit modal-box'
22+
= link_to l(:button_delete), repository_git_config_key_path(@repository, git_config_key), remote: true, method: :delete, confirm: l(:text_are_you_sure), class: 'icon icon-del'
23+
24+
- else
25+
%p{ class: 'nodata' }= l(:label_no_data)

Diff for: app/views/repository_git_config_keys/_form.html.haml

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.flash-messages= error_messages_for 'git_config_key'
22

33
.box
4+
%p= f.select :type, options_for_select(git_config_key_options, @git_config_key.type), { required: @git_config_key.new_record?, prompt: 'Select a key type' }, { disabled: !@git_config_key.new_record? }
45
%p= f.text_field :key, required: true, size: 65, label: :label_key
56
%p= f.text_field :value, required: true, size: 65

Diff for: app/views/repository_git_config_keys/index.html.haml

+10-24
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,19 @@
33
- if User.current.git_allowed_to?(:create_repository_git_config_keys, @repository)
44
.contextual= link_to l(:label_git_config_key_add), new_repository_git_config_key_path(@repository), class: 'icon icon-add modal-box'
55

6-
%h3= l(:label_git_config_keys)
6+
%h3
7+
= l(:label_git_config_keys)
8+
= link_to "(#{l(:label_gitolite_documentation)})", 'http://gitolite.com/gitolite/git-config.html', target: '_blank'
79

8-
- if @repository_git_config_keys.any?
10+
= render 'config_keys', git_config_keys: @repository_git_config_keys
911

10-
%table{ class: 'table table-hover' }
11-
%thead
12-
%tr
13-
%th= l(:label_key)
14-
%th= l(:label_value)
15-
%th
16-
17-
%tbody
18-
- @repository_git_config_keys.each do |git_config_key|
19-
%tr
20-
%td
21-
%span{ class: 'label label-info' }= git_config_key.key
22-
23-
%td
24-
%span{ class: 'label label-success' }= git_config_key.value
25-
26-
%td{ class: 'buttons' }
27-
- if User.current.git_allowed_to?(:edit_repository_git_config_keys, @repository)
28-
= link_to l(:button_edit), edit_repository_git_config_key_path(@repository, git_config_key), class: 'icon icon-edit modal-box'
29-
= link_to l(:button_delete), repository_git_config_key_path(@repository, git_config_key), remote: true, method: :delete, confirm: l(:text_are_you_sure), class: 'icon icon-del'
12+
- if User.current.git_allowed_to?(:create_repository_git_config_keys, @repository)
13+
.contextual= link_to l(:label_git_option_key_add), new_repository_git_config_key_path(@repository), class: 'icon icon-add modal-box'
3014

31-
- else
32-
%p{ class: 'nodata' }= l(:label_no_data)
15+
%h3
16+
= l(:label_git_option_keys)
17+
= link_to "(#{l(:label_gitolite_documentation)})", 'http://gitolite.com/gitolite/options.html', target: '_blank'
18+
= render 'config_keys', git_config_keys: @repository_git_option_keys
3319

3420
:javascript
3521
$(document).ready(function() { initModalBoxes(modals); });

Diff for: config/locales/models/repository_git_config_key/en.yml

+6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ en:
33
########### GIT CONFIG KEYS ###########
44
# Basics labels
55
label_git_config_keys: Git Config Keys
6+
label_git_option_keys: Gitolite configuration options
67
label_git_config_key_add: Add Git Config Key
8+
label_git_option_key_add: Add Gitolite option
9+
710
label_git_config_key_create: Create New Git Config Key
811
label_git_config_key_edit: Edit Git Config Key
912
label_git_config_key_delete: Delete Git Config Key
@@ -15,6 +18,9 @@ en:
1518
notice_git_config_key_create_failed: Failed to create Git config key
1619
notice_git_config_key_update_failed: Failed to update Git config key
1720

21+
label_gitolite_documentation: Gitolite Documentation
22+
label_git_key_type_config: Git Config Key
23+
label_git_key_type_option: Gitolite Option
1824
label_key: Key
1925
label_value: Value
2026

Diff for: config/locales/models/repository_git_config_key/fr.yml

+6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ fr:
33
########### GIT CONFIG KEYS ###########
44
# Basics labels
55
label_git_config_keys: Clés de configuration Git
6+
label_git_option_keys: Options de configuration Gitolite
67
label_git_config_key_add: Ajouter une clé de configuration Git
8+
label_git_option_key_add: Ajouter une option de configuration Gitolite
9+
710
label_git_config_key_create: Créer une clé de configuration Git
811
label_git_config_key_edit: Modifier une clé de configuration Git
912
label_git_config_key_delete: Supprimer la clé de configuration Git
@@ -15,6 +18,9 @@ fr:
1518
notice_git_config_key_create_failed: Échec de création de la clé de configuration Git
1619
notice_git_config_key_update_failed: Échec de modification de la clé de configuration Git
1720

21+
label_gitolite_documentation: Documentation Gitolite
22+
label_git_key_type_config: Clé de configuration Git
23+
label_git_key_type_option: Option de configuration Gitolite
1824
label_key: Clé
1925
label_value: Valeur
2026

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class AddTypeFieldToGitConfigKeys < ActiveRecord::Migration
2+
3+
def self.up
4+
add_column :repository_git_config_keys, :type, :string
5+
end
6+
7+
def self.down
8+
remove_column :repository_git_config_keys, :type
9+
end
10+
11+
end
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class RenameGitConfigKeysIndex < ActiveRecord::Migration
2+
3+
def self.up
4+
remove_index :repository_git_config_keys, [:key, :repository_id]
5+
add_index :repository_git_config_keys, [:key, :type, :repository_id], unique: true, name: :unique_key_name
6+
end
7+
8+
def self.down
9+
remove_index :repository_git_config_keys, name: :unique_key_name
10+
add_index :repository_git_config_keys, [:key, :repository_id], unique: true
11+
end
12+
13+
end

Diff for: lib/redmine_git_hosting/gitolite_handlers/repositories/base.rb

+8-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def logger
4040

4141

4242
def backup_old_perms
43-
@old_perms ||= repository.backup_gitolite_permissions(gitolite_repo_conf)
43+
@old_perms = repository.backup_gitolite_permissions(gitolite_repo_conf)
4444
end
4545

4646

@@ -93,9 +93,15 @@ def recreate_repository_config
9393

9494
def build_repository_config
9595
repo_conf = ::Gitolite::Config::Repo.new(repository.gitolite_repository_name)
96-
repository.gitolite_config.each do |key, value|
96+
97+
repository.git_config.each do |key, value|
9798
repo_conf.set_git_config(key, value)
9899
end
100+
101+
repository.gitolite_options.each do |key, value|
102+
repo_conf.set_gitolite_option(key, value)
103+
end
104+
99105
repo_conf
100106
end
101107

0 commit comments

Comments
 (0)