Repository navigation
Device story comments #743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
b3275b6
Created model for comments
Nakushi64 27a6699
Added commenting functionality
Nakushi64 53dc56b
Added deleting functionality
Nakushi64 96b30b6
Moderators can delete others comments
Nakushi64 e593f39
Fixed rspec issue
Nakushi64 e5aa5ac
Reworked comments with nesting resources
Nakushi64 721f423
Rubocop changes
Nakushi64 4c78d7b
More Rubocop
Nakushi64 f049346
Delete device_story_comment_decorator.rb
Nakushi64 3c74b3f
Added Akismet spam protection
Nakushi64 253b3b5
Rubocop
Nakushi64 d2db661
Fixed status messages and page refreshing after comment actions
Nakushi64 7fcc2fe
Improved error message
Nakushi64 4ec037f
Update show.html.erb
Nakushi64 e5f4aac
Added testing spec for device story comments
Nakushi64 4d3a04c
Applied suggested changes
Nakushi64 e52d11b
Rubocop changes
Nakushi64 62d7cfd
Update app/models/device_story_comment.rb
Nakushi64 a95a2bd
Update spec/requests/device_story_comments_controller_spec.rb
Nakushi64 199c3be
Update config/initializers/rakismet.rb
Nakushi64 d9c5ba8
Update config/initializers/rakismet.rb
Nakushi64 026a675
Applied recommended spec changes
Nakushi64 727977a
Rubocop changes
Nakushi64 6172638
Fixed rspec issue
Nakushi64 ca500b4
Fixed "Rakismet.key is not defined"
Nakushi64 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,74 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class DeviceStoryCommentsController < ApplicationController | ||
| before_action :set_device_story | ||
| before_action :set_device_story_comment, only: %i(show edit update destroy) | ||
|
|
||
| def index | ||
| @device_story_comments = @device_story.device_story_comments | ||
| end | ||
|
|
||
| def new | ||
| @device_story_comment = @device_story.device_story_comments.build | ||
| end | ||
|
|
||
| def create | ||
| return unless user_signed_in? | ||
|
|
||
| @device_story_comment = @device_story.device_story_comments.build(device_story_comment_params) | ||
| @device_story_comment.user_id = current_user.id | ||
| responder_create | ||
| end | ||
|
|
||
| def update | ||
| return unless user_signed_in? && ((@device_story_comment.user_id == current_user.id) || moderator?(current_user)) | ||
|
|
||
| responder_update | ||
| end | ||
|
|
||
| def responder_create | ||
| respond_to do |format| | ||
| if @device_story_comment.save && !@device_story_comment.spam? | ||
| format.html { redirect_to device_story_path(@device_story), notice: 'Comment successfully submitted!' } | ||
| else | ||
| flash[:error] = @device_story_comment.errors.full_messages.join(' ') | ||
| format.html { redirect_to device_story_path(@device_story) } | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def responder_update | ||
| respond_to do |format| | ||
| if @device_story_comment.update(device_story_comment_params) | ||
| format.html { redirect_to device_story_path(@device_story), notice: 'device_story_comment was successfully updated.' } | ||
| format.json { render :show, status: :ok, location: @device_story_comment } | ||
| else | ||
| format.html { render :edit } | ||
| format.json { render json: @device_story_comment.errors, status: :unprocessable_entity } | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def destroy | ||
| return unless user_signed_in? && ((@device_story_comment.user_id == current_user.id) || moderator?(current_user)) | ||
|
|
||
| @device_story_comment.destroy | ||
| respond_to do |format| | ||
| format.html { redirect_to device_story_path(@device_story), notice: 'Comment deleted!' } | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def set_device_story_comment | ||
| @device_story_comment = @device_story.device_story_comments.find(params[:id]) | ||
| end | ||
|
|
||
| def device_story_comment_params | ||
| params.require(:device_story_comment).permit(:content, :device_story_id, :user_id) | ||
| end | ||
|
|
||
| def set_device_story | ||
| @device_story = DeviceStory.find(params[:device_story_id]) | ||
| end | ||
| end | ||
This file contains hidden or 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 hidden or 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,9 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class DeviceStoryComment < ApplicationRecord | ||
| include Rakismet::Model | ||
| validates :content, presence: true, length: { maximum: 1000 } | ||
| validates :user_id, presence: true | ||
| belongs_to :device_story, required: true | ||
| belongs_to :user, required: true | ||
| end |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -5,7 +5,9 @@ | |
| <div class="row"> | ||
| <h2> | ||
| <%= @device_story.last_location_name %> (<%= @device_story.device_urn %>) | ||
| <div style="font-size: 15px"> <%= time_ago_in_words(@device_story.last_seen) %> ago</div> | ||
| <%- if @device_story.last_seen %> | ||
| <div style="font-size: 15px"> <%= time_ago_in_words(@device_story.last_seen) %> ago</div> | ||
| <%- end %> | ||
| </h2> | ||
| <div class="span2" style="margin: 0; margin-right: 20px"> | ||
| <table class="table table-hover" style="min-width: 164px; max-width: 164px; table-layout: fixed; margin-top: 10%; word-wrap: break-word"> | ||
|
|
@@ -47,5 +49,39 @@ | |
| </div> | ||
| </div> | ||
|
|
||
| <div> | ||
| <h2>Comments: <br></h2> | ||
| <table class="table table-striped"> | ||
| <tbody> | ||
| <%- if @device_story.device_story_comments.empty? %> | ||
| No Comments yet. | ||
| <%- else %> | ||
| <%- @device_story.device_story_comments.each do |comment| %> | ||
| <tr> | ||
| <td> | ||
| <b><%= link_to comment.user.name , comment.user %></b> <div style="display: inline-block; color: dimgrey; font-size: small">(<%= time_ago_in_words(comment.created_at) %> ago)</div> <br> | ||
| <%= comment.content %> | ||
| <%- if user_signed_in? -%> | ||
| <%- if (comment.user_id == current_user.id) || moderator?(current_user) %> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like you got the right idea here, but we should protect the route as well. People could build their own requests to delete the user if the API allows it. |
||
| <div style="float:right"> <%= link_to 'Delete', device_story_device_story_comment_path(@device_story, comment), method: :delete %></div> | ||
| <%- end %> | ||
| <%- end %> | ||
| </td> | ||
| </tr> | ||
| <%-end %> | ||
| <%- end %> | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| <div style="margin-left: 5px;min-width: 500px"> | ||
| <%- if user_signed_in? %> | ||
| <%= form_with model: DeviceStoryComment, url: device_story_device_story_comments_path(@device_story), local: true, method: 'post' do |form| %> | ||
| <%= form.label :content, current_user.name %> | ||
| <%= form.text_area :content, :rows => 3, style: 'width:97%;' %> | ||
| <p><%= form.submit "Submit comment" %></p> | ||
| <% end %> | ||
| <% end %> | ||
| </div> | ||
|
|
||
| <div class="spacer"></div> | ||
| <%= current_page_api_example :device_stories_url %> | ||
| <%= current_page_api_example :device_stories_url %> | ||
This file contains hidden or 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,4 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| Safecast::Application.config.rakismet.key = ENV['AKISMET_API_KEY'] | ||
| Safecast::Application.config.rakismet.url = "https://#{ENV['DEFAULT_HOSTNAME']}/" |
This file contains hidden or 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 hidden or 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,13 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class CreateDeviceStoryComments < ActiveRecord::Migration[5.2] | ||
| def change | ||
| create_table :device_story_comments do |t| | ||
| t.text :content | ||
| t.references :device_story, foreign_key: true | ||
| t.references :user, foreign_key: true | ||
|
|
||
| t.timestamps | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure at the moment this allows any user to delete (or update) any comment, we should set it so only moderator or comment author can do that.