proclaim 0.5.6 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/Rakefile +5 -38
- data/app/assets/config/proclaim_manifest.js +2 -0
- data/app/assets/images/{ajax_loader.gif → proclaim/ajax_loader.gif} +0 -0
- data/app/assets/javascripts/proclaim.js +7 -7
- data/app/assets/javascripts/proclaim/{comments_handler.js.coffee → comments_handler.coffee} +16 -10
- data/app/assets/javascripts/proclaim/editor.coffee +55 -0
- data/app/assets/stylesheets/{proclaim.css.scss → proclaim.scss} +7 -8
- data/app/assets/stylesheets/proclaim/{comments.css.scss → comments.scss} +0 -0
- data/app/assets/stylesheets/proclaim/{posts.css.scss → posts.scss} +60 -25
- data/app/assets/stylesheets/proclaim/{subscriptions.css.scss → subscriptions.scss} +0 -0
- data/app/controllers/proclaim/application_controller.rb +60 -56
- data/app/controllers/proclaim/comments_controller.rb +13 -42
- data/app/controllers/proclaim/posts_controller.rb +25 -57
- data/app/controllers/proclaim/subscriptions_controller.rb +3 -3
- data/app/jobs/proclaim/application_job.rb +4 -0
- data/app/mailers/proclaim/application_mailer.rb +5 -0
- data/app/mailers/proclaim/subscription_mailer.rb +19 -17
- data/app/models/proclaim/application_record.rb +5 -0
- data/app/models/proclaim/comment.rb +6 -1
- data/app/models/proclaim/post.rb +20 -28
- data/app/models/proclaim/subscription.rb +33 -11
- data/app/views/layouts/proclaim/subscription_mailer.html.erb +15 -36
- data/app/views/proclaim/comments/_comment.html.erb +7 -7
- data/app/views/proclaim/comments/_form.html.erb +7 -5
- data/app/views/proclaim/posts/_form.html.erb +34 -21
- data/app/views/proclaim/posts/show.html.erb +16 -3
- data/app/views/proclaim/subscription_mailer/welcome_email.html.erb +2 -6
- data/config/initializers/friendly_id.rb +20 -1
- data/config/routes.rb +1 -5
- data/db/migrate/20141108222616_create_proclaim_posts.rb +8 -1
- data/db/migrate/20141114235359_create_proclaim_comments.rb +1 -1
- data/db/migrate/20141115022230_create_proclaim_comment_hierarchies.rb +1 -1
- data/db/migrate/20141210234057_create_proclaim_subscriptions.rb +5 -4
- data/db/migrate/20150213015321_create_friendly_id_slugs.rb +1 -1
- data/lib/generators/proclaim/install_generator.rb +1 -1
- data/lib/generators/proclaim/templates/initialize_proclaim.rb +31 -29
- data/lib/generators/proclaim/views_generator.rb +1 -1
- data/lib/proclaim.rb +15 -15
- data/lib/proclaim/engine.rb +21 -19
- data/lib/proclaim/version.rb +1 -1
- data/vendor/assets/fonts/KaTeX_AMS-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_AMS-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_AMS-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Fraktur-Bold.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Fraktur-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Main-Bold.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Main-Bold.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Main-Bold.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Main-BoldItalic.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Main-Italic.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Main-Italic.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Main-Italic.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Main-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Main-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Main-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Math-BoldItalic.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Math-Italic.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Math-Italic.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Math-Italic.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_SansSerif-Bold.woff +0 -0
- data/vendor/assets/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_SansSerif-Italic.woff +0 -0
- data/vendor/assets/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_SansSerif-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Script-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Script-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Script-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Size1-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Size1-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Size1-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Size2-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Size2-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Size2-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Size3-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Size3-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Size3-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Size4-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Size4-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Size4-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Typewriter-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
- data/vendor/assets/javascripts/contrib/auto-render.js +339 -0
- data/vendor/assets/javascripts/contrib/auto-render.min.js +1 -0
- data/vendor/assets/javascripts/contrib/auto-render.mjs +215 -0
- data/vendor/assets/javascripts/contrib/copy-tex.css +14 -0
- data/vendor/assets/javascripts/contrib/copy-tex.js +213 -0
- data/vendor/assets/javascripts/contrib/copy-tex.min.css +1 -0
- data/vendor/assets/javascripts/contrib/copy-tex.min.js +1 -0
- data/vendor/assets/javascripts/contrib/copy-tex.mjs +85 -0
- data/vendor/assets/javascripts/contrib/mathtex-script-type.js +137 -0
- data/vendor/assets/javascripts/contrib/mathtex-script-type.min.js +1 -0
- data/vendor/assets/javascripts/contrib/mathtex-script-type.mjs +24 -0
- data/vendor/assets/javascripts/contrib/mhchem.js +3241 -0
- data/vendor/assets/javascripts/contrib/mhchem.min.js +1 -0
- data/vendor/assets/javascripts/contrib/mhchem.mjs +3109 -0
- data/vendor/assets/javascripts/katex.js +16517 -0
- data/vendor/assets/javascripts/katex.min.js +1 -0
- data/vendor/assets/javascripts/katex.mjs +16122 -0
- data/vendor/assets/javascripts/quill.core.js +8522 -0
- data/vendor/assets/javascripts/quill.js +11489 -0
- data/vendor/assets/javascripts/quill.min.js +8 -0
- data/vendor/assets/javascripts/quill.min.js.map +1 -0
- data/vendor/assets/stylesheets/katex.css +1011 -0
- data/vendor/assets/stylesheets/katex.min.css +1 -0
- data/vendor/assets/stylesheets/quill.bubble.css +952 -0
- data/vendor/assets/stylesheets/quill.core.css +397 -0
- data/vendor/assets/stylesheets/quill.snow.css +945 -0
- metadata +169 -278
- data/CHANGELOG +0 -77
- data/Gemfile +0 -14
- data/VERSION +0 -1
- data/app/assets/javascripts/proclaim/editor.js.coffee +0 -52
- data/app/assets/javascripts/proclaim/images.js.coffee +0 -3
- data/app/assets/javascripts/proclaim/subscriptions.js.coffee +0 -3
- data/app/assets/stylesheets/proclaim/images.scss +0 -3
- data/app/controllers/proclaim/images_controller.rb +0 -67
- data/app/helpers/proclaim/comments_helper.rb +0 -4
- data/app/helpers/proclaim/images_helper.rb +0 -4
- data/app/helpers/proclaim/subscriptions_helper.rb +0 -4
- data/app/models/proclaim/image.rb +0 -19
- data/app/policies/proclaim/image_policy.rb +0 -29
- data/app/uploaders/proclaim/image_uploader.rb +0 -82
- data/db/migrate/20141222224905_create_proclaim_images.rb +0 -12
- data/db/migrate/20150123115226_add_name_to_subscriptions.rb +0 -7
- data/db/migrate/20150213015850_add_slug_to_posts.rb +0 -20
- data/proclaim.gemspec +0 -51
- data/test/controllers/proclaim/comments_controller_test.rb +0 -228
- data/test/controllers/proclaim/images_controller_test.rb +0 -166
- data/test/controllers/proclaim/posts_controller_test.rb +0 -465
- data/test/controllers/proclaim/subscriptions_controller_test.rb +0 -154
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/Rakefile +0 -6
- data/test/dummy/app/assets/javascripts/application.js +0 -14
- data/test/dummy/app/assets/stylesheets/application.css +0 -16
- data/test/dummy/app/controllers/application_controller.rb +0 -15
- data/test/dummy/app/helpers/application_helper.rb +0 -28
- data/test/dummy/app/models/user.rb +0 -7
- data/test/dummy/app/views/layouts/application.html.erb +0 -16
- data/test/dummy/bin/bundle +0 -3
- data/test/dummy/bin/rails +0 -4
- data/test/dummy/bin/rake +0 -4
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -24
- data/test/dummy/config/boot.rb +0 -5
- data/test/dummy/config/database.yml +0 -25
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -45
- data/test/dummy/config/environments/production.rb +0 -80
- data/test/dummy/config/environments/test.rb +0 -49
- data/test/dummy/config/initializers/assets.rb +0 -8
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/test/dummy/config/initializers/inflections.rb +0 -16
- data/test/dummy/config/initializers/mime_types.rb +0 -4
- data/test/dummy/config/initializers/session_store.rb +0 -3
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -23
- data/test/dummy/config/routes.rb +0 -5
- data/test/dummy/config/secrets.yml +0 -22
- data/test/dummy/db/migrate/20141117214323_create_users.rb +0 -10
- data/test/dummy/db/schema.rb +0 -91
- data/test/dummy/public/404.html +0 -67
- data/test/dummy/public/422.html +0 -67
- data/test/dummy/public/500.html +0 -66
- data/test/dummy/public/favicon.ico +0 -0
- data/test/factories/proclaim/comment.rb +0 -11
- data/test/factories/proclaim/image.rb +0 -6
- data/test/factories/proclaim/post.rb +0 -14
- data/test/factories/proclaim/subscription.rb +0 -14
- data/test/factories/user.rb +0 -6
- data/test/helpers/proclaim/comments_helper_test.rb +0 -6
- data/test/helpers/proclaim/posts_helper_test.rb +0 -6
- data/test/helpers/proclaim/subscriptions_helper_test.rb +0 -6
- data/test/integration/with_javascript/comment_test.rb +0 -391
- data/test/integration/with_javascript/post_form_test.rb +0 -225
- data/test/integration/with_javascript/post_show_test.rb +0 -47
- data/test/integration/with_javascript/post_subscription_test.rb +0 -302
- data/test/integration/without_javascript/blog_subscription_test.rb +0 -114
- data/test/integration/without_javascript/manage_subscriptions_test.rb +0 -37
- data/test/integration/without_javascript/post_test.rb +0 -234
- data/test/integration/without_javascript/subscription_email_test.rb +0 -95
- data/test/integration/without_javascript/unsubscribe_test.rb +0 -32
- data/test/mailers/previews/proclaim/subscription_mailer_preview.rb +0 -22
- data/test/mailers/proclaim/subscription_mailer_test.rb +0 -91
- data/test/models/proclaim/comment_test.rb +0 -41
- data/test/models/proclaim/image_test.rb +0 -70
- data/test/models/proclaim/post_test.rb +0 -193
- data/test/models/proclaim/subscription_test.rb +0 -77
- data/test/policies/application_policy_test.rb +0 -87
- data/test/policies/proclaim/comment_policy_test.rb +0 -71
- data/test/policies/proclaim/image_policy_test.rb +0 -83
- data/test/policies/proclaim/post_policy_test.rb +0 -98
- data/test/policies/proclaim/subscription_policy_test.rb +0 -103
- data/test/proclaim_test.rb +0 -7
- data/test/support/images/test.jpg +0 -0
- data/test/support/pages/posts/edit_page.rb +0 -5
- data/test/support/pages/posts/show_page.rb +0 -47
- data/test/support/wait_for_ajax.rb +0 -11
- data/test/test_helper.rb +0 -71
- data/test/unit/proclaim/new_comment_callback_test.rb +0 -62
- data/test/unit/proclaim/new_subscription_callback_test.rb +0 -62
- data/test/unit/proclaim/post_published_callback_test.rb +0 -74
- data/vendor/assets/images/link.png +0 -0
- data/vendor/assets/images/remove.png +0 -0
- data/vendor/assets/images/resize-bigger.png +0 -0
- data/vendor/assets/images/resize-smaller.png +0 -0
- data/vendor/assets/images/unlink.png +0 -0
- data/vendor/assets/javascripts/addons/medium-editor-insert-embeds.js +0 -197
- data/vendor/assets/javascripts/addons/medium-editor-insert-images.js +0 -572
- data/vendor/assets/javascripts/addons/medium-editor-insert-maps.js +0 -50
- data/vendor/assets/javascripts/addons/medium-editor-insert-plugin.js +0 -496
- data/vendor/assets/javascripts/addons/medium-editor-insert-tables.js +0 -132
- data/vendor/assets/javascripts/medium-editor-insert-plugin.all.js +0 -1415
- data/vendor/assets/stylesheets/medium-editor-insert-plugin-frontend.css.scss +0 -55
- data/vendor/assets/stylesheets/medium-editor-insert-plugin.css.scss +0 -277
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
require_dependency "proclaim/application_controller"
|
|
1
|
+
#require_dependency "proclaim/application_controller"
|
|
2
2
|
|
|
3
3
|
module Proclaim
|
|
4
|
-
class CommentsController < ApplicationController
|
|
4
|
+
class CommentsController < Proclaim::ApplicationController
|
|
5
5
|
before_action :authenticate_author, only: [:destroy]
|
|
6
6
|
after_action :verify_authorized
|
|
7
7
|
before_action :set_comment, only: [:update, :destroy]
|
|
@@ -9,41 +9,16 @@ module Proclaim
|
|
|
9
9
|
def create
|
|
10
10
|
@comment = Comment.new(comment_params)
|
|
11
11
|
|
|
12
|
-
subscription = nil
|
|
13
|
-
if subscription_params and subscription_params[:subscribe]
|
|
14
|
-
subscription = Subscription.new(name: @comment.author,
|
|
15
|
-
email: subscription_params[:email],
|
|
16
|
-
post: @comment.post)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
12
|
errors = Array.new
|
|
20
13
|
options = Hash.new
|
|
21
14
|
options[:success_json] = lambda {comment_json(@comment)}
|
|
22
15
|
options[:failure_json] = lambda {errors}
|
|
23
16
|
options[:operation] = lambda do
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
Comment.transaction do
|
|
30
|
-
@comment.save!
|
|
31
|
-
|
|
32
|
-
if subscription
|
|
33
|
-
subscription.save!
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
return true
|
|
37
|
-
end
|
|
38
|
-
rescue ActiveRecord::RecordInvalid
|
|
39
|
-
errors += @comment.errors.full_messages
|
|
40
|
-
|
|
41
|
-
if subscription
|
|
42
|
-
errors += subscription.errors.full_messages
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
return false
|
|
46
|
-
end
|
|
17
|
+
if @comment.save
|
|
18
|
+
return true
|
|
19
|
+
else
|
|
20
|
+
errors += @comment.errors.full_messages
|
|
21
|
+
return false
|
|
47
22
|
end
|
|
48
23
|
end
|
|
49
24
|
|
|
@@ -91,17 +66,13 @@ module Proclaim
|
|
|
91
66
|
|
|
92
67
|
# Only allow a trusted parameter "white list" through.
|
|
93
68
|
def comment_params
|
|
94
|
-
params.require(:comment).permit(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
def subscription_params
|
|
101
|
-
if params[:subscription]
|
|
102
|
-
params.require(:subscription).permit(:subscribe,
|
|
103
|
-
:email)
|
|
69
|
+
p = params.require(:comment).permit(
|
|
70
|
+
:body, :author, :post_id, :parent_id,
|
|
71
|
+
subscription_attributes: [:email])
|
|
72
|
+
if params[:subscribe] && p.include?('subscription_attributes')
|
|
73
|
+
p[:subscription_attributes].merge!({name: p[:author]})
|
|
104
74
|
end
|
|
75
|
+
p
|
|
105
76
|
end
|
|
106
77
|
|
|
107
78
|
def antispam_params
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
require_dependency "proclaim/application_controller"
|
|
1
|
+
#require_dependency "proclaim/application_controller"
|
|
2
2
|
|
|
3
3
|
module Proclaim
|
|
4
|
-
class PostsController < ApplicationController
|
|
4
|
+
class PostsController < Proclaim::ApplicationController
|
|
5
5
|
before_action :authenticate_author, except: [:index, :show]
|
|
6
6
|
after_action :verify_authorized
|
|
7
7
|
after_action :verify_policy_scoped, only: :index
|
|
@@ -15,19 +15,13 @@ module Proclaim
|
|
|
15
15
|
|
|
16
16
|
# GET /posts/1
|
|
17
17
|
def show
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return redirect_to @post, status: :moved_permanently
|
|
26
|
-
end
|
|
27
|
-
rescue Pundit::NotAuthorizedError
|
|
28
|
-
# Don't leak that this resource actually exists. Turn the
|
|
29
|
-
# "permission denied" into a "not found"
|
|
30
|
-
raise ActiveRecord::RecordNotFound
|
|
18
|
+
authorize @post
|
|
19
|
+
|
|
20
|
+
# If an old id or a numeric id was used to find the record, then
|
|
21
|
+
# the request path will not match the post_path, and we should do
|
|
22
|
+
# a 301 redirect that uses the current friendly id.
|
|
23
|
+
if request.path != post_path(@post)
|
|
24
|
+
return redirect_to @post, status: :moved_permanently
|
|
31
25
|
end
|
|
32
26
|
end
|
|
33
27
|
|
|
@@ -47,22 +41,13 @@ module Proclaim
|
|
|
47
41
|
@post = Post.new(post_params)
|
|
48
42
|
@post.author = current_author
|
|
49
43
|
|
|
44
|
+
if params[:publish] == "true"
|
|
45
|
+
@post.publish
|
|
46
|
+
end
|
|
47
|
+
|
|
50
48
|
authorize @post
|
|
51
49
|
|
|
52
|
-
# Save here before potentially publishing, so we can save images
|
|
53
50
|
if @post.save
|
|
54
|
-
|
|
55
|
-
if params[:publish] == "true"
|
|
56
|
-
@post.publish
|
|
57
|
-
authorize @post # Re-authorize now that it's to be published
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# Save and rewrite each image in Carrierwave's cache
|
|
61
|
-
@post.body = saved_and_rewrite_cached_images(@post.body)
|
|
62
|
-
|
|
63
|
-
# Save again, in case the body changed or it was published
|
|
64
|
-
@post.save
|
|
65
|
-
|
|
66
51
|
redirect_to @post, notice: 'Post was successfully created.'
|
|
67
52
|
else
|
|
68
53
|
render :new
|
|
@@ -80,12 +65,7 @@ module Proclaim
|
|
|
80
65
|
|
|
81
66
|
authorize @post
|
|
82
67
|
|
|
83
|
-
if @post.
|
|
84
|
-
# Save and rewrite each image in Carrierwave's cache
|
|
85
|
-
@post.body = saved_and_rewrite_cached_images(@post.body)
|
|
86
|
-
|
|
87
|
-
@post.save
|
|
88
|
-
|
|
68
|
+
if @post.save
|
|
89
69
|
redirect_to @post, notice: 'Post was successfully updated.'
|
|
90
70
|
else
|
|
91
71
|
render :edit
|
|
@@ -102,6 +82,16 @@ module Proclaim
|
|
|
102
82
|
|
|
103
83
|
private
|
|
104
84
|
|
|
85
|
+
def user_not_authorized(exception)
|
|
86
|
+
if exception.policy.is_a? PostPolicy and exception.query == "show?"
|
|
87
|
+
# Don't leak that this resource actually exists. Turn the
|
|
88
|
+
# "permission denied" into a "not found"
|
|
89
|
+
raise ActiveRecord::RecordNotFound
|
|
90
|
+
else
|
|
91
|
+
super()
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
105
95
|
# Use callbacks to share common setup or constraints between actions.
|
|
106
96
|
def set_post
|
|
107
97
|
@post = Post.friendly.find(params[:id])
|
|
@@ -114,29 +104,7 @@ module Proclaim
|
|
|
114
104
|
params[:post][:title] = HTMLEntities.new.decode(Rails::Html::FullSanitizer.new.sanitize(params[:post][:title]))
|
|
115
105
|
end
|
|
116
106
|
|
|
117
|
-
params.require(:post).permit(:title,
|
|
118
|
-
:body,
|
|
119
|
-
images_attributes: [:id, :image, :_destroy])
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def saved_and_rewrite_cached_images(body)
|
|
123
|
-
document = Nokogiri::HTML.fragment(body)
|
|
124
|
-
cache_path = ImageUploader.cache_dir
|
|
125
|
-
document.css("img").each do |image_tag|
|
|
126
|
-
url = image_tag.attributes["src"].value
|
|
127
|
-
if url.include? cache_path
|
|
128
|
-
cache_name = cache_name_from_url(url)
|
|
129
|
-
if cache_name
|
|
130
|
-
image = @post.images.build
|
|
131
|
-
image.image.retrieve_from_cache!(cache_name)
|
|
132
|
-
image.save
|
|
133
|
-
|
|
134
|
-
image_tag.attributes["src"].value = image.image.url
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
document.inner_html
|
|
107
|
+
params.require(:post).permit(:title, :body, :quill_body)
|
|
140
108
|
end
|
|
141
109
|
end
|
|
142
110
|
end
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
require_dependency "proclaim/application_controller"
|
|
1
|
+
#require_dependency "proclaim/application_controller"
|
|
2
2
|
|
|
3
3
|
module Proclaim
|
|
4
|
-
class SubscriptionsController < ApplicationController
|
|
4
|
+
class SubscriptionsController < Proclaim::ApplicationController
|
|
5
5
|
after_action :verify_authorized
|
|
6
6
|
after_action :verify_policy_scoped, only: :index
|
|
7
7
|
before_action :set_subscription, only: [:show, :edit, :update, :destroy]
|
|
8
8
|
|
|
9
9
|
def index
|
|
10
|
-
@subscriptions = policy_scope(Subscription).order(:
|
|
10
|
+
@subscriptions = policy_scope(Subscription).order(:comment_id, :name)
|
|
11
11
|
authorize Subscription
|
|
12
12
|
end
|
|
13
13
|
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
module Proclaim
|
|
2
|
-
class SubscriptionMailer <
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def welcome_email(subscription)
|
|
6
|
-
@subscription = subscription
|
|
2
|
+
class SubscriptionMailer < ApplicationMailer
|
|
3
|
+
before_action :set_subscription
|
|
7
4
|
|
|
5
|
+
def welcome_email
|
|
8
6
|
message = Premailer.new(render_to_string, with_html_string: true, base_url: root_url)
|
|
9
7
|
base_url = root_url.gsub(/\A.*:\/\//, '').gsub(/\A(.*?)\/*\z/, '\1')
|
|
10
8
|
|
|
@@ -14,30 +12,34 @@ module Proclaim
|
|
|
14
12
|
end
|
|
15
13
|
end
|
|
16
14
|
|
|
17
|
-
def new_comment_notification_email
|
|
18
|
-
@
|
|
19
|
-
@comment = comment
|
|
15
|
+
def new_comment_notification_email
|
|
16
|
+
@comment = Comment.find(params[:comment_id])
|
|
20
17
|
|
|
21
18
|
message = Premailer.new(render_to_string, with_html_string: true, base_url: root_url)
|
|
22
19
|
|
|
23
20
|
mail to: @subscription.email,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
subject: "New Comment On \"#{@comment.post.title}\"" do |format|
|
|
22
|
+
format.html { message.to_inline_css }
|
|
23
|
+
format.text { message.to_plain_text }
|
|
27
24
|
end
|
|
28
25
|
end
|
|
29
26
|
|
|
30
|
-
def new_post_notification_email
|
|
31
|
-
@
|
|
32
|
-
@post = post
|
|
27
|
+
def new_post_notification_email
|
|
28
|
+
@post = Post.find(params[:post_id])
|
|
33
29
|
|
|
34
30
|
message = Premailer.new(render_to_string, with_html_string: true, base_url: root_url)
|
|
35
31
|
|
|
36
32
|
mail to: @subscription.email,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
subject: "New Post: #{@post.title}" do |format|
|
|
34
|
+
format.html { message.to_inline_css }
|
|
35
|
+
format.text { message.to_plain_text }
|
|
40
36
|
end
|
|
41
37
|
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def set_subscription
|
|
42
|
+
@subscription = Subscription.find(params[:subscription_id])
|
|
43
|
+
end
|
|
42
44
|
end
|
|
43
45
|
end
|
|
@@ -15,12 +15,17 @@ module Proclaim
|
|
|
15
15
|
class Comment < ActiveRecord::Base
|
|
16
16
|
acts_as_tree order: 'created_at ASC', dependent: :destroy
|
|
17
17
|
belongs_to :post, inverse_of: :comments
|
|
18
|
+
has_one :subscription, inverse_of: :comment, dependent: :destroy
|
|
18
19
|
after_initialize :maintainPost
|
|
19
|
-
|
|
20
|
+
|
|
21
|
+
# Using after_commit since we use deliver_later and re-load them from the database
|
|
22
|
+
after_create_commit :notifyPostSubscribers
|
|
20
23
|
after_create { Proclaim.notify_new_comment(self) }
|
|
21
24
|
|
|
22
25
|
validates_presence_of :body, :author, :post
|
|
23
26
|
|
|
27
|
+
accepts_nested_attributes_for :subscription, reject_if: :all_blank
|
|
28
|
+
|
|
24
29
|
private
|
|
25
30
|
|
|
26
31
|
def maintainPost
|
data/app/models/proclaim/post.rb
CHANGED
|
@@ -2,23 +2,23 @@
|
|
|
2
2
|
#
|
|
3
3
|
# Table name: proclaim_posts
|
|
4
4
|
#
|
|
5
|
-
# id
|
|
6
|
-
# author_id
|
|
7
|
-
# title
|
|
8
|
-
# body
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
5
|
+
# id :integer not null, primary key
|
|
6
|
+
# author_id :integer
|
|
7
|
+
# title :string default(""), not null
|
|
8
|
+
# body :text default(""), not null
|
|
9
|
+
# quill_body :text default(""), not null
|
|
10
|
+
# state :string default("draft"), not null
|
|
11
|
+
# slug :string
|
|
12
|
+
# published_at :datetime
|
|
13
|
+
# created_at :datetime not null
|
|
14
|
+
# updated_at :datetime not null
|
|
13
15
|
#
|
|
14
16
|
|
|
15
17
|
module Proclaim
|
|
16
18
|
class Post < ActiveRecord::Base
|
|
17
19
|
belongs_to :author, class_name: Proclaim.author_class
|
|
18
20
|
has_many :comments, inverse_of: :post, dependent: :destroy
|
|
19
|
-
has_many :subscriptions,
|
|
20
|
-
has_many :images, inverse_of: :post, dependent: :destroy
|
|
21
|
-
accepts_nested_attributes_for :images, allow_destroy: true
|
|
21
|
+
has_many :subscriptions, through: :comments
|
|
22
22
|
|
|
23
23
|
extend FriendlyId
|
|
24
24
|
friendly_id :slug_candidates, use: :history
|
|
@@ -40,13 +40,13 @@ module Proclaim
|
|
|
40
40
|
validates_presence_of :published_at, if: :published?
|
|
41
41
|
validates :published_at, absence: true, unless: :published?
|
|
42
42
|
|
|
43
|
-
validates_presence_of :title, :body, :author
|
|
43
|
+
validates_presence_of :title, :body, :quill_body, :author
|
|
44
44
|
validate :verifyBodyHtml
|
|
45
45
|
|
|
46
46
|
after_validation :move_friendly_id_error_to_title
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
# Using after_commit since we use deliver_later and re-load them from the database
|
|
49
|
+
after_commit :notifyBlogSubscribersIfPublished, on: [:create, :update]
|
|
50
50
|
|
|
51
51
|
# Only save the slug history if the post is published
|
|
52
52
|
def create_slug
|
|
@@ -60,7 +60,7 @@ module Proclaim
|
|
|
60
60
|
|
|
61
61
|
attr_writer :excerpt_length
|
|
62
62
|
def excerpt_length
|
|
63
|
-
@excerpt_length
|
|
63
|
+
@excerpt_length ||= Proclaim.excerpt_length
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
def body_plaintext
|
|
@@ -79,7 +79,10 @@ module Proclaim
|
|
|
79
79
|
|
|
80
80
|
def notifyPostSubscribers(newComment)
|
|
81
81
|
subscriptions.each do | subscription |
|
|
82
|
-
|
|
82
|
+
# Don't notify the commenter of own comment
|
|
83
|
+
if subscription.comment_id != newComment.id
|
|
84
|
+
subscription.deliver_new_comment_notification_email(newComment)
|
|
85
|
+
end
|
|
83
86
|
end
|
|
84
87
|
end
|
|
85
88
|
|
|
@@ -110,17 +113,6 @@ module Proclaim
|
|
|
110
113
|
end
|
|
111
114
|
end
|
|
112
115
|
|
|
113
|
-
def sanitizeBody
|
|
114
|
-
unless Proclaim.editor_whitelist_tags.blank? and
|
|
115
|
-
Proclaim.editor_whitelist_attributes.blank?
|
|
116
|
-
sanitizer = Rails::Html::WhiteListSanitizer.new
|
|
117
|
-
self.body = sanitizer.sanitize(
|
|
118
|
-
body,
|
|
119
|
-
tags: Proclaim.editor_whitelist_tags,
|
|
120
|
-
attributes: Proclaim.editor_whitelist_attributes)
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
|
|
124
116
|
def takeExcerptOf(text)
|
|
125
117
|
if excerpt_length >= text.length
|
|
126
118
|
return text
|
|
@@ -168,7 +160,7 @@ module Proclaim
|
|
|
168
160
|
|
|
169
161
|
def notifyBlogSubscribersIfPublished
|
|
170
162
|
# If we just published this post, notify the subscribers
|
|
171
|
-
if published? and
|
|
163
|
+
if published? and saved_change_to_state?
|
|
172
164
|
Proclaim.notify_post_published(self)
|
|
173
165
|
|
|
174
166
|
Subscription.blog_subscriptions.each do | subscription |
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
# Table name: proclaim_subscriptions
|
|
4
4
|
#
|
|
5
5
|
# id :integer not null, primary key
|
|
6
|
-
#
|
|
6
|
+
# comment_id :integer
|
|
7
|
+
# name :string default(""), not null
|
|
7
8
|
# email :string
|
|
8
9
|
# created_at :datetime not null
|
|
9
10
|
# updated_at :datetime not null
|
|
@@ -11,33 +12,39 @@
|
|
|
11
12
|
|
|
12
13
|
module Proclaim
|
|
13
14
|
class Subscription < ActiveRecord::Base
|
|
14
|
-
scope :blog_subscriptions, -> { where(
|
|
15
|
-
belongs_to :
|
|
15
|
+
scope :blog_subscriptions, -> { where(comment_id: nil) }
|
|
16
|
+
belongs_to :comment, inverse_of: :subscription, optional: true
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
# Get the comment's post as our own
|
|
19
|
+
delegate :post, to: :comment, allow_nil: true
|
|
20
|
+
|
|
21
|
+
# Using after_commit since we use deliver_later and re-load them from the database
|
|
22
|
+
after_create_commit :deliver_welcome_email
|
|
18
23
|
after_create { Proclaim.notify_new_subscription(self) }
|
|
19
24
|
|
|
20
25
|
# RFC-compliant email addresses are way nasty to match with regex, so why
|
|
21
26
|
# try? We'll be sending them an email anyway-- if they don't get it, they
|
|
22
27
|
# can re-subscribe. We'll just do an easy validation match here.
|
|
23
|
-
validates :email,
|
|
28
|
+
validates :email, format: { with: /@/ }
|
|
24
29
|
|
|
25
30
|
validates_presence_of :name
|
|
26
31
|
|
|
27
|
-
# Subscriptions aren't required to belong to a
|
|
28
|
-
# one it had better be valid
|
|
29
|
-
validates_presence_of :
|
|
32
|
+
# Subscriptions aren't required to belong to a comment, but if we're
|
|
33
|
+
# given one it had better be valid
|
|
34
|
+
validates_presence_of :comment, if: :comment_id
|
|
35
|
+
|
|
36
|
+
validate :email_is_unique
|
|
30
37
|
|
|
31
38
|
def deliver_welcome_email
|
|
32
|
-
SubscriptionMailer.
|
|
39
|
+
SubscriptionMailer.with(subscription_id: id).welcome_email.deliver_later
|
|
33
40
|
end
|
|
34
41
|
|
|
35
42
|
def deliver_new_post_notification_email(post)
|
|
36
|
-
SubscriptionMailer.
|
|
43
|
+
SubscriptionMailer.with(subscription_id: id, post_id: post.id).new_post_notification_email.deliver_later
|
|
37
44
|
end
|
|
38
45
|
|
|
39
46
|
def deliver_new_comment_notification_email(comment)
|
|
40
|
-
SubscriptionMailer.
|
|
47
|
+
SubscriptionMailer.with(subscription_id: id, comment_id: comment.id).new_comment_notification_email.deliver_later
|
|
41
48
|
end
|
|
42
49
|
|
|
43
50
|
def token
|
|
@@ -60,5 +67,20 @@ module Proclaim
|
|
|
60
67
|
def self.create_token(subscription)
|
|
61
68
|
verifier.generate(subscription.id)
|
|
62
69
|
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
def email_is_unique
|
|
74
|
+
other_subscriptions = Subscription.where(email: email)
|
|
75
|
+
unless other_subscriptions.empty?
|
|
76
|
+
other_subscriptions.each do | other_subscription |
|
|
77
|
+
if comment.nil? && other_subscription.comment.nil?
|
|
78
|
+
errors.add(:email, "is already subscribed")
|
|
79
|
+
elsif comment.post == other_subscription.post
|
|
80
|
+
errors.add(:email, "is already subscribed to comments on this post")
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
63
85
|
end
|
|
64
86
|
end
|