Skip to content

Commit cdcaa0a

Browse files
kfischer-okarinRedmine Patch Meetup
authored andcommitted
Hide links without permission
1 parent 354bd1c commit cdcaa0a

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
@@ -258,6 +258,24 @@ def test_show_delete_redirect_links
258258
end
259259
end
260260

261+
def test_hide_delete_redirect_links_without_permission
262+
@request.session[:user_id] = 2
263+
264+
wiki_page = WikiPage.find_by(title: 'CookBook_documentation')
265+
wiki_page.title = 'Old_Cookbook'
266+
wiki_page.save
267+
268+
project = wiki_page.wiki.project
269+
role = User.find(2).members.find_by(project: project).roles.first
270+
role.remove_permission! :rename_wiki_pages
271+
272+
get :show, :params => {:project_id => 'ecookbook', :id => 'Old_Cookbook'}
273+
274+
assert_select '.drdn-items' do
275+
assert_select 'a.icon-link-break', count: 0
276+
end
277+
end
278+
261279
def test_get_new
262280
@request.session[:user_id] = 2
263281

0 commit comments

Comments
 (0)