Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace all uses of wiki.slug in favor of wiki.path, fixes #736 #1101

Merged
merged 5 commits into from
Dec 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,9 @@ DEPENDENCIES
uglifier (>= 1.0.3)
will_paginate (>= 3.0.6)
will_paginate-bootstrap (>= 1.0.1)

RUBY VERSION
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to not include Gemfile or Gemfile.lock changes if not essential, but I'll leave these in this time. Thanks!

ruby 2.1.2p95

BUNDLED WITH
1.13.6
2 changes: 1 addition & 1 deletion app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def mark_spam_revision
@revision.spam
@revision.author.ban
flash[:notice] = "Item marked as spam and author banned. You can undo this on the <a href='/spam/revisions'>spam moderation page</a>."
redirect_to "/wiki/revisions/<%= @node.slug %>" + '?_=' + Time.now.to_i.to_s
redirect_to "/wiki/revisions/" + @revision.drupal_node.slug_from_path + '?_=' + Time.now.to_i.to_s
else
flash[:notice] = "Item already marked as spam and author banned. You can undo this on the <a href='/spam/revisions'>spam moderation page</a>."
redirect_to "/dashboard"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/talk_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class TalkController < ApplicationController
def show
@node = DrupalNode.find_by_slug params[:id]
@node = DrupalNode.find_by_path params[:id]
end
end
4 changes: 2 additions & 2 deletions app/controllers/wiki_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def show
end
@tagnames = @tags.collect(&:name)
set_sidebar :tags, @tagnames, {:videos => true}
@wikis = DrupalTag.find_pages(@node.slug,30) if @node.has_tag('chapter') || @node.has_tag('tabbed:wikis')
@wikis = DrupalTag.find_pages(@node.slug_from_path,30) if @node.has_tag('chapter') || @node.has_tag('tabbed:wikis')

@node.view
@revision = @node.latest
Expand Down Expand Up @@ -206,7 +206,7 @@ def revert

# wiki pages which have a root URL, like /about
def root
@node = DrupalNode.find_root_by_slug(params[:id])
@node = DrupalNode.find_by_path(params[:id])
return if check_and_redirect_node(@node)
if @node
@revision = @node.latest
Expand Down
8 changes: 6 additions & 2 deletions app/models/drupal_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ def self.inheritance_column
"rails_type"
end

def slug_from_path
self.path.split('/').last
end

before_save :set_changed_and_created
after_create :setup
before_validation :set_path, on: :create
Expand Down Expand Up @@ -320,7 +324,7 @@ def gallery
# base this on a tag!
def is_place?
# self.has_tag('chapter')
self.slug[0..5] == 'place/'
self.path[0..6] == '/wiki/place'
end

# ============================================
Expand Down Expand Up @@ -497,7 +501,7 @@ def edit_path
path
end

def self.find_root_by_slug(title)
def self.find_by_path(title)
DrupalNode.where(path: ["/#{title}"]).first
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/talk/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<div><p class="help-text" style="margin-top: 10px;font-family: 'Junction Light';clear:left;"><%= raw t('talk.show.welcome', :page => @node.latest.title, :url1 => @node.path, :url2 => '/wiki/talk-pages') %></p></div>
<div><iframe src="https://pad.publiclab.org/p/<%= @node.slug[0,50] %>" style="width: 100%; height:800px;"><p><%= t('talk.show.try_direct_link', :url1 => 'https://pad.publiclab.org/p/'+@node.slug[0,50]) %></p></iframe></div>
<div><iframe src="https://pad.publiclab.org/p/<%= @node.slug_from_path[0,50] %>" style="width: 100%; height:800px;"><p><%= t('talk.show.try_direct_link', :url1 => 'https://pad.publiclab.org/p/'+@node.slug_from_path[0,50]) %></p></iframe></div>
4 changes: 2 additions & 2 deletions app/views/wiki/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<h3><%= t('wiki.edit.did_you_mean') %>:</h3>
<ul class="nav bullet">
<% @related[0..5].each do |wiki| %>
<li><a href="/wiki/<%= wiki.slug %>"><i class="fa fa-book"></i> <%= wiki.title %></a></li>
<li><a href="/wiki/<%= wiki.path %>"><i class="fa fa-book"></i> <%= wiki.title %></a></li>
<% end %>
</ul>
<p><i class="fa fa-search"></i> <%= raw t('wiki.edit.try_searching_for', :url1 => "/search/"+params[:id], :wiki => params[:id]) %></p>
Expand All @@ -17,7 +17,7 @@
<ul class="nav nav-list">
<li class="nav-header"><%= t('wiki.edit.more') %></li>
<li><a href="/wiki/getting-started"><%= t('wiki.edit.getting_started') %></a></li>
<% if @node.path %><li><a href="/wiki/revisions/<%= @node.slug %>"><%= t('wiki.edit.revisions_for_this_page') %></a></li><% end %>
<% if @node.path %><li><a href="/wiki/revisions/<%= @node.slug_from_path %>"><%= t('wiki.edit.revisions_for_this_page') %></a></li><% end %>
<li><a href="/wiki/posting-research"><%= t('wiki.edit.about_posting_research') %></a></li>
<li><a href="/wiki/authoring-help#Advanced+formatting"><%= t('wiki.edit.advanced_formatting') %></a></li>
</ul>
Expand Down
6 changes: 3 additions & 3 deletions app/views/wiki/revisions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<h3 id="wiki-title" style="margin-top:0;"><%= raw t('wiki.revisions.revisions_for', :wiki => @node.title) %></h3>

<ul class="nav nav-tabs">
<li><a href="/wiki/<%= @node.slug %>"><%= t('wiki.revisions.view') %></a></li>
<li><a href="/wiki/edit/<%= @node.slug %>"><%= t('wiki.revisions.edit') %></a></li>
<li class="active"><a href="/wiki/revisions/<%= @node.slug %>">Revisions (<%= @node.revisions.length %>)</a></li>
<li><a href="/wiki/<%= @node.slug_from_path %>"><%= t('wiki.revisions.view') %></a></li>
<li><a href="/wiki/edit/<%= @node.slug_from_path %>"><%= t('wiki.revisions.edit') %></a></li>
<li class="active"><a href="/wiki/revisions/<%= @node.slug_from_path %>">Revisions (<%= @node.revisions.length %>)</a></li>
<!--<li class="pull-right"><%= render :partial => "home/social" %></li>-->
</ul>

Expand Down
11 changes: 5 additions & 6 deletions app/views/wiki/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<h1 style="font-family: 'Junction Light';"><i class="fa fa-book"></i> <%= @revision.title %> <a onClick="$('#wiki-toolbar').toggle()" class="btn btn-link"><b class="caret"></b></a></h1>

<% if @is_revision %>
<div class="alert alert-warning"><%= raw t('wiki.show.revision_from', :time => @revision.created_at.to_s(:long)) %> <a href="/wiki/revisions/<%= @node.slug %>"><%= t('wiki.show.view_all_revisions') %></a></div>
<div class="alert alert-warning"><%= raw t('wiki.show.revision_from', :time => @revision.created_at.to_s(:long)) %> <a href="/wiki/revisions/<%= @node.slug_from_path %>"><%= t('wiki.show.view_all_revisions') %></a></div>

<% end %>

Expand All @@ -44,17 +44,16 @@
<li class="active"><a href="#"><span class="hidden-xs"><%= t('wiki.show.view') %></span><span class="visible-xs"><i class="fa fa-file-o"></i></span></a></li>
<li><a href="<%= @node.edit_path %>?t=<%= Time.now.to_i %>"><i class="fa fa-pencil"></i><span class="hidden-xs hidden-sm"> <%= t('wiki.show.edit') %></span></a></li>
<% if current_user && current_user.role == "admin" %><li><%= link_to "/wiki/delete/"+@node.id.to_s, :confirm => I18n.t('wiki.show.are_you_sure_delete', :path => @node.path) do %><i class="fa fa-trash"></i><span class="hidden-xs hidden-sm"> <%= t('wiki.show.delete') %></span><% end %></li><% end %>
<li><a href="/talk/<%= @node.slug %>"><i class="fa fa-comments-o"></i><span class="hidden-xs hidden-sm"> <%= t('wiki.show.talk') %></span></a></li>
<li><a href="/wiki/revisions/<%= @node.slug %>"><span class="hidden-xs"><%= @node.revisions.length %> </span><i class="fa fa-list"></i></a></li>
<li><a href="/talk/<%= @node.slug_from_path %>"><i class="fa fa-comments-o"></i><span class="hidden-xs hidden-sm"> <%= t('wiki.show.talk') %></span></a></li>
<li><a href="/wiki/revisions/<%= @node.slug_from_path %>"><span class="hidden-xs"><%= @node.revisions.length %> </span><i class="fa fa-list"></i></a></li>
</ul>
</div>
</div>

<br />

<% if @node.has_power_tag('parent') %>
<% slug = @node.power_tag('parent') %>
<% parent = DrupalNode.find_by_slug(slug) %>
<% parent = DrupalNode.find_by_path("/wiki/" + @node.power_tag('parent')) %>
<% if parent %>
<div class="alert alert-success" style="border-color:#eee;background:#f8f8f8;color:#aaa;">&laquo; <%= raw t('wiki.show.back_to_wiki', :url1 => parent.path, :title => parent.latest.title) %></a></div>
<% end %>
Expand All @@ -77,7 +76,7 @@
<% if @node.power_tags('tabbed').include?("notes") %>
<div class="tab-pane" id="tab-notes">
<%= render :partial => "notes/notes" %>
<p><a href="/tag/<%= @node.slug %>"><%= raw t('wiki.show.more_research', :tag => @node.slug) %> &raquo;</a></p>
<p><a href="/tag/<%= @node.slug_from_path %>"><%= raw t('wiki.show.more_research', :tag => @node.slug_from_path) %> &raquo;</a></p>
<br />
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion test/functional/admin_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def teardown
assert_equal 0, revision.status
assert_equal 0, revision.author.status
assert_not_equal node(:spam_targeted_page).latest.vid, revision.vid
assert_redirected_to "/wiki/revisions/<%= @node.slug %>" + '?_=' + Time.now.to_i.to_s
assert_redirected_to "/wiki/revisions/" + revision.drupal_node.slug_from_path + '?_=' + Time.now.to_i.to_s
end

test "admin user should be able to republish a revision" do
Expand Down