-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…1143) - Delete all jQuery code related to comments - Rewrite frontend in React - Refactor services for comments - comments_helper.rb: logic for the comments array that gets passed as a prop to the Comments React widget - comment_form_helper.rb: form props for form used in Comments React widget - comments_viewers_service.rb (previously comments_visibility.rb): service for determining which comments to display to users/ability to delete - comments_controller.rb: moved all comment create/delete logic from other controllers into one - Update tests, write more tests (a lot of which were missing) - Only display commenting if moment/strategy is published
- Loading branch information
1 parent
9259217
commit 882bd29
Showing
49 changed files
with
1,739 additions
and
1,234 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
class CommentController < ApplicationController | ||
def create | ||
response = { | ||
comment: generate_comments( | ||
Comment.where(id: handle_create(params[:comment])) | ||
).first | ||
} | ||
render json: response, status: :ok | ||
rescue ActiveRecord::RecordInvalid | ||
render json: {}, status: :bad_request | ||
end | ||
|
||
def delete | ||
comment = Comment.where(id: params[:comment_id]).first | ||
raise 'Comment does not exist' if comment.nil? | ||
|
||
handle_delete(comment) | ||
render json: { id: comment.id }, status: :ok | ||
rescue TypeError, RuntimeError | ||
render json: {}, status: :bad_request | ||
end | ||
|
||
private | ||
|
||
def remove_meeting_notification!(comment_id) | ||
CommentNotificationsService.remove( | ||
comment_id: comment_id, | ||
model_name: 'meeting' | ||
) | ||
end | ||
|
||
def remove_meeting_notification(comment, meeting) | ||
my_comment = comment.present? && (comment.comment_by == current_user.id) | ||
return unless (my_comment && meeting.member?(current_user)) || | ||
meeting.led_by?(current_user) | ||
|
||
remove_meeting_notification!(comment.id) | ||
end | ||
|
||
def handle_create(comment_params) | ||
comment = Comment.create_from!(comment_params) | ||
comment.notify_of_creation!(current_user) | ||
comment.id | ||
end | ||
|
||
def handle_delete(comment) | ||
if %w[moment strategy].include?(comment.commentable_type) | ||
CommentViewersService.deletable?(comment, current_user) | ||
CommentNotificationsService.remove(comment_id: comment.id, | ||
model_name: | ||
comment.commentable_type) | ||
elsif comment.commentable_type == 'meeting' | ||
meeting_id = comment.commentable_id | ||
meeting = Meeting.find_by(id: meeting_id) | ||
remove_meeting_notification(comment, meeting) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.