This repository has been archived by the owner on Oct 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #299 from 18F/file-upload
[Delivers #89433964] File upload
- Loading branch information
Showing
19 changed files
with
292 additions
and
40 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -28,3 +28,6 @@ coverage | |
# Ignore Cloud Foundry files | ||
cf-ssh.yml | ||
*manifest.yml | ||
|
||
# Ignore file uploads | ||
/public/system |
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
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 |
---|---|---|
|
@@ -7,4 +7,4 @@ $bgdetails: #efefef; | |
$borderdetails: #bdbdbd; | ||
$lightgray: #838383; | ||
$medgray: #545454; | ||
|
||
$break-small: 480px; |
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
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,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 ||= Proposal.find(params[:proposal_id]) | ||
end | ||
|
||
def attachments_params | ||
params.require(:attachment).permit(:file) | ||
end | ||
|
||
def auth_errors(exception) | ||
redirect_to carts_path, :alert => "You are not allowed to add an attachment to that proposal" | ||
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
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,16 @@ | ||
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 | ||
|
||
# Default url for attachments expires after 10 minutes | ||
def url | ||
self.file.expiring_url(10*60) | ||
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
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
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,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 |
Oops, something went wrong.