Skip to content

Commit 937c5d3

Browse files
author
root
committed
Move permissions check methods in User model
1 parent 5558fc0 commit 937c5d3

21 files changed

Lines changed: 68 additions & 60 deletions

app/controllers/download_git_revision_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def set_repository
3636

3737

3838
def can_download_git_revision
39-
render_403 unless view_context.user_allowed_to(:download_git_revision, @project)
39+
render_403 unless User.current.allowed_to_download?(@repository)
4040
end
4141

4242

app/controllers/gitolite_public_keys_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def set_user_from_params
7070

7171

7272
def set_user_from_current_user
73-
if User.current.allowed_to?(:create_gitolite_ssh_key, nil, global: true)
73+
if User.current.allowed_to_ssh?
7474
@user = User.current
7575
@redirect_url = url_for(controller: 'gitolite_public_keys', action: 'index')
7676
@cancel_url = url_for(controller: 'my', action: 'account')

app/controllers/repository_deployment_credentials_controller.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,17 @@ def set_current_tab
8585

8686

8787
def can_view_credentials
88-
render_403 unless view_context.user_allowed_to(:view_deployment_keys, @project)
88+
render_403 unless User.current.git_allowed_to?(:view_deployment_keys, @repository)
8989
end
9090

9191

9292
def can_create_credentials
93-
render_403 unless view_context.user_allowed_to(:create_deployment_keys, @project)
93+
render_403 unless User.current.git_allowed_to?(:create_deployment_keys, @repository)
9494
end
9595

9696

9797
def can_edit_credentials
98-
render_403 unless view_context.user_allowed_to(:edit_deployment_keys, @project)
98+
render_403 unless User.current.git_allowed_to?(:edit_deployment_keys, @repository)
9999
end
100100

101101

@@ -142,7 +142,7 @@ def other_deployment_keys
142142

143143

144144
def users_allowed_to_create_deployment_keys
145-
@project.users.select { |user| user != User.current && user.allowed_to?(:create_deployment_keys, @project) }
145+
@project.users.select { |user| user != User.current && user.git_allowed_to?(:create_deployment_keys, @repository) }
146146
end
147147

148148

app/controllers/repository_git_config_keys_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,17 @@ def set_current_tab
7777

7878

7979
def can_view_config_keys
80-
render_403 unless view_context.user_allowed_to(:view_repository_git_config_keys, @project)
80+
render_403 unless User.current.git_allowed_to?(:view_repository_git_config_keys, @repository)
8181
end
8282

8383

8484
def can_create_config_keys
85-
render_403 unless view_context.user_allowed_to(:create_repository_git_config_keys, @project)
85+
render_403 unless User.current.git_allowed_to?(:create_repository_git_config_keys, @repository)
8686
end
8787

8888

8989
def can_edit_config_keys
90-
render_403 unless view_context.user_allowed_to(:edit_repository_git_config_keys, @project)
90+
render_403 unless User.current.git_allowed_to?(:edit_repository_git_config_keys, @repository)
9191
end
9292

9393

app/controllers/repository_git_notifications_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ def set_current_tab
8282

8383

8484
def can_view_git_notifications
85-
render_403 unless view_context.user_allowed_to(:view_repository_git_notifications, @project)
85+
render_403 unless User.current.git_allowed_to?(:view_repository_git_notifications, @repository)
8686
end
8787

8888

8989
def can_create_git_notifications
90-
render_403 unless view_context.user_allowed_to(:create_repository_git_notifications, @project)
90+
render_403 unless User.current.git_allowed_to?(:create_repository_git_notifications, @repository)
9191
end
9292

9393

9494
def can_edit_git_notifications
95-
render_403 unless view_context.user_allowed_to(:edit_repository_git_notifications, @project)
95+
render_403 unless User.current.git_allowed_to?(:edit_repository_git_notifications, @repository)
9696
end
9797

9898

app/controllers/repository_mirrors_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ def set_current_tab
7474

7575

7676
def can_view_mirrors
77-
render_403 unless view_context.user_allowed_to(:view_repository_mirrors, @project)
77+
render_403 unless User.current.git_allowed_to?(:view_repository_mirrors, @repository)
7878
end
7979

8080

8181
def can_create_mirrors
82-
render_403 unless view_context.user_allowed_to(:create_repository_mirrors, @project)
82+
render_403 unless User.current.git_allowed_to?(:create_repository_mirrors, @repository)
8383
end
8484

8585

8686
def can_edit_mirrors
87-
render_403 unless view_context.user_allowed_to(:edit_repository_mirrors, @project)
87+
render_403 unless User.current.git_allowed_to?(:edit_repository_mirrors, @repository)
8888
end
8989

9090

app/controllers/repository_post_receive_urls_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ def set_current_tab
6868

6969

7070
def can_view_post_receive_urls
71-
render_403 unless view_context.user_allowed_to(:view_repository_post_receive_urls, @project)
71+
render_403 unless User.current.git_allowed_to?(:view_repository_post_receive_urls, @repository)
7272
end
7373

7474

7575
def can_create_post_receive_urls
76-
render_403 unless view_context.user_allowed_to(:create_repository_post_receive_urls, @project)
76+
render_403 unless User.current.git_allowed_to?(:create_repository_post_receive_urls, @repository)
7777
end
7878

7979

8080
def can_edit_post_receive_urls
81-
render_403 unless view_context.user_allowed_to(:edit_repository_post_receive_urls, @project)
81+
render_403 unless User.current.git_allowed_to?(:edit_repository_post_receive_urls, @repository)
8282
end
8383

8484

app/controllers/repository_protected_branches_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,17 @@ def set_current_tab
9696

9797

9898
def can_view_protected_branches
99-
render_403 unless view_context.user_allowed_to(:view_repository_protected_branches, @project)
99+
render_403 unless User.current.git_allowed_to?(:view_repository_protected_branches, @repository)
100100
end
101101

102102

103103
def can_create_protected_branches
104-
render_403 unless view_context.user_allowed_to(:create_repository_protected_branches, @project)
104+
render_403 unless User.current.git_allowed_to?(:create_repository_protected_branches, @repository)
105105
end
106106

107107

108108
def can_edit_protected_branches
109-
render_403 unless view_context.user_allowed_to(:edit_repository_protected_branches, @project)
109+
render_403 unless User.current.git_allowed_to?(:edit_repository_protected_branches, @repository)
110110
end
111111

112112

app/helpers/git_hosting_helper.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ def label_with_icon(label, icon, opts = {})
2424
end
2525

2626

27-
def user_allowed_to(permission, project)
28-
if project.active?
29-
return User.current.allowed_to?(permission, project)
30-
else
31-
return User.current.allowed_to?(permission, nil, global: true)
32-
end
33-
end
34-
35-
3627
def plugin_asset_link(plugin_name, asset_name)
3728
File.join(Redmine::Utils.relative_url_root, 'plugin_assets', plugin_name, 'images', asset_name)
3829
end

app/models/concerns/gitolitable_permissions.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,8 @@ def pushable_via_http?
6464
def downloadable?
6565
if git_annex_enabled?
6666
false
67-
elsif project.active?
68-
User.current.allowed_to?(:download_git_revision, project)
6967
else
70-
User.current.allowed_to?(:download_git_revision, nil, global: true)
68+
User.current.allowed_to_download?(self)
7169
end
7270
end
7371

0 commit comments

Comments
 (0)