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

+68
-60
lines changed

Diff for: app/controllers/download_git_revision_controller.rb

+1-1
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

Diff for: app/controllers/gitolite_public_keys_controller.rb

+1-1
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')

Diff for: app/controllers/repository_deployment_credentials_controller.rb

+4-4
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

Diff for: app/controllers/repository_git_config_keys_controller.rb

+3-3
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

Diff for: app/controllers/repository_git_notifications_controller.rb

+3-3
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

Diff for: app/controllers/repository_mirrors_controller.rb

+3-3
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

Diff for: app/controllers/repository_post_receive_urls_controller.rb

+3-3
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

Diff for: app/controllers/repository_protected_branches_controller.rb

+3-3
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

Diff for: app/helpers/git_hosting_helper.rb

-9
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

Diff for: app/models/concerns/gitolitable_permissions.rb

+1-3
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

Diff for: app/models/concerns/gitolitable_urls.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def go_url
6565

6666

6767
def ssh_access
68-
{ url: ssh_url, committer: User.current.allowed_to_commit?(project).to_s }
68+
{ url: ssh_url, committer: User.current.allowed_to_commit?(self).to_s }
6969
end
7070

7171

@@ -76,7 +76,7 @@ def http_access
7676

7777

7878
def https_access
79-
{ url: https_url, committer: User.current.allowed_to_commit?(project).to_s }
79+
{ url: https_url, committer: User.current.allowed_to_commit?(self).to_s }
8080
end
8181

8282

@@ -86,7 +86,7 @@ def git_access
8686

8787

8888
def git_annex_access
89-
{ url: git_annex_url, committer: User.current.allowed_to_commit?(project).to_s }
89+
{ url: git_annex_url, committer: User.current.allowed_to_commit?(self).to_s }
9090
end
9191

9292

Diff for: app/views/repositories/_edit_bottom.html.haml

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
#repository-tabs
44
%ul
5-
- if user_allowed_to(:view_deployment_keys, @repository.project)
5+
- if User.current.git_allowed_to?(:view_deployment_keys, @repository)
66
%li{ id: 'tab-repository_deployment_credentials' }= link_to label_with_icon(l(:label_deployment_credentials), 'fa-lock'), repository_deployment_credentials_path(@repository)
77

8-
- if user_allowed_to(:view_repository_git_notifications, @repository.project)
8+
- if User.current.git_allowed_to?(:view_repository_git_notifications, @repository)
99
%li{ id: 'tab-repository_git_notifications' }= link_to label_with_icon(l(:label_git_notifications), 'fa-bullhorn'), repository_git_notifications_path(@repository)
1010

11-
- if user_allowed_to(:view_repository_mirrors, @repository.project)
11+
- if User.current.git_allowed_to?(:view_repository_mirrors, @repository)
1212
%li{ id: 'tab-repository_mirrors' }= link_to label_with_icon(l(:label_repository_mirrors), 'fa-cloud-upload'), repository_mirrors_path(@repository)
1313

14-
- if user_allowed_to(:view_repository_post_receive_urls, @repository.project)
14+
- if User.current.git_allowed_to?(:view_repository_post_receive_urls, @repository)
1515
%li{ id: 'tab-repository_post_receive_urls' }= link_to label_with_icon(l(:label_post_receive_urls), 'fa-external-link'), repository_post_receive_urls_path(@repository)
1616

17-
- if user_allowed_to(:view_repository_git_config_keys, @repository.project)
17+
- if User.current.git_allowed_to?(:view_repository_git_config_keys, @repository)
1818
%li{ id: 'tab-repository_git_config_keys' }= link_to label_with_icon(l(:label_git_config_keys), 'fa-th-list'), repository_git_config_keys_path(@repository)
1919

20-
- if user_allowed_to(:view_repository_protected_branches, @repository.project)
20+
- if User.current.git_allowed_to?(:view_repository_protected_branches, @repository)
2121
%li{ id: 'tab-repository_protected_branches' }= link_to label_with_icon(l(:label_protected_branches), 'fa-shield'), repository_protected_branches_path(@repository)
2222

2323
= render 'javascript'

Diff for: app/views/repositories/_xitolite_options.html.haml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
= label_tag 'repository_git_extra[git_daemon]', l(:label_enable_git_daemon)
1616
= f.check_box :git_daemon, disabled: (!repository.public_project? && !repository.public_repo?)
1717

18-
- if user_allowed_to(:create_repository_git_notifications, repository.project)
18+
- if User.current.git_allowed_to?(:create_repository_git_notifications, repository)
1919
%p
2020
= label_tag 'repository_git_extra[git_notify]', l(:label_enable_git_notify)
2121
= f.check_box :git_notify
2222

23-
- if user_allowed_to(:create_repository_protected_branches, repository.project)
23+
- if User.current.git_allowed_to?(:create_repository_protected_branches, repository)
2424
%p
2525
= label_tag 'repository_git_extra[protected_branch]', l(:label_enable_protected_branches)
2626
= f.check_box :protected_branch

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%div
22

3-
- if user_allowed_to(:create_deployment_keys, @project)
3+
- if User.current.git_allowed_to?(:create_deployment_keys, @repository)
44
.contextual
55
- css_class = (!@user_keys.empty? || !@other_keys.empty?) ? 'modal-box' : 'modal-box-close-only'
66
= link_to l(:label_deployment_credential_add), new_repository_deployment_credential_path(@repository), class: "icon icon-add #{css_class}"
@@ -38,7 +38,7 @@
3838
%td= checked_image2 credential.active?
3939

4040
%td{ class: 'buttons' }
41-
- if user_allowed_to(:edit_deployment_keys, @project) && (User.current.admin? || User.current == credential.user)
41+
- if User.current.git_allowed_to?(:edit_deployment_keys, @repository) && (User.current.admin? || User.current == credential.user)
4242
= link_to l(:button_edit), edit_repository_deployment_credential_path(@repository, credential), class: 'icon icon-edit modal-box'
4343
= link_to l(:button_delete), repository_deployment_credential_path(@repository, credential), remote: true, method: :delete, confirm: l(:text_are_you_sure), class: 'icon icon-del'
4444
- else

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%div
22

3-
- if user_allowed_to(:create_repository_git_config_keys, @project)
3+
- 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

66
%h3= l(:label_git_config_keys)
@@ -24,7 +24,7 @@
2424
%span{ class: 'label label-success' }= git_config_key.value
2525

2626
%td{ class: 'buttons' }
27-
- if user_allowed_to(:edit_repository_git_config_keys, @project)
27+
- if User.current.git_allowed_to?(:edit_repository_git_config_keys, @repository)
2828
= link_to l(:button_edit), edit_repository_git_config_key_path(@repository, git_config_key), class: 'icon icon-edit modal-box'
2929
= 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'
3030

Diff for: app/views/repository_git_notifications/show.html.haml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
- if @repository.git_notification_enabled?
44
- unless @git_notification.nil?
5-
- if user_allowed_to(:edit_repository_git_notifications, @project)
5+
- if User.current.git_allowed_to?(:edit_repository_git_notifications, @repository)
66
.contextual
77
= link_to l(:label_git_notifications_edit), edit_repository_git_notifications_path(@repository), class: 'icon icon-edit modal-box'
88
= link_to l(:label_git_notifications_delete), repository_git_notifications_path(@repository), remote: true, method: :delete, confirm: l(:text_are_you_sure), class: 'icon icon-del'
99
- else
10-
- if user_allowed_to(:create_repository_git_notifications, @project)
10+
- if User.current.git_allowed_to?(:create_repository_git_notifications, @repository)
1111
.contextual= link_to l(:label_git_notifications_add), new_repository_git_notifications_path(@repository), class: 'icon icon-add modal-box'
1212

1313
%h3{ class: 'git' }= l(:label_git_notifications)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%div
22

3-
- if user_allowed_to(:create_repository_mirrors, @project)
3+
- if User.current.git_allowed_to?(:create_repository_mirrors, @repository)
44
.contextual= link_to l(:label_mirror_add), new_repository_mirror_path(@repository), class: 'icon icon-add modal-box'
55

66
%h3= l(:label_repository_mirrors)
@@ -25,7 +25,7 @@
2525
%td= checked_image2 mirror.active?
2626

2727
%td{ class: 'buttons' }
28-
- if user_allowed_to(:edit_repository_mirrors, @project)
28+
- if User.current.git_allowed_to?(:edit_repository_mirrors, @repository)
2929
= link_to label_with_icon(l(:label_mirror_push), 'fa-rocket', class: 'fa-align'), push_repository_mirror_path(@repository, mirror), class: 'modal-box-close-only'
3030
= link_to l(:button_edit), edit_repository_mirror_path(@repository, mirror), class: 'icon icon-edit modal-box'
3131
= link_to l(:button_delete), repository_mirror_path(@repository, mirror), remote: true, method: :delete, confirm: l(:text_are_you_sure), class: 'icon icon-del'

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%div
22

3-
- if user_allowed_to(:create_repository_post_receive_urls, @project)
3+
- if User.current.git_allowed_to?(:create_repository_post_receive_urls, @repository)
44
.contextual= link_to l(:label_post_receive_url_add), new_repository_post_receive_url_path(@repository), class: 'icon icon-add modal-box'
55

66
%h3= l(:label_post_receive_urls)
@@ -29,7 +29,7 @@
2929
%span{ class: 'label label-info' }= trigger
3030

3131
%td{ class: 'buttons' }
32-
- if user_allowed_to(:edit_repository_post_receive_urls, @project)
32+
- if User.current.git_allowed_to?(:edit_repository_post_receive_urls, @repository)
3333
= link_to l(:button_edit), edit_repository_post_receive_url_path(@repository, post_receive_url), class: 'icon icon-edit modal-box'
3434
= link_to l(:button_delete), repository_post_receive_url_path(@repository, post_receive_url), remote: true, method: :delete, confirm: l(:text_are_you_sure), class: 'icon icon-del'
3535

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%div
22

3-
- if user_allowed_to(:create_repository_protected_branches, @project)
3+
- if User.current.git_allowed_to?(:create_repository_protected_branches, @repository)
44
.contextual= link_to l(:label_protected_branch_add), new_repository_protected_branch_path(@repository), class: 'icon icon-add modal-box'
55

66
%h3= l(:label_protected_branches)
@@ -34,7 +34,7 @@
3434
%span{ class: 'label label-info' }= user
3535

3636
%td{ class: 'buttons' }
37-
- if user_allowed_to(:edit_repository_protected_branches, @project)
37+
- if User.current.git_allowed_to?(:edit_repository_protected_branches, @repository)
3838
= link_to l(:button_edit), edit_repository_protected_branch_path(@repository, protected_branch), class: 'icon icon-edit modal-box'
3939
= link_to l(:button_clone), clone_repository_protected_branch_path(@repository, protected_branch), class: 'icon icon-clone modal-box'
4040
= link_to l(:button_delete), repository_protected_branch_path(@repository, protected_branch), remote: true, method: :delete, confirm: l(:text_are_you_sure), class: 'icon icon-del'

Diff for: lib/redmine_git_hosting/git_access.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def upload_access_check(actor, repository)
3232

3333

3434
def user_download_access_check(user, repository)
35-
if user && user.allowed_to?(:view_changesets, repository.project)
35+
if user && user.allowed_to_clone?(repository)
3636
build_status_object(true)
3737
else
3838
build_status_object(false, "You don't have access")
@@ -41,7 +41,7 @@ def user_download_access_check(user, repository)
4141

4242

4343
def user_upload_access_check(user, repository)
44-
if user && user.allowed_to?(:commit_access, repository.project)
44+
if user && user.allowed_to_commit?(repository)
4545
build_status_object(true)
4646
else
4747
build_status_object(false, "You don't have access")

0 commit comments

Comments
 (0)