Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update cx collections #1299

Merged
merged 8 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ gem "rubocop-rspec"
gem 'active_model_serializers', '>= 0.10.13'
gem 'acts-as-list'
gem 'aws-sdk-rails', '>= 3.8.0'
gem 'aws-sdk-s3'
gem 'caracal', '>= 1.4.1'
gem 'carrierwave', '>= 2.2.1'
gem 'devise', '>= 4.8.1'
Expand Down
142 changes: 76 additions & 66 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,51 @@ GEM
aasm-diagram (0.1.3)
aasm (~> 5.0, >= 4.12)
ruby-graphviz (~> 1.2)
actioncable (7.1.1)
actionpack (= 7.1.1)
activesupport (= 7.1.1)
actioncable (7.1.2)
actionpack (= 7.1.2)
activesupport (= 7.1.2)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
zeitwerk (~> 2.6)
actionmailbox (7.1.1)
actionpack (= 7.1.1)
activejob (= 7.1.1)
activerecord (= 7.1.1)
activestorage (= 7.1.1)
activesupport (= 7.1.1)
actionmailbox (7.1.2)
actionpack (= 7.1.2)
activejob (= 7.1.2)
activerecord (= 7.1.2)
activestorage (= 7.1.2)
activesupport (= 7.1.2)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.1.1)
actionpack (= 7.1.1)
actionview (= 7.1.1)
activejob (= 7.1.1)
activesupport (= 7.1.1)
actionmailer (7.1.2)
actionpack (= 7.1.2)
actionview (= 7.1.2)
activejob (= 7.1.2)
activesupport (= 7.1.2)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.2)
actionpack (7.1.1)
actionview (= 7.1.1)
activesupport (= 7.1.1)
actionpack (7.1.2)
actionview (= 7.1.2)
activesupport (= 7.1.2)
nokogiri (>= 1.8.5)
racc
rack (>= 2.2.4)
rack-session (>= 1.0.1)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
actiontext (7.1.1)
actionpack (= 7.1.1)
activerecord (= 7.1.1)
activestorage (= 7.1.1)
activesupport (= 7.1.1)
actiontext (7.1.2)
actionpack (= 7.1.2)
activerecord (= 7.1.2)
activestorage (= 7.1.2)
activesupport (= 7.1.2)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.1.1)
activesupport (= 7.1.1)
actionview (7.1.2)
activesupport (= 7.1.2)
builder (~> 3.1)
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
Expand All @@ -71,22 +72,22 @@ GEM
activemodel (>= 4.1)
case_transform (>= 0.2)
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
activejob (7.1.1)
activesupport (= 7.1.1)
activejob (7.1.2)
activesupport (= 7.1.2)
globalid (>= 0.3.6)
activemodel (7.1.1)
activesupport (= 7.1.1)
activerecord (7.1.1)
activemodel (= 7.1.1)
activesupport (= 7.1.1)
activemodel (7.1.2)
activesupport (= 7.1.2)
activerecord (7.1.2)
activemodel (= 7.1.2)
activesupport (= 7.1.2)
timeout (>= 0.4.0)
activestorage (7.1.1)
actionpack (= 7.1.1)
activejob (= 7.1.1)
activerecord (= 7.1.1)
activesupport (= 7.1.1)
activestorage (7.1.2)
actionpack (= 7.1.2)
activejob (= 7.1.2)
activerecord (= 7.1.2)
activesupport (= 7.1.2)
marcel (~> 1.0)
activesupport (7.1.1)
activesupport (7.1.2)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
Expand All @@ -104,17 +105,20 @@ GEM
aes_key_wrap (1.1.0)
ast (2.4.2)
aws-eventstream (1.2.0)
aws-partitions (1.848.0)
aws-partitions (1.853.0)
aws-record (2.13.0)
aws-sdk-dynamodb (~> 1, >= 1.85.0)
aws-sdk-core (3.186.0)
aws-sdk-core (3.187.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.5)
jmespath (~> 1, >= 1.6.1)
aws-sdk-dynamodb (1.96.0)
aws-sdk-core (~> 3, >= 3.184.0)
aws-sigv4 (~> 1.1)
aws-sdk-kms (1.72.0)
aws-sdk-core (~> 3, >= 3.184.0)
aws-sigv4 (~> 1.1)
aws-sdk-rails (3.9.0)
aws-record (~> 2)
aws-sdk-ses (~> 1, >= 1.50.0)
Expand All @@ -123,13 +127,17 @@ GEM
aws-sessionstore-dynamodb (~> 2)
concurrent-ruby (~> 1)
railties (>= 5.2.0)
aws-sdk-s3 (1.136.0)
aws-sdk-core (~> 3, >= 3.181.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.6)
aws-sdk-ses (1.56.0)
aws-sdk-core (~> 3, >= 3.184.0)
aws-sigv4 (~> 1.1)
aws-sdk-sesv2 (1.41.0)
aws-sdk-core (~> 3, >= 3.184.0)
aws-sigv4 (~> 1.1)
aws-sdk-sqs (1.65.0)
aws-sdk-sqs (1.67.0)
aws-sdk-core (~> 3, >= 3.184.0)
aws-sigv4 (~> 1.1)
aws-sessionstore-dynamodb (2.1.0)
Expand All @@ -138,15 +146,15 @@ GEM
aws-sigv4 (1.6.1)
aws-eventstream (~> 1, >= 1.0.2)
base64 (0.2.0)
bcrypt (3.1.19)
bcrypt (3.1.20)
bigdecimal (3.1.4)
bindata (2.4.15)
bindex (0.8.1)
bootsnap (1.17.0)
msgpack (~> 1.2)
brakeman (6.0.1)
builder (3.2.4)
bullet (7.1.3)
bullet (7.1.4)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.11)
bundler-audit (0.9.1)
Expand Down Expand Up @@ -241,7 +249,7 @@ GEM
activesupport (>= 6.0.0)
railties (>= 6.0.0)
io-console (0.6.0)
irb (1.8.3)
irb (1.9.0)
rdoc
reline (>= 0.3.8)
jbuilder (2.11.5)
Expand Down Expand Up @@ -279,7 +287,7 @@ GEM
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logstop (0.3.1)
loofah (2.21.4)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
mail (2.8.1)
Expand All @@ -302,7 +310,7 @@ GEM
multi_xml (0.6.0)
multipart-post (2.3.0)
mutex_m (0.2.0)
net-imap (0.4.4)
net-imap (0.4.5)
date
net-protocol
net-pop (0.1.2)
Expand All @@ -313,7 +321,7 @@ GEM
net-protocol
newrelic_rpm (9.6.0)
base64
nio4r (2.5.9)
nio4r (2.6.0)
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
Expand Down Expand Up @@ -353,10 +361,10 @@ GEM
method_source (~> 1.0)
psych (5.1.1.1)
stringio
public_suffix (5.0.3)
public_suffix (5.0.4)
puma (6.4.0)
nio4r (~> 2.0)
racc (1.7.2)
racc (1.7.3)
rack (2.2.8)
rack-cors (2.0.1)
rack (>= 2.0.0)
Expand All @@ -369,20 +377,20 @@ GEM
rackup (1.0.0)
rack (< 3)
webrick
rails (7.1.1)
actioncable (= 7.1.1)
actionmailbox (= 7.1.1)
actionmailer (= 7.1.1)
actionpack (= 7.1.1)
actiontext (= 7.1.1)
actionview (= 7.1.1)
activejob (= 7.1.1)
activemodel (= 7.1.1)
activerecord (= 7.1.1)
activestorage (= 7.1.1)
activesupport (= 7.1.1)
rails (7.1.2)
actioncable (= 7.1.2)
actionmailbox (= 7.1.2)
actionmailer (= 7.1.2)
actionpack (= 7.1.2)
actiontext (= 7.1.2)
actionview (= 7.1.2)
activejob (= 7.1.2)
activemodel (= 7.1.2)
activerecord (= 7.1.2)
activestorage (= 7.1.2)
activesupport (= 7.1.2)
bundler (>= 1.15.0)
railties (= 7.1.1)
railties (= 7.1.2)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
Expand All @@ -399,9 +407,9 @@ GEM
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.1.1)
actionpack (= 7.1.1)
activesupport (= 7.1.1)
railties (7.1.2)
actionpack (= 7.1.2)
activesupport (= 7.1.2)
irb
rackup (>= 1.0.0)
rake (>= 12.2)
Expand All @@ -421,7 +429,7 @@ GEM
redis-namespace (1.11.0)
redis (>= 4)
regexp_parser (2.8.2)
reline (0.3.9)
reline (0.4.0)
io-console (~> 0.5)
request_store (1.5.1)
rack (>= 1.4)
Expand Down Expand Up @@ -466,10 +474,11 @@ GEM
rubocop (~> 1.41)
rubocop-factory_bot (2.24.0)
rubocop (~> 1.33)
rubocop-rails (2.22.1)
rubocop-rails (2.22.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
rubocop-rspec (2.25.0)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
Expand Down Expand Up @@ -566,6 +575,7 @@ DEPENDENCIES
acts-as-list
acts-as-taggable-on
aws-sdk-rails (>= 3.8.0)
aws-sdk-s3
bootsnap
brakeman
bullet
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/site.scss
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ footer {
.well {
border: 1px solid #d6d7d9;
padding: 20px;
margin: 10px 0;
margin-bottom: 10px;
overflow-wrap: break-word;
}

Expand Down
33 changes: 27 additions & 6 deletions app/controllers/admin/cx_collection_details_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Admin::CxCollectionDetailsController < AdminController
before_action :set_cx_collection_detail, only: %i[ show edit upload update destroy ]
before_action :set_cx_collection_detail, only: %i[ show edit upload upload_csv update destroy ]
before_action :set_cx_collections, only: %i[ new edit upload ]

def index
Expand All @@ -26,8 +26,8 @@ def create

respond_to do |format|
if @cx_collection_detail.save
format.html { redirect_to admin_cx_collection_detail_url(@cx_collection_detail), notice: "Cx collection detail was successfully created." }
format.json { render :show, status: :created, location: @cx_collection_detail }
format.html { redirect_to upload_admin_cx_collection_detail_url(@cx_collection_detail), notice: "CX Collection Detail was successfully created." }
format.json { render :upload, status: :created, location: @cx_collection_detail }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @cx_collection_detail.errors, status: :unprocessable_entity }
Expand All @@ -38,7 +38,7 @@ def create
def update
respond_to do |format|
if @cx_collection_detail.update(cx_collection_detail_params)
format.html { redirect_to admin_cx_collection_detail_url(@cx_collection_detail), notice: "Cx collection detail was successfully updated." }
format.html { redirect_to admin_cx_collection_detail_url(@cx_collection_detail), notice: "CX Collection Detail was successfully updated." }
format.json { render :show, status: :ok, location: @cx_collection_detail }
else
format.html { render :edit, status: :unprocessable_entity }
Expand All @@ -51,19 +51,40 @@ def destroy
@cx_collection_detail.destroy

respond_to do |format|
format.html { redirect_to cx_collection_details_url, notice: "Cx collection detail was successfully destroyed." }
format.html { redirect_to cx_collection_details_url, notice: "CX Collection Detail was successfully destroyed." }
format.json { head :no_content }
end
end

# Handle a large-ish csv upload (5+ MB) to S3
def upload_csv
file = params[:file] # Assuming the file comes from a form field named 'file'
bucket = ENV.fetch("S3_UPLOADS_AWS_BUCKET_NAME")

s3 = Aws::S3::Resource.new
key = "cx_data_collections/cx-upload-#{Time.now.to_i}-#{file.original_filename}}"
obj = s3.bucket(bucket).object(file.original_filename)
# Upload the file
response = obj.upload_file(file.path)

CxCollectionDetailUpload.create!({
user_id: current_user.id,
cx_collection_detail_id: @cx_collection_detail.id,
size: obj.size,
key: obj.key,
})

render :upload, message: 'File successfully uploaded'
end

private
def set_cx_collection_detail
@cx_collection_detail = CxCollectionDetail.find(params[:id])
end

def set_cx_collections
if service_manager_permissions?
@cx_collections = CxCollection.all.includes(:organization)
@cx_collections = CxCollection.all.includes(:organization).order('organizations.abbreviation')
else
@cx_collections = current_user.organization.cx_collections
end
Expand Down
Loading