Skip to content

Commit c413400

Browse files
author
root
committed
1 parent 9940b51 commit c413400

File tree

7 files changed

+115
-36
lines changed

7 files changed

+115
-36
lines changed

app/models/concerns/gitolitable/authorizations.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def urls_are_viewable?
4242

4343

4444
def ssh_access_available?
45-
User.current.allowed_to_commit?(self) && !git_annex_enabled?
45+
git_ssh_enabled? && !git_annex_enabled? && User.current.allowed_to_commit?(self)
4646
end
4747

4848

@@ -62,7 +62,7 @@ def git_access_available?
6262

6363

6464
def go_access_available?
65-
(public_project? || public_repo?) && smart_http_enabled?
65+
(public_project? || public_repo?) && smart_http_enabled? && git_go_enabled?
6666
end
6767

6868

app/models/concerns/gitolitable/features.rb

+16-6
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,38 @@ def git_notification_enabled?
3939
end
4040

4141

42-
def smart_http_enabled?
43-
extra[:git_http] != 0
42+
def git_ssh_enabled?
43+
extra[:git_ssh]
44+
end
45+
46+
47+
def git_go_enabled?
48+
extra[:git_go]
4449
end
4550

4651

4752
def https_access_enabled?
48-
extra[:git_http] == 1 || extra[:git_http] == 2
53+
extra[:git_https]
4954
end
5055

5156

5257
def http_access_enabled?
53-
extra[:git_http] == 3 || extra[:git_http] == 2
58+
extra[:git_http]
59+
end
60+
61+
62+
def smart_http_enabled?
63+
https_access_enabled? || http_access_enabled?
5464
end
5565

5666

5767
def only_https_access_enabled?
58-
extra[:git_http] == 1
68+
https_access_enabled? && !http_access_enabled?
5969
end
6070

6171

6272
def only_http_access_enabled?
63-
extra[:git_http] == 3
73+
http_access_enabled? && !https_access_enabled?
6474
end
6575

6676

app/models/repository_git_extra.rb

+9-19
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ class RepositoryGitExtra < ActiveRecord::Base
77
[l(:label_https_and_http), '2']
88
]
99

10-
DISABLED = 0
11-
HTTP = 3
12-
HTTPS = 1
13-
BOTH = 2
14-
1510
ALLOWED_URLS = %w[ssh http https go git git_annex]
1611

1712
URLS_ICONS = {
@@ -24,15 +19,14 @@ class RepositoryGitExtra < ActiveRecord::Base
2419
}
2520

2621
## Attributes
27-
attr_accessible :git_http, :git_daemon, :git_notify, :git_annex, :default_branch, :protected_branch,
22+
attr_accessible :git_http, :git_https, :git_ssh, :git_go, :git_daemon, :git_notify, :git_annex, :default_branch, :protected_branch,
2823
:public_repo, :key, :urls_order, :notification_sender, :notification_prefix
2924

3025
## Relations
3126
belongs_to :repository
3227

3328
## Validations
3429
validates :repository_id, presence: true, uniqueness: true
35-
validates :git_http, presence: true, numericality: { only_integer: true }, inclusion: { in: [DISABLED, HTTP, HTTPS, BOTH] }
3630
validates :default_branch, presence: true
3731
validates :key, presence: true
3832
validates :notification_sender, format: { with: RedmineGitHosting::Validators::EMAIL_REGEX, allow_blank: true }
@@ -82,31 +76,27 @@ def check_if_default_branch_changed
8276
def check_urls_order_consistency
8377
check_ssh_url
8478
check_git_http_urls
85-
# Add go url only for existing record to avoid chicken/egg issue
86-
check_go_url unless new_record?
79+
check_go_url
8780
check_git_url
8881
check_git_annex_url
8982
end
9083

9184

92-
# SSH url should always be present in urls_order Array
93-
#
9485
def check_ssh_url
95-
add_url('ssh')
86+
git_ssh? ? add_url('ssh') : remove_url('ssh')
9687
end
9788

9889

9990
def check_git_http_urls
100-
case git_http
101-
when HTTP
91+
if git_http? && git_https?
10292
add_url('http')
103-
remove_url('https')
104-
when HTTPS
10593
add_url('https')
106-
remove_url('http')
107-
when BOTH
94+
elsif git_http?
10895
add_url('http')
96+
remove_url('https')
97+
elsif git_https?
10998
add_url('https')
99+
remove_url('http')
110100
else
111101
remove_url('http')
112102
remove_url('https')
@@ -115,7 +105,7 @@ def check_git_http_urls
115105

116106

117107
def check_go_url
118-
repository.go_access_available? ? add_url('go') : remove_url('go')
108+
git_go? ? add_url('go') : remove_url('go')
119109
end
120110

121111

app/use_cases/repositories/create.rb

+15-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,26 @@ def enable_git_annex?
2828

2929
def standard_repository_options
3030
{
31-
git_http: RedmineGitHosting::Config.gitolite_http_by_default?,
3231
git_daemon: RedmineGitHosting::Config.gitolite_daemon_by_default?,
3332
git_notify: RedmineGitHosting::Config.gitolite_notify_by_default?,
3433
git_annex: false,
3534
default_branch: 'master',
3635
key: RedmineGitHosting::Utils::Crypto.generate_secret(64)
37-
}
36+
}.merge(smart_http_options)
37+
end
38+
39+
40+
def smart_http_options
41+
case RedmineGitHosting::Config.gitolite_http_by_default?
42+
when '1' # HTTPS only
43+
{ git_https: true }
44+
when '2' # HTTPS and HTTP
45+
{ git_http: true, git_https: true }
46+
when '3' # HTTP only
47+
{ git_http: true }
48+
else
49+
{}
50+
end
3851
end
3952

4053

app/views/repositories/_xitolite_options.html.haml

+18-6
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,19 @@
3030

3131
%p
3232
= label_tag 'repository_git_extra[git_http]', l(:label_enable_smart_http)
33-
= f.select :git_http, options_for_select(RepositoryGitExtra::SMART_HTTP_OPTIONS, selected: repository.extra[:git_http].to_s)
33+
= f.check_box :git_http
3434

3535
%p
36-
= label_tag 'repository_git_extra[default_branch]', l(:label_repository_default_branch)
37-
- if !repository.branches.empty?
38-
= f.select :default_branch, repository_branches_list(repository.branches)
39-
- else
40-
%span{ class: 'label label-info' }= repository.git_default_branch
36+
= label_tag 'repository_git_extra[git_https]', l(:label_enable_smart_https)
37+
= f.check_box :git_https
38+
39+
%p
40+
= label_tag 'repository_git_extra[git_go]', l(:label_enable_go_url)
41+
= f.check_box :git_go
42+
43+
%p
44+
= label_tag 'repository_git_extra[git_ssh]', l(:label_enable_ssh_url)
45+
= f.check_box :git_ssh
4146

4247
.col-md-4
4348
- unless repository.git_annex_enabled?
@@ -57,6 +62,13 @@
5762
.col-md-4
5863

5964
- unless repository.git_annex_enabled?
65+
%p
66+
= label_tag 'repository_git_extra[default_branch]', l(:label_repository_default_branch)
67+
- if !repository.branches.empty?
68+
= f.select :default_branch, repository_branches_list(repository.branches)
69+
- else
70+
%span{ class: 'label label-info' }= repository.git_default_branch
71+
6072
%p
6173
%label= l(:label_mirroring_keys_installed)
6274
= image_tag (RedmineGitHosting::Config.mirroring_keys_installed? ? 'true.png' : 'exclamation.png')

config/locales/models/repository_xitolite/fr.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ fr:
2424
label_repository_options: Options du dépôt
2525
label_enable_git_notify: Activer la liste de diffusion
2626
label_enable_git_daemon: Activer le daemon Git
27-
label_enable_smart_http: Mode Smart HTTP
27+
label_enable_smart_http: Activer SmartHTTP
28+
label_enable_smart_https: Activer SmartHTTPS
29+
label_enable_ssh_url: Afficher l'url SSH
30+
label_enable_go_url: Activer l'url Go
2831
label_enable_protected_branches: Activer les branches protégées
2932
label_enable_public_repo: Rendre le dépôt public
3033
label_git_daemon: Daemon Git
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
class SplitSmartHttp < ActiveRecord::Migration
2+
3+
def self.up
4+
add_column :repository_git_extras, :git_https, :boolean, default: false, after: :git_http
5+
add_column :repository_git_extras, :git_ssh, :boolean, default: true, after: :git_https
6+
add_column :repository_git_extras, :git_go, :boolean, default: false, after: :git_https
7+
8+
add_column :repository_git_extras, :git_http_temp, :boolean, default: false, after: :git_http
9+
10+
RepositoryGitExtra.reset_column_information
11+
12+
RepositoryGitExtra.all.each do |git_extra|
13+
case git_extra[:git_http]
14+
when 1 # HTTPS only
15+
git_extra.update_column(:git_https, true)
16+
when 2 # HTTPS and HTTP
17+
git_extra.update_column(:git_https, true)
18+
git_extra.update_column(:git_http_temp, true)
19+
when # HTTP only
20+
git_extra.update_column(:git_http_temp, true)
21+
end
22+
end
23+
24+
remove_column :repository_git_extras, :git_http
25+
rename_column :repository_git_extras, :git_http_temp, :git_http
26+
end
27+
28+
def self.down
29+
add_column :repository_git_extras, :git_http_temp, :integer, after: :git_http
30+
31+
RepositoryGitExtra.reset_column_information
32+
33+
RepositoryGitExtra.all.each do |git_extra|
34+
if git_extra[:git_https] && git_extra[:git_http]
35+
git_extra.update_column(:git_http_temp, 2)
36+
elsif git_extra[:git_https]
37+
git_extra.update_column(:git_http_temp, 1)
38+
elsif git_extra[:git_http]
39+
git_extra.update_column(:git_http_temp, 3)
40+
end
41+
end
42+
43+
remove_column :repository_git_extras, :git_https
44+
remove_column :repository_git_extras, :git_ssh
45+
remove_column :repository_git_extras, :git_go
46+
47+
remove_column :repository_git_extras, :git_http
48+
rename_column :repository_git_extras, :git_http_temp, :git_http
49+
end
50+
51+
end

0 commit comments

Comments
 (0)