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

@ -29,7 +29,7 @@ To set public/private wiki page :
$bundle exec rake redmine:plugins:migrate RAILS_ENV=production
## Compatibility :
Tested for RedMine 3.3.* (Manually)
Tested for RedMine 4.0.3 (Manually)
## License :
This plugin is licensed under the MIT license.

View file

@ -3,7 +3,7 @@
<!--If the wiki is private, set PRIVATE flag-->
<% if @page.private? and User.current.allowed_to?(:view_privates_wiki, @project) %>
<span class="private_page_flag" title="<%= l(:private_title) %>"><%= l(:private_flag) %></span>
<span class="private_wiki_flag private_wiki_head"><%= l(:private_flag) %></span>
<% end %>
<!--If authorized, allow user to see changing privacy buttons-->
@ -11,9 +11,9 @@
<%= link_to_if_authorized(l(:button_setpublic_wiki), {:action => 'change_privacy', :id => @page.title, :private => 0}, :method => :post, :class => 'icon icon-setpublic') if @page.private? %>
<script type="text/javascript">
$('.contextual:first').prepend($('.private_page_flag'));
$('.contextual:first').prepend($('.private_wiki_flag.private_wiki_head'));
$('.contextual:first').append($('.icon-setprivate'));
$('.contextual:first').append($('.icon-setpublic'));
</script>
<% end %>
<% end %>

View file

@ -27,7 +27,7 @@
<% if !page.private? %>
<li><%= link_to page.pretty_title, :action => 'show', :id => page.title, :project_id => page.project %></li>
<% elsif User.current.allowed_to?(:view_privates_wiki, @project) %>
<li><%= link_to page.pretty_title, :action => 'show', :id => page.title, :project_id => page.project %> <span class="private_wiki_flag" style="display:inline-block;" title="<%= l(:private_title) %>"><%= l(:private_flag) %></span></li>
<li><%= link_to page.pretty_title, :action => 'show', :id => page.title, :project_id => page.project %>&nbsp;&nbsp;&nbsp;&nbsp;<span class="private_wiki_flag" style="display:inline-block;"><%= l(:private_flag) %></span></li>
<% end %>
<% end %>
</ul>
@ -35,7 +35,7 @@
<h3><%= format_date(date) %></h3>
<ul>
<% @pages_by_date[date].each do |page| %>
<li><%= link_to page.pretty_title, :action => 'show', :id => page.title, :project_id => page.project %> <span class="private_wiki_flag" style="display:inline-block;" title="<%= l(:private_title) %>"><%= l(:private_flag) %></span></li>
<li><%= link_to page.pretty_title, :action => 'show', :id => page.title, :project_id => page.project %>&nbsp;&nbsp;&nbsp;&nbsp;<span class="private_wiki_flag" style="display:inline-block;"><%= l(:private_flag) %></span></li>
<% end %>
</ul>
<% end %>

View file

@ -1,21 +1,14 @@
.private_page_flag,
.private_wiki_flag {
background: #d22;
background: #D22;
color: white;
padding: 1px 2px;
padding: 2px 2px 2px 2px;
border-radius: 2px;
cursor: default;
}
.private_wiki_flag {
margin-left: .44em;
background: rgb(255, 50, 0, 0.5);
line-height: 1em;
}
.icon-setprivate{
background-image: url(../images/hide.png);
background-image: url(../images/hide.png);
}
.icon-setpublic{
background-image: url(../images/reveal.png);
background-image: url(../images/reveal.png);
}

View file

@ -2,5 +2,4 @@
en:
button_setprivate_wiki: Set Private
button_setpublic_wiki: Set Public
private_flag: P!
private_title: Private page
private_flag: PRIVATE

View file

@ -1,6 +0,0 @@
# Spanish strings go here for Rails i18n
es:
button_setprivate_wiki: Priv.
button_setpublic_wiki: Pub.
private_flag: P!
private_title: Página privada

View file

@ -2,5 +2,4 @@
fr:
button_setprivate_wiki: Rendre Privé
button_setpublic_wiki: Rendre Public
private_flag: P!
private_title: Privé
private_flag: PRIVÉ

View file

@ -1,4 +1,4 @@
class AddPrivateWikiAttribute < ActiveRecord::Migration
class AddPrivateWikiAttribute < ActiveRecord::Migration[4.2]
def change
#Add a "Private" attribute used to identify visibility of wikis
add_column(:wiki_pages, "private", :boolean, :default => false)

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