allow site to disable comments on profile

This commit is contained in:
Kyle Drake 2014-08-31 20:25:59 -07:00
parent 8274ac3e80
commit 92fcee0aea
6 changed files with 41 additions and 5 deletions

15
app.rb
View file

@ -122,6 +122,7 @@ post '/site/:username/comment' do |username|
require_login require_login
site = Site[username: username] site = Site[username: username]
redirect request.referrer if site.profile_comments_enabled == false
if params[:message].empty? || (site.is_blocking?(current_site) || current_site.is_blocking?(site)) if params[:message].empty? || (site.is_blocking?(current_site) || current_site.is_blocking?(site))
redirect "/site/#{username}" redirect "/site/#{username}"
@ -476,6 +477,15 @@ get '/settings' do
erb :'settings' erb :'settings'
end end
post '/settings/profile' do
require_login
current_site.update(
profile_comments_enabled: params[:site][:profile_comments_enabled]
)
flash[:success] = 'Profile settings changed.'
redirect '/settings'
end
post '/signin' do post '/signin' do
dashboard_if_signed_in dashboard_if_signed_in
@ -1076,7 +1086,10 @@ post '/event/:event_id/comment' do |event_id|
content_type :json content_type :json
event = Event[id: event_id] event = Event[id: event_id]
return {result: 'error'}.to_json if event.site.is_blocking?(current_site) site = event.site
return {result: 'error'}.to_json if site.is_blocking?(current_site)
return {result: 'error'}.to_json if site.profile_comments_enabled == false
event.add_site_comment current_site, params[:message] event.add_site_comment current_site, params[:message]
{result: 'success'}.to_json {result: 'success'}.to_json

View file

@ -77,8 +77,7 @@ Stripe.api_key = $config['stripe_api_key']
Dir.glob('models/*.rb').each {|m| require File.join(DIR_ROOT, "#{m}") } Dir.glob('models/*.rb').each {|m| require File.join(DIR_ROOT, "#{m}") }
Dir.glob('workers/*.rb').each {|w| require File.join(DIR_ROOT, "/#{w}") } Dir.glob('workers/*.rb').each {|w| require File.join(DIR_ROOT, "/#{w}") }
DB.loggers << Logger.new(STDOUT) if ENV['RACK_ENV'] == 'development'
#DB.loggers << Logger.new(STDOUT) if ENV['RACK_ENV'] == 'development'
if ENV['RACK_ENV'] == 'development' if ENV['RACK_ENV'] == 'development'
# If new, throw up a random Server for development. # If new, throw up a random Server for development.

View file

@ -0,0 +1,9 @@
Sequel.migration do
up {
DB.add_column :sites, :profile_comments_enabled, :boolean, default: true
}
down {
DB.drop_column :sites, :profile_comments_enabled
}
end

View file

@ -7,7 +7,7 @@
<%= event_likes_count %>&nbsp;<%= event_likes_count == 1 ? 'like' : 'likes' %> <%= event_likes_count %>&nbsp;<%= event_likes_count == 1 ? 'like' : 'likes' %>
<% end %> <% end %>
<% end %> <% end %>
<% if current_site %> <% if current_site && event.site.profile_comments_enabled %>
<a id="reply" href="#" onclick="Template.renderComment(<%= event.id %>); return false"> <a id="reply" href="#" onclick="Template.renderComment(<%= event.id %>); return false">
<% if event.profile_comment_id %> <% if event.profile_comment_id %>
Reply Reply

View file

@ -35,6 +35,21 @@
<a class="btn-Action" href="/plan">Supporter Info</a> <a class="btn-Action" href="/plan">Supporter Info</a>
<% end %> <% end %>
<h2>Site Profile</h2>
<div>
<form method="POST" action="/settings/profile">
<%== csrf_token_input_html %>
<p>
<input name="site[profile_comments_enabled]" type="hidden" value="true">
<input name="site[profile_comments_enabled]" type="checkbox" value="false"
<% if current_site.profile_comments_enabled == false %>checked<% end %>
> Turn off profile comments
</p>
<input class="btn-Action" type="submit" value="Update Site Profile Settings">
</form>
</div>
<h2>Custom Domain</h2> <h2>Custom Domain</h2>
<p> <p>
You can configure a custom domain for your Neocities site! <strong><a href="/custom_domain">Click Here</a></strong> for more information. You can configure a custom domain for your Neocities site! <strong><a href="/custom_domain">Click Here</a></strong> for more information.

View file

@ -66,7 +66,7 @@
<div class="container"> <div class="container">
<div class="content misc-page columns right-col"><div class="col-left"> <div class="content misc-page columns right-col"><div class="col-left">
<div class="col col-66"> <div class="col col-66">
<% if current_site %> <% if current_site && site.profile_comments_enabled %>
<div class="post-comment"> <div class="post-comment">
<form method="POST" action="/site/<%= site.username %>/comment"> <form method="POST" action="/site/<%= site.username %>/comment">
<input name="csrf_token" type="hidden" value="<%= csrf_token %>"> <input name="csrf_token" type="hidden" value="<%= csrf_token %>">