Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow users to delete uploaded files.
- Loading branch information
Showing
13 changed files
with
88 additions
and
41 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
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 |
---|---|---|
@@ -1,8 +1,16 @@ | ||
class Sufia::UploadsController < ApplicationController | ||
before_action :authenticate_user! | ||
module Sufia | ||
class UploadsController < ApplicationController | ||
load_and_authorize_resource class: UploadedFile | ||
|
||
def create | ||
@uploaded_file = UploadedFile.create!(file: params[:files].first, | ||
user: current_user) | ||
def create | ||
@upload.attributes = { file: params[:files].first, | ||
user: current_user } | ||
@upload.save! | ||
end | ||
|
||
def destroy | ||
@upload.destroy | ||
head :no_content | ||
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
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,12 @@ | ||
module Sufia | ||
# Store a file uploaded by a user. Eventually these files get | ||
# attached to FileSets and pushed into Fedora. | ||
class UploadedFile < ActiveRecord::Base | ||
mount_uploader :file, UploadedFileUploader | ||
belongs_to :user, class_name: '::User' | ||
|
||
before_destroy do |obj| | ||
obj.remove_file! | ||
end | ||
end | ||
end |
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
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
json.files [@uploaded_file] do |uploaded_file| | ||
json.files [@upload] do |uploaded_file| | ||
json.id uploaded_file.id | ||
json.name uploaded_file.file.file.filename | ||
json.size uploaded_file.file.file.size | ||
# TODO: implement these | ||
# json.url "/uploads/#{uploaded_file.id}" | ||
# json.thumbnail_url uploaded_file.id | ||
# json.delete_url 'deleteme' | ||
# json.delete_type 'DELETE' | ||
json.deleteUrl sufia.polymorphic_path(uploaded_file) | ||
json.deleteType 'DELETE' | ||
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