Skip to content

Commit

Permalink
fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
alinvetian committed Dec 11, 2024
2 parents 643a5f3 + 68a55be commit 8a3d174
Show file tree
Hide file tree
Showing 39 changed files with 327 additions and 172 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ source 'https://rubygems.org'
gem 'irb', '~> 1.4.1'
gem 'mail', '~> 2.8'
gem 'mysql2', '~> 0.5.3'
gem 'rails', '~> 7.0.8.5'
gem 'rails', '~> 7.0.8.7'
gem 'react-rails', '~> 2.6.2'
gem 'shakapacker', '~> 6.0'
gem 'sprockets', '~> 4.0'
Expand Down
116 changes: 58 additions & 58 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,67 +17,67 @@ GIT
GEM
remote: https://rubygems.org/
specs:
actioncable (7.0.8.5)
actionpack (= 7.0.8.5)
activesupport (= 7.0.8.5)
actioncable (7.0.8.7)
actionpack (= 7.0.8.7)
activesupport (= 7.0.8.7)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (7.0.8.5)
actionpack (= 7.0.8.5)
activejob (= 7.0.8.5)
activerecord (= 7.0.8.5)
activestorage (= 7.0.8.5)
activesupport (= 7.0.8.5)
actionmailbox (7.0.8.7)
actionpack (= 7.0.8.7)
activejob (= 7.0.8.7)
activerecord (= 7.0.8.7)
activestorage (= 7.0.8.7)
activesupport (= 7.0.8.7)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.0.8.5)
actionpack (= 7.0.8.5)
actionview (= 7.0.8.5)
activejob (= 7.0.8.5)
activesupport (= 7.0.8.5)
actionmailer (7.0.8.7)
actionpack (= 7.0.8.7)
actionview (= 7.0.8.7)
activejob (= 7.0.8.7)
activesupport (= 7.0.8.7)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (7.0.8.5)
actionview (= 7.0.8.5)
activesupport (= 7.0.8.5)
actionpack (7.0.8.7)
actionview (= 7.0.8.7)
activesupport (= 7.0.8.7)
rack (~> 2.0, >= 2.2.4)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (7.0.8.5)
actionpack (= 7.0.8.5)
activerecord (= 7.0.8.5)
activestorage (= 7.0.8.5)
activesupport (= 7.0.8.5)
actiontext (7.0.8.7)
actionpack (= 7.0.8.7)
activerecord (= 7.0.8.7)
activestorage (= 7.0.8.7)
activesupport (= 7.0.8.7)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.0.8.5)
activesupport (= 7.0.8.5)
actionview (7.0.8.7)
activesupport (= 7.0.8.7)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (7.0.8.5)
activesupport (= 7.0.8.5)
activejob (7.0.8.7)
activesupport (= 7.0.8.7)
globalid (>= 0.3.6)
activemodel (7.0.8.5)
activesupport (= 7.0.8.5)
activerecord (7.0.8.5)
activemodel (= 7.0.8.5)
activesupport (= 7.0.8.5)
activestorage (7.0.8.5)
actionpack (= 7.0.8.5)
activejob (= 7.0.8.5)
activerecord (= 7.0.8.5)
activesupport (= 7.0.8.5)
activemodel (7.0.8.7)
activesupport (= 7.0.8.7)
activerecord (7.0.8.7)
activemodel (= 7.0.8.7)
activesupport (= 7.0.8.7)
activestorage (7.0.8.7)
actionpack (= 7.0.8.7)
activejob (= 7.0.8.7)
activerecord (= 7.0.8.7)
activesupport (= 7.0.8.7)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (7.0.8.5)
activesupport (7.0.8.7)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
Expand Down Expand Up @@ -407,7 +407,7 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2024.1001)
mini_mime (1.1.5)
minitest (5.25.1)
minitest (5.25.4)
mize (0.6.0)
mocha (2.4.5)
ruby2_keywords (>= 0.0.5)
Expand Down Expand Up @@ -439,11 +439,11 @@ GEM
netrc (0.11.0)
nio4r (2.7.3)
noid (0.9.0)
nokogiri (1.16.7-arm64-darwin)
nokogiri (1.17.1-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-darwin)
nokogiri (1.17.1-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
nokogiri (1.17.1-x86_64-linux)
racc (~> 1.4)
notiffany (0.1.3)
nenv (~> 0.1)
Expand Down Expand Up @@ -507,29 +507,29 @@ GEM
rack
rack-test (2.1.0)
rack (>= 1.3)
rails (7.0.8.5)
actioncable (= 7.0.8.5)
actionmailbox (= 7.0.8.5)
actionmailer (= 7.0.8.5)
actionpack (= 7.0.8.5)
actiontext (= 7.0.8.5)
actionview (= 7.0.8.5)
activejob (= 7.0.8.5)
activemodel (= 7.0.8.5)
activerecord (= 7.0.8.5)
activestorage (= 7.0.8.5)
activesupport (= 7.0.8.5)
rails (7.0.8.7)
actioncable (= 7.0.8.7)
actionmailbox (= 7.0.8.7)
actionmailer (= 7.0.8.7)
actionpack (= 7.0.8.7)
actiontext (= 7.0.8.7)
actionview (= 7.0.8.7)
activejob (= 7.0.8.7)
activemodel (= 7.0.8.7)
activerecord (= 7.0.8.7)
activestorage (= 7.0.8.7)
activesupport (= 7.0.8.7)
bundler (>= 1.15.0)
railties (= 7.0.8.5)
railties (= 7.0.8.7)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.5.0)
loofah (~> 2.19, >= 2.19.1)
railties (7.0.8.5)
actionpack (= 7.0.8.5)
activesupport (= 7.0.8.5)
railties (7.0.8.7)
actionpack (= 7.0.8.7)
activesupport (= 7.0.8.7)
method_source
rake (>= 12.2)
thor (~> 1.0)
Expand Down Expand Up @@ -827,7 +827,7 @@ DEPENDENCIES
puma (= 6.4.3)
pundit (~> 2.3)
rack-attack
rails (~> 7.0.8.5)
rails (~> 7.0.8.7)
rb-readline
rdoc (~> 6.1.1)
react-rails (~> 2.6.2)
Expand Down
57 changes: 42 additions & 15 deletions app/controllers/health_controller.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,69 @@
class HealthController < ApplicationController

def check
health_status = { status: 'OK' }
@health_status = {}
populate_statuses

status_code = @health_status.map { |_k, v| v[:status] }.include?('not connected') ? :service_unavailable : :ok
notify_health_status_change(status_code, @health_status)

render json: { status: status_code }.merge(@health_status), status: status_code and return if params.key?(:advanced)

render json: { status: status_code }.merge(simple_response_hash), status: status_code
end

private

def simple_response_hash
return @simple_response_hash if @simple_response_hash

@simple_response_hash = @health_status.each_with_object({}) do |(key, value), result|
result[key] = value[:status]
end
end

def populate_statuses
# Check database connectivity
@health_status[:database] = {}
begin
StashEngine::Identifier.last
health_status[:database] = 'connected'
@health_status[:database][:status] = 'connected'
rescue StandardError => e
health_status[:database] = 'not connected'
health_status[:database_error] = e.message if params[:advanced]
@health_status[:database][:status] = 'not connected'
@health_status[:database][:error] = e.message
end

# Check Solr connectivity
@health_status[:solr] = {}
begin
solr = RSolr.connect(url: Blacklight.connection_config[:url])
solr.get('select', params: { fl: 'dc_identifier_s', rows: 1 })
health_status[:solr] = 'connected'
@health_status[:solr][:status] = 'connected'
rescue StandardError => e
health_status[:solr] = 'not connected'
health_status[:solr_error] = e.message if params[:advanced]
@health_status[:solr][:status] = 'not connected'
@health_status[:solr][:error] = e.message
end

# Check AWS S3 connectivity
@health_status[:aws_s3] = {}
begin
if Stash::Aws::S3.new.exists?(s3_key: 's3_status_check.txt')
health_status[:aws_s3] = 'connected'
@health_status[:aws_s3][:status] = 'connected'
else
health_status[:aws_s3] = 'not connected'
health_status[:aws_s3_error] = 'file does not exist' if params[:advanced]
@health_status[:aws_s3][:status] = 'not connected'
@health_status[:aws_s3][:error] = 'file does not exist'
end
rescue StandardError => e
health_status[:aws_s3] = 'not connected'
health_status[:aws_s3_error] = e.message if params[:advanced]
@health_status[:aws_s3][:status] = 'not connected'
@health_status[:aws_s3][:error] = e.message
end
end

def notify_health_status_change(status_code, health_status)
old_statuses = Rails.cache.read('health_status')
Rails.cache.write('health_status', simple_response_hash, expires_in: 10.minute)
return if old_statuses == simple_response_hash

status_code = health_status.values.include?('not connected') ? :service_unavailable : :ok
health_status[:status] = status_code
render json: health_status, status: status_code
StashEngine::NotificationsMailer.health_status_change(status_code, health_status).deliver_now
end
end
4 changes: 2 additions & 2 deletions app/controllers/stash_engine/admin_dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@ def load
end

def curation_activity_change
return publishing_error if @resource.id != @identifier.last_submitted_resource.id &&
return publishing_error if @resource.id != @identifier.last_submitted_resource&.id &&
%w[embargoed published].include?(params.dig(:curation_activity, :status))

return state_error unless CurationActivity.allowed_states(@last_state).include?(@status)
return state_error unless CurationActivity.allowed_states(@last_state, current_user).include?(@status)

decipher_curation_activity
@note = params.dig(:curation_activity, :note)
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/stash_engine/admin_datasets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ def create_salesforce_case
redirect_to(sf_url, allow_other_host: true)
end

def destroy
identifier = Identifier.find(params[:id])
authorize identifier

if identifier.destroy
redirect_to admin_dashboard_path, notice: "Dataset with DOI #{identifier.identifier} has been deleted."
else
redirect_to activity_log_path(identifier.id), alert: 'Dataset could not be deleted. Please try again later.'
end
end

private

def load
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/stash_engine/admin_datasets_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def status_select(statuses = [])
end

def filter_status_select(current_status)
statuses = StashEngine::CurationActivity.allowed_states(current_status)
statuses = StashEngine::CurationActivity.allowed_states(current_status, current_user)

statuses.delete(current_status) # because we don't show the current state as an option, it is implied by leaving state blank

Expand Down
4 changes: 0 additions & 4 deletions app/helpers/stash_engine/dashboard_helper.rb

This file was deleted.

4 changes: 0 additions & 4 deletions app/helpers/stash_engine/edit_histories_helper.rb

This file was deleted.

4 changes: 0 additions & 4 deletions app/helpers/stash_engine/embargoes_helper.rb

This file was deleted.

4 changes: 0 additions & 4 deletions app/helpers/stash_engine/file_uploads_helper.rb

This file was deleted.

4 changes: 0 additions & 4 deletions app/helpers/stash_engine/pages_helper.rb

This file was deleted.

4 changes: 0 additions & 4 deletions app/helpers/stash_engine/resources_helper.rb

This file was deleted.

4 changes: 0 additions & 4 deletions app/helpers/stash_engine/searches_helper.rb

This file was deleted.

4 changes: 0 additions & 4 deletions app/helpers/stash_engine/shares_helper.rb

This file was deleted.

4 changes: 0 additions & 4 deletions app/helpers/stash_engine/tenants_helper.rb

This file was deleted.

4 changes: 0 additions & 4 deletions app/helpers/stash_engine/zenodo_queue_helper.rb

This file was deleted.

13 changes: 13 additions & 0 deletions app/mailers/stash_engine/notifications_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module StashEngine

# Mails users about submissions
class NotificationsMailer < ApplicationMailer

def health_status_change(status_code, health_status)
@status_code = status_code
@health_status = health_status

mail(to: 'devs@datadryad.org', subject: "#{rails_env}Health check status changed - #{status_code}")
end
end
end
6 changes: 4 additions & 2 deletions app/models/stash_engine/curation_activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ def first_time_in_status?
resource.curation_activities.where('id < ?', id).where(status: status).empty?
end

def self.allowed_states(current_state)
CURATOR_ALLOWED_STATES[current_state].dup
def self.allowed_states(current_state, current_user)
statuses = CURATOR_ALLOWED_STATES[current_state].dup
statuses << 'withdrawn' if current_user.superuser? # superusers can withdraw a datasets from any status
statuses.uniq
end

# Private methods
Expand Down
Loading

0 comments on commit 8a3d174

Please sign in to comment.