mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
better email infrastructure, email for profile comments, webapp format support
This commit is contained in:
parent
85fbfed910
commit
d611a5a290
7 changed files with 167 additions and 7 deletions
13
migrations/053_add_email_controls.rb
Normal file
13
migrations/053_add_email_controls.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
Sequel.migration do
|
||||
up {
|
||||
DB.add_column :sites, :send_emails, :boolean, default: true
|
||||
DB.add_column :sites, :send_comment_emails, :boolean, default: true
|
||||
DB.add_column :sites, :send_follow_emails, :boolean, default: true
|
||||
}
|
||||
|
||||
down {
|
||||
DB.drop_column :sites, :send_emails
|
||||
DB.drop_column :sites, :send_comment_emails
|
||||
DB.drop_column :sites, :send_follow_emails
|
||||
}
|
||||
end
|
|
@ -33,7 +33,7 @@ class Site < Sequel::Model
|
|||
}
|
||||
|
||||
VALID_EXTENSIONS = %w{
|
||||
html htm txt text css js jpg jpeg png gif svg md markdown eot ttf woff woff2 json geojson csv tsv mf ico pdf asc key pgp xml mid midi manifest otf
|
||||
html htm txt text css js jpg jpeg png gif svg md markdown eot ttf woff woff2 json geojson csv tsv mf ico pdf asc key pgp xml mid midi manifest otf webapp
|
||||
}
|
||||
|
||||
MINIMUM_PASSWORD_LENGTH = 5
|
||||
|
@ -81,6 +81,8 @@ class Site < Sequel::Model
|
|||
IP_CREATE_LIMIT = 50
|
||||
TOTAL_IP_CREATE_LIMIT = 300
|
||||
|
||||
FROM_EMAIL = 'noreply@neocities.org'
|
||||
|
||||
PLAN_FEATURES = {}
|
||||
|
||||
PLAN_FEATURES[:supporter] = {
|
||||
|
@ -183,6 +185,25 @@ class Site < Sequel::Model
|
|||
!account_sites_dataset.select(:id).where(id: site.id).first.nil?
|
||||
end
|
||||
|
||||
def add_profile_comment(opts)
|
||||
DB.transaction {
|
||||
profile_comment = super
|
||||
actioning_site = Site[id: opts[:actioning_site_id]]
|
||||
|
||||
return if actioning_site.owner == owner
|
||||
|
||||
send_email(
|
||||
subject: "#{actioning_site.username.capitalize} commented on your site",
|
||||
body: render_template(
|
||||
'email/new_comment.erb',
|
||||
actioning_site: actioning_site,
|
||||
message: opts[:message],
|
||||
profile_comment: profile_comment
|
||||
)
|
||||
)
|
||||
}
|
||||
end
|
||||
|
||||
class << self
|
||||
def valid_login?(username_or_email, plaintext)
|
||||
site = get_with_identifier username_or_email
|
||||
|
@ -429,7 +450,7 @@ class Site < Sequel::Model
|
|||
return true
|
||||
end
|
||||
|
||||
if account_sites_events_dataset.exclude(site_change_id: nil).count >= COMMENTING_ALLOWED_UPDATED_COUNT &&
|
||||
if (account_sites_events_dataset.exclude(site_change_id: nil).count >= COMMENTING_ALLOWED_UPDATED_COUNT || (created_at < Date.new(2014, 12, 25).to_time && changed_count >= COMMENTING_ALLOWED_UPDATED_COUNT )) &&
|
||||
created_at < Time.now - 604800
|
||||
owner.set commenting_allowed: true
|
||||
owner.save_changes validate: false
|
||||
|
@ -698,6 +719,27 @@ class Site < Sequel::Model
|
|||
super
|
||||
end
|
||||
|
||||
def can_email?(col=nil)
|
||||
return false unless owner.send_emails
|
||||
return false if col && !owner.send(col)
|
||||
true
|
||||
end
|
||||
|
||||
def send_email(args={})
|
||||
%i{subject body}.each do |a|
|
||||
raise ArgumentError, "argument missing: #{a}" if args[a].nil?
|
||||
end
|
||||
|
||||
if can_email?(args[:col])
|
||||
EmailWorker.perform_async({
|
||||
from: FROM_EMAIL,
|
||||
to: email,
|
||||
subject: args[:subject],
|
||||
body: args[:body]
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
def parent?
|
||||
parent_site_id.nil?
|
||||
end
|
||||
|
@ -817,8 +859,8 @@ class Site < Sequel::Model
|
|||
end
|
||||
end
|
||||
|
||||
def render_template(name)
|
||||
Tilt.new(template_file_path(name), pretty: true).render self
|
||||
def render_template(name, locals={})
|
||||
Tilt.new(template_file_path(name), pretty: true).render self, locals
|
||||
end
|
||||
|
||||
def template_file_path(name)
|
||||
|
|
41
tests/SIL Open Font License.txt
Normal file
41
tests/SIL Open Font License.txt
Normal file
|
@ -0,0 +1,41 @@
|
|||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
@ -103,6 +103,7 @@ describe 'site/settings' do
|
|||
end
|
||||
end
|
||||
|
||||
=begin
|
||||
describe 'ssl' do
|
||||
include Capybara::DSL
|
||||
|
||||
|
@ -197,6 +198,7 @@ describe 'site/settings' do
|
|||
end
|
||||
end
|
||||
end
|
||||
=end
|
||||
|
||||
describe 'change username' do
|
||||
include Capybara::DSL
|
||||
|
|
|
@ -7,6 +7,25 @@ describe 'site page' do
|
|||
Capybara.default_driver = :rack_test
|
||||
end
|
||||
|
||||
it 'allows commenting' do
|
||||
site = Fabricate :site
|
||||
commenting_site = Fabricate :site, commenting_allowed: true
|
||||
page.set_rack_session id: commenting_site.id
|
||||
visit "/site/#{site.username}"
|
||||
fill_in 'message', with: 'I love your site!'
|
||||
click_button 'Post'
|
||||
site.profile_comments.count.must_equal 1
|
||||
profile_comment = site.profile_comments.first
|
||||
profile_comment.actioning_site.must_equal commenting_site
|
||||
profile_comment.message.must_equal 'I love your site!'
|
||||
end
|
||||
|
||||
it 'does not allow commenting without requirements met' do
|
||||
#site = Fabricate :site
|
||||
#commenting_site
|
||||
puts "FIXTHIS"
|
||||
end
|
||||
|
||||
it '404s for missing site' do
|
||||
visit '/site/failderp'
|
||||
page.status_code.must_equal 404
|
||||
|
|
|
@ -1,13 +1,46 @@
|
|||
require_relative './environment.rb'
|
||||
require 'rack/test'
|
||||
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app
|
||||
Sinatra::Application
|
||||
end
|
||||
|
||||
describe Site do
|
||||
describe 'can_email' do
|
||||
it 'should fail if send_emails is false' do
|
||||
site = Fabricate :site
|
||||
site.can_email?.must_equal true
|
||||
site.update send_emails: false
|
||||
site.can_email?.must_equal false
|
||||
site.can_email?(:send_comment_emails).must_equal false
|
||||
site.update send_emails: true
|
||||
site.can_email?(:send_comment_emails).must_equal true
|
||||
site.update send_comment_emails: false
|
||||
site.can_email?(:send_comment_emails).must_equal false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'send_email' do
|
||||
before do
|
||||
EmailWorker.jobs.clear
|
||||
@site = Fabricate :site
|
||||
end
|
||||
|
||||
it 'works' do
|
||||
@site.send_email(subject: 'Subject', body: 'Body')
|
||||
EmailWorker.jobs.length.must_equal 1
|
||||
args = EmailWorker.jobs.first['args'].first
|
||||
args['from'].must_equal Site::FROM_EMAIL
|
||||
args['to'].must_equal @site.email
|
||||
args['subject'].must_equal 'Subject'
|
||||
args['body'].must_equal 'Body'
|
||||
end
|
||||
|
||||
it 'fails if send_emails is false' do
|
||||
@site.update send_emails: false
|
||||
@site.send_email(subject: 'Subject', body: 'Body')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'plan_name' do
|
||||
it 'should set to free for missing stripe_customer_id' do
|
||||
site = Fabricate :site
|
||||
|
|
10
views/templates/email/new_comment.erb
Normal file
10
views/templates/email/new_comment.erb
Normal file
|
@ -0,0 +1,10 @@
|
|||
<%= actioning_site.username %> just commented on your site:
|
||||
|
||||
<%= message %>
|
||||
|
||||
---
|
||||
To view/reply, visit this link: https://neocities.org/site/<%= username %>?event_id=<%= profile_comment.event.id %>
|
||||
|
||||
Regards,
|
||||
|
||||
Neocities
|
Loading…
Add table
Reference in a new issue