Skip to content

Commit 2a44682

Browse files
Hide links without permission
1 parent ff0db9f commit 2a44682

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

app/views/wiki/show.html.erb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
<%= link_to_if_authorized(l(:button_lock), {:action => 'protect', :id => @page.title, :protected => 1}, :method => :post, :class => 'icon icon-lock') if !@page.protected? %>
1616
<%= link_to_if_authorized(l(:button_unlock), {:action => 'protect', :id => @page.title, :protected => 0}, :method => :post, :class => 'icon icon-unlock') if @page.protected? %>
1717
<%= link_to_if_authorized(l(:button_rename), {:action => 'rename', :id => @page.title}, :class => 'icon icon-move') %>
18-
<% @redirects_to_self.map { |redirect| %>
19-
<%= link_to("Delete redirect from #{WikiPage.pretty_title(redirect.title)}", {:controller => 'wiki_redirects', :action => 'destroy', :project_id => @project.identifier, :wiki_page_id => @page.title, :id => redirect.id}, :method => :delete, :class => 'icon icon-link-break') %>
20-
<% } %>
18+
<% if User.current.allowed_to?(:rename_wiki_pages, @project) %>
19+
<% @redirects_to_self.map { |redirect| %>
20+
<%= link_to("Delete redirect from #{WikiPage.pretty_title(redirect.title)}", {:controller => 'wiki_redirects', :action => 'destroy', :project_id => @project.identifier, :wiki_page_id => @page.title, :id => redirect.id}, :method => :delete, :class => 'icon icon-link-break') %>
21+
<% } %>
22+
<% end %>
2123
<%= link_to_if_authorized(l(:button_delete), {:action => 'destroy', :id => @page.title}, :method => :delete, :data => {:confirm => l(:text_are_you_sure)}, :class => 'icon icon-del') %>
2224
<% else %>
2325
<%= link_to_if_authorized(l(:button_rollback), {:action => 'edit', :id => @page.title, :version => @content.version }, :class => 'icon icon-cancel') %>

test/functional/wiki_controller_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,24 @@ def test_show_delete_redirect_links
211211
end
212212
end
213213

214+
def test_hide_delete_redirect_links_without_permission
215+
@request.session[:user_id] = 2
216+
217+
wiki_page = WikiPage.find_by(title: 'CookBook_documentation')
218+
wiki_page.title = 'Old_Cookbook'
219+
wiki_page.save
220+
221+
project = wiki_page.wiki.project
222+
role = User.find(2).members.find_by(project: project).roles.first
223+
role.remove_permission! :rename_wiki_pages
224+
225+
get :show, :params => {:project_id => 'ecookbook', :id => 'Old_Cookbook'}
226+
227+
assert_select '.drdn-items' do
228+
assert_select 'a.icon-link-break', count: 0
229+
end
230+
end
231+
214232
def test_get_new
215233
@request.session[:user_id] = 2
216234

0 commit comments

Comments
 (0)