Skip to content

Commit

Permalink
[fix] 404 error when preview opendata/dateset (#2030)
Browse files Browse the repository at this point in the history
* [fix] 404 error when preview opendata/dateset

* [modify] opendata/dataset show_point.html

* [fix] 404 error when preview closed opendata/app or opendata/idea
  • Loading branch information
ShinjiTanimoto authored and sunny4381 committed Apr 11, 2018
1 parent 5097307 commit 543f581
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 42 deletions.
6 changes: 4 additions & 2 deletions app/controllers/opendata/agents/nodes/app/app_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@ class Opendata::Agents::Nodes::App::AppController < ApplicationController

def set_app
@app_path ||= Opendata::App.to_app_path(@cur_path)
@app ||= Opendata::App.site(@cur_site).and_public.
@app ||= Opendata::App.site(@cur_site).
filename(@app_path).
first

raise "404" unless @app
raise '404' if !@preview && !@app.public?
end

def set_ideas
@app_idea_path = Opendata::App.to_app_path(@cur_path)

@app_idea = Opendata::App.site(@cur_site).and_public.
@app_idea = Opendata::App.site(@cur_site).
filename(@app_idea_path).
first

raise "404" unless @app_idea
raise '404' if !@preview && !@app_idea.public?

cond = { site_id: @cur_site.id, app_ids: @app_idea.id }
@ideas = Opendata::Idea.where(cond).and_public.order_by(:updated.asc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@ class Opendata::Agents::Nodes::Dataset::DatasetController < ApplicationControlle

def set_dataset
@dataset_path = Opendata::Dataset.to_dataset_path(@cur_path)
@dataset = Opendata::Dataset.site(@cur_site).and_public.
@dataset = Opendata::Dataset.site(@cur_site).
filename(@dataset_path).
first

raise "404" unless @dataset
raise '404' if !@preview && !@dataset.public?
end

def set_apps
@dataset_app_path = Opendata::Dataset.to_dataset_path(@cur_path)

@dataset_app = Opendata::Dataset.site(@cur_site).and_public.
@dataset_app = Opendata::Dataset.site(@cur_site).
filename(@dataset_app_path).
first

raise "404" unless @dataset_app
raise '404' if !@preview && !@dataset_app.public?

cond = { site_id: @cur_site.id, dataset_ids: @dataset_app.id }
@apps = Opendata::App.where(cond).and_public.order_by(:updated.asc)
Expand All @@ -37,11 +39,12 @@ def set_apps
def set_ideas
@dataset_idea_path = Opendata::Dataset.to_dataset_path(@cur_path)

@dataset_idea = Opendata::Dataset.site(@cur_site).and_public.
@dataset_idea = Opendata::Dataset.site(@cur_site).
filename(@dataset_idea_path).
first

raise "404" unless @dataset_idea
raise '404' if !@preview && !@dataset_idea.public?

cond = { site_id: @cur_site.id, dataset_ids: @dataset_idea.id }
@ideas = Opendata::Idea.where(cond).and_public.order_by(:updated.asc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Opendata::Agents::Nodes::Idea::CommentController < ApplicationController
def set_comments
@idea_path = Opendata::Idea.to_idea_path(@cur_path)

@idea = Opendata::Idea.site(@cur_site).and_public.
@idea = Opendata::Idea.site(@cur_site).
filename(@idea_path).
first

Expand All @@ -26,6 +26,7 @@ def set_comments
@comment_mode = logged_in?(redirect: false)

raise "404" unless @idea
raise '404' if !@preview && !@idea.public?
end

def set_workflow
Expand Down
9 changes: 6 additions & 3 deletions app/controllers/opendata/agents/nodes/idea/idea_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ class Opendata::Agents::Nodes::Idea::IdeaController < ApplicationController

def set_idea
@idea_path = Opendata::Idea.to_idea_path(@cur_path)
@idea = Opendata::Idea.site(@cur_site).and_public.
@idea = Opendata::Idea.site(@cur_site).
filename(@idea_path).
first

raise "404" unless @idea
raise '404' if !@preview && !@idea.public?
end

public
Expand Down Expand Up @@ -97,10 +98,11 @@ def show_dataset

idea_path = @cur_path.sub(/\/dataset\/.*/, ".html")

@idea_ds = Opendata::Idea.site(@cur_site).and_public.
@idea_ds = Opendata::Idea.site(@cur_site).
filename(idea_path).
first
raise "404" unless @idea_ds
raise '404' if !@preview && !@idea_ds.public?

end

Expand All @@ -109,10 +111,11 @@ def show_app

idea_path = @cur_path.sub(/\/app\/.*/, ".html")

@idea_ap = Opendata::Idea.site(@cur_site).and_public.
@idea_ap = Opendata::Idea.site(@cur_site).
filename(idea_path).
first
raise "404" unless @idea_ap
raise '404' if !@preview && !@idea_ap.public?

end

Expand Down
10 changes: 6 additions & 4 deletions app/views/opendata/agents/nodes/app/app/show_point.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<% return if @cur_node.hide_point? %>
<%= jquery do %>
Opendata_Point.renderButton();
$(".point .label a").colorbox({ fixed: true, width: "300px", height: "50%" })
<% if @preview.blank? %>
<%= jquery do %>
Opendata_Point.renderButton();
$(".point .label a").colorbox({ fixed: true, width: "300px", height: "50%" })
<% end %>
<% end %>

<div class="count">
Expand All @@ -18,4 +20,4 @@
</span>
</div>

<div class="like"><%= link_to I18n.t("opendata.labels.iine"), "#{@app.point_url}", class: "update #{@mode}", "data-auth-token" => form_authenticity_token, rel: "nofollow" if @mode %></div>
<div class="like"><%= link_to I18n.t("opendata.labels.iine"), @preview.present? ? '#' : @app.point_url, class: "update #{@mode}", "data-auth-token" => form_authenticity_token, rel: "nofollow" if @mode %></div>
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<% return if @cur_node.hide_point? %>
<%= jquery do %>
Opendata_Point.renderButton();
$(".point .label a").colorbox({ fixed: true, width: "300px", height: "50%" });
<% if @preview.blank? %>
<%= jquery do %>
Opendata_Point.renderButton();
$(".point .label a").colorbox({ fixed: true, width: "300px", height: "50%" });
<% end %>
<% end %>

<div class="count">
Expand All @@ -18,4 +20,4 @@
</span>
</div>

<div class="like"><%= link_to I18n.t("opendata.labels.iine"), "#{@dataset.point_url}", class: "update #{@mode}", "data-auth-token" => form_authenticity_token, rel: "nofollow" if @mode %></div>
<div class="like"><%= link_to I18n.t("opendata.labels.iine"), @preview.present? ? '#' : @dataset.point_url, class: "update #{@mode}", "data-auth-token" => form_authenticity_token, rel: "nofollow" if @mode %></div>
44 changes: 23 additions & 21 deletions app/views/opendata/agents/nodes/idea/comment/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
<%= coffee do %>
$ ->
<% if @preview.blank? %>
<%= coffee do %>
$ ->

$(".comment-add").click (event)->
text = $('#s_comment_body').val()
if text.length > 0
$(@).css('pointer-events', 'none')
$(".comment-add").click (event)->
text = $('#s_comment_body').val()
if text.length > 0
$(@).css('pointer-events', 'none')
$.ajax
url: "<%= @idea.comment_add_url %>"
type: "POST"
data: { comment_body : text, authenticity_token: "<%= form_authenticity_token %>" }
success: (data)->
$("#idea-comments").html data
event.preventDefault()

$(".comment_delete").click (event)->
$.ajax
url: "<%= @idea.comment_add_url %>"
url: "<%= @idea.comment_delete_url %>"
type: "POST"
data: { comment_body : text, authenticity_token: "<%= form_authenticity_token %>" }
data: { comment : $(this).attr("id"), authenticity_token: "<%= form_authenticity_token %>" }
success: (data)->
$("#idea-comments").html data
event.preventDefault()

$(".comment_delete").click (event)->
$.ajax
url: "<%= @idea.comment_delete_url %>"
type: "POST"
data: { comment : $(this).attr("id"), authenticity_token: "<%= form_authenticity_token %>" }
success: (data)->
$("#idea-comments").html data
event.preventDefault()
event.preventDefault()

$(".comment .label a").colorbox({ fixed: true, width: "300px", height: "50%" })
$(".comment .label a").colorbox({ fixed: true, width: "300px", height: "50%" })

<% end %>
<% end %>

<div class="info-wrap">
Expand All @@ -43,7 +45,7 @@
<% end %>
</div>
<% if @comment_mode && [@idea.member_id, comment.member_id].include?(@cur_member.id) %>
<%= link_to I18n.t("opendata.labels.delete"), "", class: "comment_delete", id: comment.id if comment.comment_deleted.nil? %>
<%= link_to I18n.t("opendata.labels.delete"), "#", class: "comment_delete", id: comment.id if comment.comment_deleted.nil? %>
<% end %>
<% member_name = comment.get_member_name %>
Expand All @@ -64,7 +66,7 @@
<dt><%= f.label(:comment_body, Opendata::Idea.t(:comment_body)) %></dt>
<dd><%= f.text_area(:comment_body, maxlength: "400", title: Opendata::IdeaComment.t(:text)) %></dd>
</dl>
<%= link_to(I18n.t("opendata.labels.add_comment"), "", class: "comment-add") %>
<%= link_to I18n.t("opendata.labels.add_comment"), "#", class: "comment-add" %>
<% end %>
<% elsif member_login_enabled? %>
<div class="invite"><%= I18n.t("opendata.labels.comment_invite_start") %><%= link_to I18n.t("opendata.labels.login"),"#{member_login_path}login.html?ref=#{CGI.escape(@idea.url)}" %><%= I18n.t("opendata.labels.comment_invite_end") %></div>
Expand Down
10 changes: 6 additions & 4 deletions app/views/opendata/agents/nodes/idea/idea/show_point.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<% return if @cur_node.hide_point? %>
<%= jquery do %>
Opendata_Point.renderButton();
$("#idea-point .label a").colorbox({ fixed: true, width: "300px", height: "50%" })
<% if @preview.blank? %>
<%= jquery do %>
Opendata_Point.renderButton();
$("#idea-point .label a").colorbox({ fixed: true, width: "300px", height: "50%" })
<% end %>
<% end %>

<div class="count">
Expand All @@ -18,4 +20,4 @@
</span>
</div>

<div class="like"><%= link_to I18n.t("opendata.labels.iine"), "#{@idea.point_url}", class: "update #{@mode}", "data-auth-token" => form_authenticity_token, rel: "nofollow" if @mode %></div>
<div class="like"><%= link_to I18n.t("opendata.labels.iine"), @preview.present? ? '#' : @idea.point_url, class: "update #{@mode}", "data-auth-token" => form_authenticity_token, rel: "nofollow" if @mode %></div>

0 comments on commit 543f581

Please sign in to comment.