-
Notifications
You must be signed in to change notification settings - Fork 54
[Delivers #89433964] File upload #299
Changes from 5 commits
339806f
78c5274
8a81e73
b87be71
747f2a4
19bd9b9
e73e38f
cc5b8a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,6 @@ coverage | |
# Ignore Cloud Foundry files | ||
cf-ssh.yml | ||
*manifest.yml | ||
|
||
# Ignore file uploads | ||
/public/system |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ gem 'acts_as_list' | |
gem 'ar_outer_joins' | ||
gem 'autoprefixer-rails' | ||
gem 'awesome_print' | ||
gem 'aws-sdk-v1' | ||
gem 'bootstrap-sass', '~> 3.3.0' | ||
gem 'dotenv-rails', require: 'dotenv/rails-now' | ||
gem 'draper' | ||
|
@@ -16,6 +17,7 @@ gem 'jquery-rails' | |
gem 'jquery-turbolinks' | ||
gem 'newrelic_rpm' | ||
gem 'omniauth-myusa', git: 'https://github.com/18F/omniauth-myusa.git' | ||
gem "paperclip", "~> 4.2" | ||
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. There are differing opinions on this, but I would leave the version restriction off unless there's a specific reason to lock the range. 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. At the very least, for consistency. |
||
gem 'pg' | ||
gem 'pundit' | ||
gem 'rack-cors', require: 'rack/cors' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ $bgdetails: #efefef; | |
$borderdetails: #bdbdbd; | ||
$lightgray: #838383; | ||
$medgray: #545454; | ||
|
||
$break-small: 480px; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class AttachmentsController < ApplicationController | ||
before_filter :authenticate_user! | ||
before_filter ->{authorize self.proposal, :can_show!} | ||
rescue_from Pundit::NotAuthorizedError, with: :auth_errors | ||
|
||
def create | ||
attachment = self.proposal.attachments.build(attachments_params) | ||
attachment.user = current_user | ||
if attachment.save | ||
flash[:success] = "You successfully added a attachment" | ||
else | ||
flash[:error] = attachment.errors.full_messages | ||
end | ||
|
||
redirect_to proposal.cart | ||
end | ||
|
||
protected | ||
def proposal | ||
@cached_proposal ||= Cart.find(params[:cart_id]).proposal | ||
end | ||
|
||
def attachments_params | ||
params.require(:attachment).permit(:file) | ||
end | ||
|
||
def auth_errors(exception) | ||
redirect_to carts_path, :alert => "You are not allowed to see that cart" | ||
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. Maybe "you aren't allowed to add an attachment to that proposal"? 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. Can do |
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Attachment < ActiveRecord::Base | ||
has_attached_file :file | ||
do_not_validate_attachment_file_type :file | ||
|
||
validates_presence_of :file | ||
validates_presence_of :proposal | ||
validates_presence_of :user | ||
|
||
belongs_to :proposal | ||
belongs_to :user | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,10 +75,10 @@ | |
|
||
|
||
|
||
<div class="cart-comments-container"> | ||
<div id="cart-comments"> | ||
<h3>Comments on this purchase request</h3> | ||
<%- if @show_comments %> | ||
<%- if @include_comments_files %> | ||
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. I'm not sure that we need this anymore, but that can be a separate discussion. 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. Let's loop in @phirefly ; I think he added this initially. |
||
<div class="cart-comments-container proposal-submodel-container"> | ||
<div id="cart-comments"> | ||
<h3>Comments on this purchase request</h3> | ||
<%= form_for [cart, Comment.new] do |f| %> | ||
<%= f.text_area :comment_text, rows: 5 %> | ||
|
||
|
@@ -96,14 +96,14 @@ | |
|
||
<% if cart.comments.any? %> | ||
<% cart.comments.each do |c| %> | ||
<div class='comment-item'> | ||
<div class='line-item'> | ||
<div class='row'> | ||
<% unless c.user.nil? %> | ||
<p class='comment-sender col-sm-6 col-xs-12'> | ||
<strong><%= c.user_full_name %></strong> | ||
</p> | ||
<% end %> | ||
<p class='comment-date col-sm-6 col-xs-12'> | ||
<p class='date col-sm-6 col-xs-12'> | ||
<%= date_with_tooltip(c.created_at) %> | ||
</p> | ||
</div> | ||
|
@@ -120,9 +120,50 @@ | |
No comments have been added yet | ||
</p> | ||
<% end %> | ||
<%- end %> | ||
</div> | ||
|
||
<div id="files"> | ||
<h3>Attachments to this proposal</h3> | ||
<%= form_for [cart, Attachment.new] do |f| %> | ||
<div class="line-item"> | ||
<div class="row"> | ||
<%= f.file_field :file %> | ||
</div> | ||
</div> | ||
<div class='row text-area-info-container'> | ||
<div class='col-xs-7 col-sm-6 text-area-info-web'> | ||
<p> | ||
Attaching a file will associate it with this proposal. Files cannot be removed | ||
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. Not sure that the last part is necessary, even if it's true for the moment. 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. Will delete |
||
</p> | ||
</div> | ||
<p class='col-xs-5 col-sm-6 text-area-button'> | ||
<%= submit_tag "Attach a File", id: :add_a_file %> | ||
</p> | ||
</div> | ||
<%- end %> | ||
<% cart.proposal.attachments.each do |attachment| %> | ||
<div class="line-item"> | ||
<div class="row"> | ||
<p class="col-sm-6 col-xs-12"> | ||
<a href="<%= attachment.file.expiring_url(10*60) %>"><%= attachment.file_file_name %></a> | ||
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. What is the magic number here? Maybe move to a helper or decorator or something? 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. Can do. I'll just replace override file_url. Magic number is for an arbitrary timeout: 10 minutes. |
||
</p> | ||
<p class="col-sm-3 col-xs-6"> | ||
<strong><%= attachment.user.full_name %></strong> | ||
</p> | ||
<p class="col-sm-3 col-xs-6 date righted"> | ||
<%= date_with_tooltip(attachment.created_at) %> | ||
</p> | ||
</div> | ||
</div> | ||
<% end %> | ||
<% if cart.proposal.attachments.empty? %> | ||
<p class="empty-list-label"> | ||
No attachments have been added yet | ||
</p> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
<%- end %> | ||
|
||
<% if policy(cart.proposal).can_approve_or_reject? %> | ||
<%= render partial: 'approval_actions', locals: { current_user: @current_user, cart: cart} %> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,5 +46,18 @@ class Application < Rails::Application | |
config.autoload_paths << Rails.root.join('lib') | ||
|
||
config.assets.precompile << 'common/communicarts.css' | ||
|
||
# Paperclip's attachment settings are determined by S3 env vars | ||
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. Maybe mention that it will be saved to the filesystem otherwise? 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. Can do |
||
if ENV['S3_BUCKET_NAME'] && ENV['S3_ACCESS_KEY_ID'] && ENV['S3_SECRET_ACCESS_KEY'] | ||
Paperclip::Attachment.default_options.merge!( | ||
bucket: ENV['S3_BUCKET_NAME'], | ||
s3_credentials: { | ||
access_key_id: ENV['S3_ACCESS_KEY_ID'], | ||
secret_access_key: ENV['S3_SECRET_ACCESS_KEY'] | ||
}, | ||
s3_permissions: :private, | ||
storage: :s3, | ||
) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
end | ||
|
||
resources :comments, only: [:index, :create] | ||
resources :attachments, only: [:create] | ||
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. Might as well put this under 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. Just waiting for that shoe to drop :) 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. Let's not wait. |
||
end | ||
|
||
namespace :ncr do | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateAttachments < ActiveRecord::Migration | ||
def change | ||
create_table :attachments do |t| | ||
t.attachment :file | ||
t.references :proposal | ||
t.references :user | ||
t.timestamps | ||
end | ||
end | ||
end |
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.
Why
v1
?aws-sdk
is the newer one, which it seems like Paperclip supports.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.
Not quite yet: thoughtbot/paperclip#1764
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.
Far enough. Mind adding an inline comment linking to that issue?