Skip to content

Commit

Permalink
Hide links without permission
Browse files Browse the repository at this point in the history
  • Loading branch information
kfischer-okarin committed Feb 15, 2021
1 parent ff0db9f commit 2a44682
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/views/wiki/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
<%= link_to_if_authorized(l(:button_lock), {:action => 'protect', :id => @page.title, :protected => 1}, :method => :post, :class => 'icon icon-lock') if !@page.protected? %>
<%= link_to_if_authorized(l(:button_unlock), {:action => 'protect', :id => @page.title, :protected => 0}, :method => :post, :class => 'icon icon-unlock') if @page.protected? %>
<%= link_to_if_authorized(l(:button_rename), {:action => 'rename', :id => @page.title}, :class => 'icon icon-move') %>
<% @redirects_to_self.map { |redirect| %>
<%= 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') %>
<% } %>
<% if User.current.allowed_to?(:rename_wiki_pages, @project) %>
<% @redirects_to_self.map { |redirect| %>
<%= 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') %>
<% } %>
<% end %>
<%= 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') %>
<% else %>
<%= link_to_if_authorized(l(:button_rollback), {:action => 'edit', :id => @page.title, :version => @content.version }, :class => 'icon icon-cancel') %>
Expand Down
18 changes: 18 additions & 0 deletions test/functional/wiki_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,24 @@ def test_show_delete_redirect_links
end
end

def test_hide_delete_redirect_links_without_permission
@request.session[:user_id] = 2

wiki_page = WikiPage.find_by(title: 'CookBook_documentation')
wiki_page.title = 'Old_Cookbook'
wiki_page.save

project = wiki_page.wiki.project
role = User.find(2).members.find_by(project: project).roles.first
role.remove_permission! :rename_wiki_pages

get :show, :params => {:project_id => 'ecookbook', :id => 'Old_Cookbook'}

assert_select '.drdn-items' do
assert_select 'a.icon-link-break', count: 0
end
end

def test_get_new
@request.session[:user_id] = 2

Expand Down

0 comments on commit 2a44682

Please sign in to comment.