From 79846311e6aca471f7f9d49628bccaf5fc171151 Mon Sep 17 00:00:00 2001 From: Swapnil Gupta <500swapnil@gmail.com> Date: Fri, 16 Dec 2016 21:38:49 +0400 Subject: [PATCH] Replace all uses of wiki.slug in favor of wiki.path, fixes #736 (#1101) * Replace slug by path * Fixed test for node.slug_from_path * Added @revision * add drupal_node * Update on removing slugs --- Gemfile.lock | 6 ++++++ app/controllers/admin_controller.rb | 2 +- app/controllers/talk_controller.rb | 2 +- app/controllers/wiki_controller.rb | 4 ++-- app/models/drupal_node.rb | 8 ++++++-- app/views/talk/show.html.erb | 2 +- app/views/wiki/edit.html.erb | 4 ++-- app/views/wiki/revisions.html.erb | 6 +++--- app/views/wiki/show.html.erb | 11 +++++------ test/functional/admin_controller_test.rb | 2 +- 10 files changed, 28 insertions(+), 19 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d0336f94f7..2ed858687c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -339,3 +339,9 @@ DEPENDENCIES uglifier (>= 1.0.3) will_paginate (>= 3.0.6) will_paginate-bootstrap (>= 1.0.1) + +RUBY VERSION + ruby 2.1.2p95 + +BUNDLED WITH + 1.13.6 diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index b026f1955f..8a41eb78c5 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -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 spam moderation page." - 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 spam moderation page." redirect_to "/dashboard" diff --git a/app/controllers/talk_controller.rb b/app/controllers/talk_controller.rb index c6c41c4b88..9c12d04713 100644 --- a/app/controllers/talk_controller.rb +++ b/app/controllers/talk_controller.rb @@ -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 diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index a35d5f00d2..8247f7e2c8 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -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 @@ -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 diff --git a/app/models/drupal_node.rb b/app/models/drupal_node.rb index 39445b9fab..bcefbaf959 100644 --- a/app/models/drupal_node.rb +++ b/app/models/drupal_node.rb @@ -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 @@ -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 # ============================================ @@ -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 diff --git a/app/views/talk/show.html.erb b/app/views/talk/show.html.erb index 5965f0875d..44233f2dca 100644 --- a/app/views/talk/show.html.erb +++ b/app/views/talk/show.html.erb @@ -1,2 +1,2 @@
<%= raw t('talk.show.welcome', :page => @node.latest.title, :url1 => @node.path, :url2 => '/wiki/talk-pages') %>
<%= raw t('wiki.edit.try_searching_for', :url1 => "/search/"+params[:id], :wiki => params[:id]) %>
@@ -17,7 +17,7 @@ diff --git a/app/views/wiki/revisions.html.erb b/app/views/wiki/revisions.html.erb index 9b1ad4032c..6ccf211e35 100644 --- a/app/views/wiki/revisions.html.erb +++ b/app/views/wiki/revisions.html.erb @@ -4,9 +4,9 @@<%= raw t('wiki.show.more_research', :tag => @node.slug) %> »
+<%= raw t('wiki.show.more_research', :tag => @node.slug_from_path) %> »