biovision-comment 0.7.190905.0 → 0.8.190926.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a602c3288d543c9a10860099700cb6657f206b3b6dce1b88a82c5ad1c239b5c8
4
- data.tar.gz: 552231814a6ad6ed6b43c1edbc12b195192090e2ef821d73b962c1c6cd1850b4
3
+ metadata.gz: 7aa9177ba4ca81f53183269587c9ff8d1ab7da046904e65616a72686856b1b44
4
+ data.tar.gz: 24550aecb8c28841f760bbe9f4caef9ca502efb0c396450ab39f5a18f2499856
5
5
  SHA512:
6
- metadata.gz: ba351318a8b74404e890374ae9c9a1cfab90924d25c10dc0374660fba6b014005e7ce4105ca3f6ce4805939935cbd52fd4517d4cda960057e1e2c23bbbc6badb
7
- data.tar.gz: 5272919b6715ef8641f458257d9d35f2638b5c4cb6b593163c1fe44e0e3c5d8da2a265477a205bc338b7bd5625282d9330b7db042de7e1b3556fd04a14ea3a1e
6
+ metadata.gz: b49ee2521b7c018184f042c464d905c6209452f21aacdb636327a4a07fe254ea79a34ff522ff7257531727e441076e8faf4f683fb8c3e235291904d58c7e8134
7
+ data.tar.gz: 967b2cb830a8f4076c45c4ccdac61152f88943e67e0a3b5d13c642241e896bd6464c55f017f48884a5e7e4327214ceaa879a4d7cdda6dab94c06f297272370f2
@@ -115,4 +115,60 @@ Comments.components.replyFormMover = {
115
115
  }
116
116
  };
117
117
 
118
+ Comments.components.commentApproval = {
119
+ initialized: false,
120
+ selector: ".js-approve-comment",
121
+ buttons: [],
122
+ init: function () {
123
+ document.querySelectorAll(this.selector).forEach(this.apply);
124
+ this.initialized = true;
125
+ },
126
+ apply: function (button) {
127
+ const component = Comments.components.commentApproval;
128
+ component.buttons.push(button);
129
+ button.addEventListener("click", component.click);
130
+ },
131
+ click: function (event) {
132
+ const button = event.target;
133
+ const url = button.getAttribute("data-url");
134
+ const request = Biovision.jsonAjaxRequest("put", url, function () {
135
+ const container = button.closest("div");
136
+ container.remove();
137
+ }, function () {
138
+ button.disabled = false;
139
+ });
140
+
141
+ button.disabled = true;
142
+ request.send();
143
+ }
144
+ };
145
+
146
+ Comments.components.commentDelete = {
147
+ initialized: false,
148
+ selector: ".js-delete-comment",
149
+ buttons: [],
150
+ init: function () {
151
+ document.querySelectorAll(this.selector).forEach(this.apply);
152
+ this.initialized = true;
153
+ },
154
+ apply: function (button) {
155
+ const component = Comments.components.commentDelete;
156
+ component.buttons.push(button);
157
+ button.addEventListener("click", component.click);
158
+ },
159
+ click: function (event) {
160
+ const button = event.target;
161
+ const url = button.getAttribute("data-url");
162
+ const request = Biovision.jsonAjaxRequest("delete", url, function () {
163
+ const container = button.closest("div");
164
+ container.remove();
165
+ }, function () {
166
+ button.disabled = false;
167
+ });
168
+
169
+ button.disabled = true;
170
+ request.send();
171
+ }
172
+ };
173
+
118
174
  Biovision.components.comments = Comments;
@@ -148,6 +148,10 @@ $row-background-odd: #fafafa !default;
148
148
  }
149
149
  }
150
150
  }
151
+
152
+ .children {
153
+ margin-left: var(--spacer-xs, .8rem);
154
+ }
151
155
  }
152
156
 
153
157
  .comment-form {
@@ -23,6 +23,12 @@ class Admin::CommentsController < AdminController
23
23
  head :no_content
24
24
  end
25
25
 
26
+ def destroy
27
+ @entity.destroy
28
+
29
+ head :no_content
30
+ end
31
+
26
32
  protected
27
33
 
28
34
  def component_slug
@@ -2,7 +2,6 @@
2
2
 
3
3
  # Comments
4
4
  class CommentsController < ApplicationController
5
- before_action :set_handler
6
5
  before_action :restrict_access, except: %i[check create]
7
6
  before_action :set_entity, only: %i[edit update destroy]
8
7
 
@@ -45,6 +44,11 @@ class CommentsController < ApplicationController
45
44
  redirect_to(@entity.commentable || admin_comments_path)
46
45
  end
47
46
 
47
+ # get /comments/:id
48
+ def show
49
+ redirect_to(admin_comment_path(id: params[:id]))
50
+ end
51
+
48
52
  private
49
53
 
50
54
  def component_slug
@@ -86,6 +90,7 @@ class CommentsController < ApplicationController
86
90
  end
87
91
 
88
92
  def notify_participants
93
+ flash[:notice] = t('comments.create.premoderation') unless @entity.approved?
89
94
  # to be implemented...
90
95
  end
91
96
  end
@@ -48,7 +48,8 @@ class Comment < ApplicationRecord
48
48
 
49
49
  scope :recent, -> { order 'id desc' }
50
50
  scope :chronological, -> { order 'id asc' }
51
- scope :visible, -> { where(deleted: false, visible: true, spam: false) } #, approved: true) }
51
+ scope :approved, -> { where(approved: true) }
52
+ scope :visible, -> { approved.where(deleted: false, visible: true, spam: false) }
52
53
  scope :list_for_administration, -> { recent }
53
54
  scope :list_for_visitors, -> { visible.chronological }
54
55
  scope :list_for_visitors_recent, -> { visible.recent }
@@ -17,6 +17,7 @@ module Biovision
17
17
  # @param [Hash] parameters
18
18
  def create_comment(parameters)
19
19
  @comment = ::Comment.new(parameters)
20
+ @comment.approved = approval_flag if settings['premoderation']
20
21
  @comment.save
21
22
  @comment
22
23
  end
@@ -34,6 +35,20 @@ module Biovision
34
35
 
35
36
  result
36
37
  end
38
+
39
+ def approval_flag
40
+ threshold = settings['auto_approve_threshold']
41
+ if @comment.user.nil?
42
+ criteria = {
43
+ user_id: nil,
44
+ ip: @comment.ip,
45
+ agent_id: @comment.agent_id
46
+ }
47
+ ::Comment.approved.where(criteria).count >= threshold
48
+ else
49
+ ::Comment.approved.owned_by(@comment.user).count >= threshold
50
+ end
51
+ end
37
52
  end
38
53
  end
39
54
  end
@@ -8,7 +8,7 @@ class CommentHandler
8
8
  def initialize(user = nil)
9
9
  slug = Biovision::Components::CommentsComponent::SLUG
10
10
  @user = user
11
- @handler = Biovision::Components::BaseComponent.handler(slug)
11
+ @handler = Biovision::Components::BaseComponent.handler(slug, user)
12
12
  end
13
13
 
14
14
  # Get list of comments for entity
@@ -18,7 +18,7 @@ class CommentHandler
18
18
  #
19
19
  # @param [ApplicationRecord] entity
20
20
  def list(entity)
21
- if @handler.class.allow?(@user)
21
+ if @handler.allow?
22
22
  entity.comments.list_for_administration
23
23
  else
24
24
  entity.comments.list_for_visitors
@@ -32,16 +32,21 @@ class CommentHandler
32
32
  # comments must be more than threshold; anonymous comments are always
33
33
  # non-approved.
34
34
  def approve?
35
- return true unless @component.settings['premoderate']
35
+ return true unless @handler.settings['premoderate']
36
36
  return false if @user.nil?
37
- return true if @component.class.allow?(@user)
37
+ return true if @handler.allow?
38
38
 
39
- gate = @component.settings['auto_approve_threshold'].to_i
39
+ gate = @handler.settings['auto_approve_threshold'].to_i
40
40
  positive = Comment.where(user: @user, approved: true).count
41
41
  negative = Comment.where(user: @user, approved: false).count
42
42
  positive - negative >= gate
43
43
  end
44
44
 
45
+ # @param [String] privilege_name
46
+ def allow?(*privilege_name)
47
+ @handler.allow?(*privilege_name)
48
+ end
49
+
45
50
  # @param [ApplicationRecord] entity
46
51
  def allow_reply?(entity)
47
52
  entity.respond_to?(:commentable_by?) && entity.commentable_by?(@user)
@@ -6,19 +6,11 @@ class CommentsManager
6
6
  # @param [TrueClass|FalseClass] anchor
7
7
  def self.commentable_path(comment, anchor = false)
8
8
  method_name = "#{comment.commentable_type}_path".downcase.to_sym
9
- if respond_to?(method_name)
10
- result = send(method_name, comment.commentable)
9
+ if comment.commentable.respond_to?(:url)
10
+ result = comment.commentable.url
11
11
  anchor ? "#{result}#comment-#{comment.id}" : result
12
12
  else
13
13
  "##{method_name}"
14
14
  end
15
15
  end
16
-
17
- # @param [Post] entity
18
- def self.post_path(entity)
19
- return '#post' unless Gem.loaded_specs.key?('biovision-post')
20
-
21
- handler = PostManager.new(entity)
22
- handler.post_path
23
- end
24
16
  end
@@ -21,6 +21,13 @@
21
21
  <%= simple_format(entity.body) %>
22
22
  </div>
23
23
 
24
+ <% unless entity.approved? %>
25
+ <div>
26
+ <button class="js-approve-comment" data-url="<%= approve_admin_comment_path(id: entity.id) %>"><%= t('.approve') %></button>
27
+ <button class="js-delete-comment" data-url="<%= admin_comment_path(id: entity.id) %>"><%= t(:delete) %></button>
28
+ </div>
29
+ <% end %>
30
+
24
31
  <ul class="actions">
25
32
  <li><%= edit_icon(edit_comment_path(id: entity.id)) %></li>
26
33
  <% unless entity.deleted? %>
@@ -52,4 +52,13 @@
52
52
  </div>
53
53
  </dd>
54
54
  </dl>
55
+
56
+ <%= render partial: 'shared/track', locals: { item: @entity } %>
57
+
58
+ <% unless @entity.approved? %>
59
+ <div>
60
+ <button class="js-approve-comment" data-url="<%= approve_admin_comment_path(id: @entity.id) %>"><%= t('admin.comments.entity.in_list.approve') %></button>
61
+ <button class="js-delete-comment" data-url="<%= admin_comment_path(id: @entity.id) %>"><%= t(:delete) %></button>
62
+ </div>
63
+ <% end %>
55
64
  </article>
@@ -10,7 +10,7 @@
10
10
  <div class="deleted"><%= t('.deleted') %></div>
11
11
  <% else %>
12
12
  <meta itemprop="url" content="<%= url_for(anchor: element_id) %>"/>
13
- <% if current_user_has_privilege?(:moderator) %>
13
+ <% if handler.allow?('moderator') %>
14
14
  <ul class="actions">
15
15
  <li><%= edit_icon(edit_comment_path(id: comment.id)) %></li>
16
16
  <li class="danger"><%= destroy_icon(comment) %></li>
@@ -65,7 +65,8 @@
65
65
  locals: {
66
66
  comment: item[:comment],
67
67
  show_container: show_container,
68
- comment_tree: comment_tree
68
+ comment_tree: comment_tree,
69
+ handler: handler
69
70
  }
70
71
  )
71
72
  %>
@@ -8,7 +8,8 @@
8
8
  locals: {
9
9
  comment: item[:comment],
10
10
  show_container: show_reply_container,
11
- comment_tree: comment_tree
11
+ comment_tree: comment_tree,
12
+ handler: handler
12
13
  }
13
14
  )
14
15
  %>
@@ -38,7 +38,7 @@ ru:
38
38
  admin:
39
39
  comments:
40
40
  nav_item:
41
- text: "Комментарии"
41
+ text: "Список комментариев"
42
42
  description: "Модерация комментариев"
43
43
  index:
44
44
  title: "Комментарии, страница %{page}"
@@ -47,6 +47,9 @@ ru:
47
47
  title: "Комментарий №%{id}"
48
48
  comment:
49
49
  deleted: "Комментарий удалён"
50
+ entity:
51
+ in_list:
52
+ approve: "Одобрить"
50
53
  index:
51
54
  dashboard:
52
55
  biovision_comment:
@@ -60,6 +63,7 @@ ru:
60
63
  comments:
61
64
  create:
62
65
  success: "Комментарий добавлен"
66
+ premoderation: "Ваш комментарий добавлен в очередь модерации"
63
67
  update:
64
68
  success: "Комментарий изменён"
65
69
  destroy:
@@ -9,11 +9,12 @@ Rails.application.routes.draw do
9
9
  end
10
10
 
11
11
  namespace :admin do
12
- resources :comments, only: %i[index show] do
12
+ resources :comments, only: %i[index show destroy] do
13
13
  member do
14
14
  post 'toggle', defaults: { format: :json }
15
15
  put 'lock', defaults: { format: :json }
16
16
  delete 'lock', action: :unlock, defaults: { format: :json }
17
+ put 'approve'
17
18
  end
18
19
  end
19
20
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Biovision
4
4
  module Comment
5
- VERSION = '0.7.190905.0'
5
+ VERSION = '0.8.190926.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: biovision-comment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.190905.0
4
+ version: 0.8.190926.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxim Khan-Magomedov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-04 00:00:00.000000000 Z
11
+ date: 2019-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails