Actualizar plugin Private Wiki a 0.2.0-mistraloz

This commit is contained in:
Manuel Cillero 2020-11-30 11:11:31 +01:00
parent b37d1305f1
commit fd78375294
10 changed files with 43 additions and 59 deletions

View file

@ -3,36 +3,35 @@ module WikiPatches
module ApplicationHelperPatch
def self.included(base)
base.class_eval do
#Override application's method to not display hidden wikis or to display it with the PRIVATE flag
def render_page_hierarchy_with_wiki_hidding(pages, node=nil, options={})
content = ''
if pages[node]
content << "<ul class=\"pages-hierarchy\">\n"
pages[node].each do |page|
if !page.private? then
content << "<li>"
content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title, :version => nil},
:title => (options[:timestamp] && page.updated_on ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
content << "\n" + render_page_hierarchy(pages, page.id, options) if pages[page.id]
content << "</li>\n"
elsif User.current.allowed_to?(:view_privates_wiki, @project) then
content << "<li>"
content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title, :version => nil},
:title => (options[:timestamp] && page.updated_on ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
content << ' <span class="private_wiki_flag" style="display:inline-block;" title="' + l(:private_title) + '">' + l(:private_flag) + '</span>'
content << "\n" + render_page_hierarchy(pages, page.id, options) if pages[page.id]
content << "</li>\n"
end
end
content << "</ul>\n"
end
content.html_safe
end
alias_method_chain :render_page_hierarchy, :wiki_hidding
def render_page_hierarchy(pages, node=nil, options={})
content = +''
if pages[node]
content << "<ul class=\"pages-hierarchy\">\n"
pages[node].each do |page|
if page.private and !User.current.allowed_to?(:view_privates_wiki, @project) then
next
end
content << "<li>"
if controller.controller_name == 'wiki' && controller.action_name == 'export'
href = "##{page.title}"
else
href = {:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title, :version => nil}
end
content << link_to(h(page.pretty_title), href,
:title => (options[:timestamp] && page.updated_on ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
if page.private then
content << "&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"private_wiki_flag\" style=\"display:inline-block;\">" + l(:private_flag) + "</span>"
end
content << "\n" + render_page_hierarchy(pages, page.id, options) if pages[page.id]
content << "</li>\n"
end
content << "</ul>\n"
end
content.html_safe
end
end
end
end
end
end

View file

@ -5,7 +5,7 @@ module WikiPatches
base.class_eval do
unloadable
#Test :valide before :show action on wiki_controller
before_filter :validate, :only => [:show,:edit,:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy]
before_action :validate, :only => [:show,:edit,:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy]
end
end
@ -25,4 +25,4 @@ module WikiPatches
end
end
end
end
end