Skip to content

Commit 666c87b

Browse files
author
root
committed
Small refactoring
1 parent 8438ede commit 666c87b

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

Diff for: lib/redmine_git_hosting/gitolite_wrappers/global/common.rb

+17
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ def rw_access_perms
3232
[permissions]
3333
end
3434

35+
36+
def repo_conf
37+
all_repository_config
38+
end
39+
40+
41+
def perms
42+
repo_conf.permissions.select { |p| p.has_key? 'RW+' }
43+
end
44+
45+
46+
# RedmineGitHosting key can act on any refspec ('') so it should be in that 'subgroup'
47+
#
48+
def users
49+
perms[0]['RW+']['']
50+
end
51+
3552
end
3653
end
3754
end

Diff for: lib/redmine_git_hosting/gitolite_wrappers/global/disable_rw_access.rb

-6
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,11 @@ def call
1919

2020

2121
def remove_redmine_key
22-
repo_conf = all_repository_config
23-
24-
# RedmineGitHosting key must be in RW+ group
25-
perms = repo_conf.permissions.select{ |p| p.has_key? 'RW+' }
26-
2722
# RedmineGitHosting key must be in [RW+][''] group
2823
# Return if those groups are absent : it means that our key is not here
2924
return if perms.empty? || !perms[0]['RW+'].include?('')
3025

3126
# Check for key presence
32-
users = perms[0]['RW+']['']
3327
return if !users.include?(redmine_gitolite_key)
3428

3529
# Delete the key

Diff for: lib/redmine_git_hosting/gitolite_wrappers/global/enable_rw_access.rb

+1-14
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,17 @@ def call
2222

2323

2424
def add_redmine_key
25-
repo_conf = all_repository_config
26-
2725
# RedmineGitHosting key must be in RW+ group
28-
perms = repo_conf.permissions.select{ |p| p.has_key? 'RW+' }
29-
3026
# If not create the RW+ group and add the key
3127
if perms.empty?
3228
logger.info("#{context} : No permissions set for '@all' repository, add RedmineGitHosting key")
3329
repo_conf.permissions = rw_access_perms
34-
return
35-
end
36-
37-
# RedmineGitHosting key can act on any refspec ('') so it should be it that 'subgroup'
38-
users = perms[0]['RW+']['']
39-
40-
# If not create it
41-
if users.nil?
30+
elsif users.nil?
4231
logger.info("#{context} : RedmineGitHosting key is not present, add it !")
4332
repo_conf.permissions[0]['RW+'][''] = [redmine_gitolite_key]
44-
# Check that the 'subgroup' contains our key
4533
elsif !users.include?(redmine_gitolite_key)
4634
logger.info("#{context} : RedmineGitHosting key is not present, add it !")
4735
repo_conf.permissions[0]['RW+'][''].push(redmine_gitolite_key)
48-
# Our key already here, nothing to do
4936
else
5037
logger.info("#{context} : RedmineGitHosting key is present, nothing to do.")
5138
end

0 commit comments

Comments
 (0)