Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
Fixing Merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
cdahlhausen committed Sep 24, 2019
2 parents 01c5488 + 76643cc commit 18e9d77
Show file tree
Hide file tree
Showing 13 changed files with 497 additions and 165 deletions.
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ gem 'turbolinks'
gem 'jbuilder', '~> 2.9.1'
gem 'pg', '1.1.4' # Necessary for talking to our RDS instance
gem 'pundit'
gem 'figaro'
gem 'devise', '4.7.0'
# gem 'figaro'
gem 'devise', '4.7.1'
gem 'devise-security'
gem 'devise-two-factor'
gem 'dotenv-rails'
Expand All @@ -41,7 +41,7 @@ gem 'inherited_resources', '1.11.0'
gem 'uuidtools'
gem 'kaminari'
gem 'sassc-rails'
gem 'sassc', '2.0.1'
gem 'sassc', '2.2.0'
gem 'bootstrap-sass', '~> 3.4.1'
gem 'browser-timezone-rails'

Expand Down
12 changes: 5 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ GEM
crass (1.0.4)
declarative (0.0.10)
declarative-option (0.1.0)
devise (4.7.0)
devise (4.7.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
Expand Down Expand Up @@ -142,7 +142,7 @@ GEM
factory_bot_rails (5.0.2)
factory_bot (~> 5.0.2)
railties (>= 4.2.0)
faker (2.1.2)
faker (2.2.1)
i18n (>= 0.8)
faraday (0.15.4)
multipart-post (>= 1.2, < 3)
Expand Down Expand Up @@ -316,9 +316,8 @@ GEM
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rubyzip (1.2.3)
sassc (2.0.1)
sassc (2.2.0)
ffi (~> 1.9)
rake
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
Expand Down Expand Up @@ -396,15 +395,14 @@ DEPENDENCIES
chart-js-rails
coffee-rails (~> 5.0.0)
coveralls (= 0.8.23)
devise (= 4.7.0)
devise (= 4.7.1)
devise-authy
devise-security
devise-two-factor
dotenv-rails
email_validator
factory_bot_rails
faker
figaro
gelf
google_drive
inherited_resources (= 1.11.0)
Expand All @@ -428,7 +426,7 @@ DEPENDENCIES
rspec-its
rspec-rails (~> 3.8.2)
rubyzip
sassc (= 2.0.1)
sassc (= 2.2.0)
sassc-rails
shoulda-matchers (~> 4.1.2)
simple_form (~> 4.1.0)
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,11 @@ def set_grace_period_notice
rescue_from ActionController::RoutingError do |exception|
logger.error "Routing error occurred. URL: #{request.url}"
logger.error exception.backtrace.join("\n")
request.format = 'json' if api_request?
logger.error 'Routing error occurred'
respond_to do |format|
format.html { render 'shared/404', status: 404 }
format.json { render :json => { status: 'error', message: 'The page you were looking for could not be found! If you were searching for a specific object or file, check to make sure you have the correct identifier and try again. If you believe you have reached this message in error, please contact your administrator or an APTrust administrator.' }, status: 404 }
format.json { render :json => { status: 'error', message: 'The page you were looking for could not be found! If you were searching for a specific object or file, check to make sure you have the correct identifier and try again. If you believe you have reached this message in error, please contact your administrator or an APTrust administrator.', url: request.original_url }, status: 404 }
end
end

Expand Down
137 changes: 80 additions & 57 deletions app/controllers/generic_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def show
else
authorize current_user, :nil_file?
respond_to do |format|
format.json { render json: { status: 'error', message: 'This file could not be found. Please check to make sure the identifier was properly escaped.' }, status: :not_found }
format.json { render json: { status: 'error', message: 'This file could not be found. Please check to make sure the identifier was properly escaped.', url: request.original_url }, status: 404 }
format.html { redirect_to root_url, alert: "A Generic File with identifier: #{params[:generic_file_identifier]} was not found. Please check to make sure the identifier was properly escaped." }
end
end
Expand Down Expand Up @@ -106,40 +106,56 @@ def update
# nested params cause new events to be created,
# and it would require too much logic to determine which
# events should not be duplicated.
authorize @generic_file
@generic_file.state = 'A'
if resource.update(single_generic_file_params)
render json: object_as_json, status: :ok
if @generic_file
authorize @generic_file
@generic_file.state = 'A'
if resource.update(single_generic_file_params)
render json: object_as_json, status: :ok
else
log_model_error(resource)
render json: resource.errors, status: :unprocessable_entity
end
else
log_model_error(resource)
render json: resource.errors, status: :unprocessable_entity
authorize current_user, :nil_file?
respond_to do |format|
format.json { render json: { status: 'error', message: 'This file could not be found. Please check to make sure the identifier was properly escaped.', url: request.original_url }, status: 404 }
format.html { redirect_to root_url, alert: "A Generic File with identifier: #{params[:generic_file_identifier]} was not found. Please check to make sure the identifier was properly escaped." }
end
end
end

def destroy
authorize @generic_file, :soft_delete?
# Don't allow a delete request if an ingest or restore is in process
# for this object. OK to delete if another delete request is in process.
result = WorkItem.can_delete_file?(@generic_file.intellectual_object.identifier, @generic_file.identifier)
if @generic_file.state == 'D'
redirect_to @generic_file
flash[:alert] = 'This file has already been deleted.'
elsif result == 'true'
log = Email.log_deletion_request(@generic_file)
ConfirmationToken.where(generic_file_id: @generic_file.id).delete_all #delete any old tokens. Only the new one should be valid
token = ConfirmationToken.create(generic_file: @generic_file, token: SecureRandom.hex)
token.save!
NotificationMailer.deletion_request(@generic_file, current_user, log, token).deliver!
respond_to do |format|
format.json { head :no_content }
format.html {
redirect_to @generic_file
flash[:notice] = 'An email has been sent to the administrators of this institution to confirm deletion of this file.'
}
if @generic_file
authorize @generic_file, :soft_delete?
# Don't allow a delete request if an ingest or restore is in process
# for this object. OK to delete if another delete request is in process.
result = WorkItem.can_delete_file?(@generic_file.intellectual_object.identifier, @generic_file.identifier)
if @generic_file.state == 'D'
redirect_to @generic_file
flash[:alert] = 'This file has already been deleted.'
elsif result == 'true'
log = Email.log_deletion_request(@generic_file)
ConfirmationToken.where(generic_file_id: @generic_file.id).delete_all #delete any old tokens. Only the new one should be valid
token = ConfirmationToken.create(generic_file: @generic_file, token: SecureRandom.hex)
token.save!
NotificationMailer.deletion_request(@generic_file, current_user, log, token).deliver!
respond_to do |format|
format.json { head :no_content }
format.html {
redirect_to @generic_file
flash[:notice] = 'An email has been sent to the administrators of this institution to confirm deletion of this file.'
}
end
else
redirect_to @generic_file
flash[:alert] = "Your file cannot be deleted at this time due to a pending #{result} request."
end
else
redirect_to @generic_file
flash[:alert] = "Your file cannot be deleted at this time due to a pending #{result} request."
authorize current_user, :nil_file?
respond_to do |format|
format.json { render json: { status: 'error', message: 'This file could not be found. Please check to make sure the identifier was properly escaped.', url: request.original_url }, status: 404 }
format.html { redirect_to root_url, alert: "A Generic File with identifier: #{params[:generic_file_identifier]} was not found. Please check to make sure the identifier was properly escaped." }
end
end
end

Expand Down Expand Up @@ -194,37 +210,44 @@ def finished_destroy
end
end


def restore
authorize @generic_file, :restore?
message = ""
api_status_code = :ok
restore_item = nil
pending = WorkItem.pending_action_for_file(@generic_file.identifier)
if @generic_file.state == 'D'
api_status_code = :conflict
message = 'This file has been deleted and cannot be queued for restoration.'
elsif pending.nil?
restore_item = WorkItem.create_restore_request_for_file(@generic_file, current_user.email)
message = 'Your file has been queued for restoration.'
if @generic_file
authorize @generic_file, :restore?
message = ""
api_status_code = :ok
restore_item = nil
pending = WorkItem.pending_action_for_file(@generic_file.identifier)
if @generic_file.state == 'D'
api_status_code = :conflict
message = 'This file has been deleted and cannot be queued for restoration.'
elsif pending.nil?
restore_item = WorkItem.create_restore_request_for_file(@generic_file, current_user.email)
message = 'Your file has been queued for restoration.'
else
api_status_code = :conflict
message = "Your file cannot be queued for restoration at this time due to a pending #{pending.action} request."
end
respond_to do |format|
status = restore_item.nil? ? 'error' : 'ok'
item_id = restore_item.nil? ? 0 : restore_item.id
format.json {
render :json => { status: status, message: message, work_item_id: item_id }, :status => api_status_code
}
format.html {
if restore_item.nil?
flash[:alert] = message
else
flash[:notice] = message
end
redirect_to @generic_file
}
end
else
api_status_code = :conflict
message = "Your file cannot be queued for restoration at this time due to a pending #{pending.action} request."
end
respond_to do |format|
status = restore_item.nil? ? 'error' : 'ok'
item_id = restore_item.nil? ? 0 : restore_item.id
format.json {
render :json => { status: status, message: message, work_item_id: item_id }, :status => api_status_code
}
format.html {
if restore_item.nil?
flash[:alert] = message
else
flash[:notice] = message
end
redirect_to @generic_file
}
authorize current_user, :nil_file?
respond_to do |format|
format.json { render json: { status: 'error', message: 'This file could not be found. Please check to make sure the identifier was properly escaped.', url: request.original_url }, status: 404 }
format.html { redirect_to root_url, alert: "A Generic File with identifier: #{params[:generic_file_identifier]} was not found. Please check to make sure the identifier was properly escaped." }
end
end
end

Expand Down
Loading

0 comments on commit 18e9d77

Please sign in to comment.