diff --git a/src/supermarket/app/controllers/api/v1/cookbooks_controller.rb b/src/supermarket/app/controllers/api/v1/cookbooks_controller.rb index 9feba0f653..a5a4ee25f6 100644 --- a/src/supermarket/app/controllers/api/v1/cookbooks_controller.rb +++ b/src/supermarket/app/controllers/api/v1/cookbooks_controller.rb @@ -89,8 +89,9 @@ def contingent private def assign_cookbook - @cookbook = Cookbook.with_name(params[:cookbook]) - .includes(:cookbook_versions) - .first! + @cookbook = Cookbook + .with_name(params[:cookbook]) + .includes(:cookbook_versions) + .first! end end diff --git a/src/supermarket/app/controllers/collaborators_controller.rb b/src/supermarket/app/controllers/collaborators_controller.rb index a143642f3a..1a371cab20 100644 --- a/src/supermarket/app/controllers/collaborators_controller.rb +++ b/src/supermarket/app/controllers/collaborators_controller.rb @@ -12,9 +12,10 @@ class CollaboratorsController < ApplicationController # for a given resource. # def index - @collaborators = User.includes(:chef_account) - .where.not(id: params[:ineligible_user_ids]) - .limit(20) + @collaborators = User + .includes(:chef_account) + .where.not(id: params[:ineligible_user_ids]) + .limit(20) if params[:q] @collaborators = @collaborators.search(params[:q]) @@ -146,11 +147,12 @@ def perform_fieri(cookbook) # Params used when creating one or more +Collaborator+. # def collaborator_params - params.require(:collaborator) - .permit(:resourceable_type, - :resourceable_id, - :user_ids, - :group_ids) + params + .require(:collaborator) + .permit(:resourceable_type, + :resourceable_id, + :user_ids, + :group_ids) end def group_collaborators(resource, group) diff --git a/src/supermarket/app/controllers/cookbooks_controller.rb b/src/supermarket/app/controllers/cookbooks_controller.rb index 4f8df6c084..f64d02496a 100644 --- a/src/supermarket/app/controllers/cookbooks_controller.rb +++ b/src/supermarket/app/controllers/cookbooks_controller.rb @@ -56,18 +56,22 @@ def index # Return the three most recently updated and created cookbooks. # def directory - @recently_updated_cookbooks = Cookbook.order_by_latest_upload_date - .limit(5) - @most_downloaded_cookbooks = Cookbook.includes(:cookbook_versions) - .ordered_by("most_downloaded") - .limit(5) - @most_followed_cookbooks = Cookbook.includes(:cookbook_versions) - .ordered_by("most_followed") - .limit(5) - @featured_cookbooks = Cookbook.includes(:cookbook_versions) - .featured - .order(:name) - .limit(5) + @recently_updated_cookbooks = Cookbook + .order_by_latest_upload_date + .limit(5) + @most_downloaded_cookbooks = Cookbook + .includes(:cookbook_versions) + .ordered_by("most_downloaded") + .limit(5) + @most_followed_cookbooks = Cookbook + .includes(:cookbook_versions) + .ordered_by("most_followed") + .limit(5) + @featured_cookbooks = Cookbook + .includes(:cookbook_versions) + .featured + .order(:name) + .limit(5) @cookbook_count = Cookbook.count @user_count = User.count @@ -154,9 +158,10 @@ def follow # Makes the current user unfollow the specified cookbook. # def unfollow - cookbook_follower = @cookbook.cookbook_followers - .where(user: current_user) - .first! + cookbook_follower = @cookbook + .cookbook_followers + .where(user: current_user) + .first! cookbook_follower.destroy Supermarket::Metrics.increment "cookbook.unfollowed" diff --git a/src/supermarket/app/lib/supermarket/health.rb b/src/supermarket/app/lib/supermarket/health.rb index 998c86de3f..2a1f8e4d38 100644 --- a/src/supermarket/app/lib/supermarket/health.rb +++ b/src/supermarket/app/lib/supermarket/health.rb @@ -56,9 +56,10 @@ def check_features # def expired_ocid_tokens postgres_health_metric do - @supermarket[:expired_ocid_tokens] = Account.for("chef_oauth2") - .where("oauth_expires < ?", Time.current) - .count + @supermarket[:expired_ocid_tokens] = Account + .for("chef_oauth2") + .where("oauth_expires < ?", Time.current) + .count end end diff --git a/src/supermarket/app/models/cookbook.rb b/src/supermarket/app/models/cookbook.rb index bacec70b2e..d1fa3c4021 100644 --- a/src/supermarket/app/models/cookbook.rb +++ b/src/supermarket/app/models/cookbook.rb @@ -333,14 +333,15 @@ def followed_by?(user) # @return [Array] # def contingents - CookbookDependency.includes(cookbook_version: :cookbook) - .where(cookbook_id: id) - .sort_by do |cd| - [ - cd.cookbook_version.cookbook.name, - Chef::Version.new(cd.cookbook_version.version) - ] - end + CookbookDependency + .includes(cookbook_version: :cookbook) + .where(cookbook_id: id) + .sort_by do |cd| + [ + cd.cookbook_version.cookbook.name, + Chef::Version.new(cd.cookbook_version.version) + ] + end end # diff --git a/src/supermarket/app/models/user.rb b/src/supermarket/app/models/user.rb index 97e952daeb..a67fda93d8 100644 --- a/src/supermarket/app/models/user.rb +++ b/src/supermarket/app/models/user.rb @@ -68,8 +68,9 @@ class User < ApplicationRecord # +SystemEmail+ in question # def email_preference_for(name) - email_preferences.includes(:system_email) - .find_by(system_emails: { name: name }) + email_preferences + .includes(:system_email) + .find_by(system_emails: { name: name }) end # diff --git a/src/supermarket/app/workers/cookbook_deletion_worker.rb b/src/supermarket/app/workers/cookbook_deletion_worker.rb index 69aad1a75d..1be3a48311 100644 --- a/src/supermarket/app/workers/cookbook_deletion_worker.rb +++ b/src/supermarket/app/workers/cookbook_deletion_worker.rb @@ -11,22 +11,28 @@ class CookbookDeletionWorker def perform(cookbook) id = cookbook["id"] - subscribed_user_ids = SystemEmail.find_by!(name: "Cookbook deleted") - .subscribed_users - .pluck(:id) + subscribed_user_ids = SystemEmail + .find_by!(name: "Cookbook deleted") + .subscribed_users + .pluck(:id) - followers_or_collaborators = CookbookFollower.where(cookbook_id: id) - .includes(:user) + - Collaborator.where(resourceable_id: id, - resourceable_type: "Cookbook") - .includes(:user) + follows = CookbookFollower + .where(cookbook_id: id) + .includes(:user) + collaborations = Collaborator + .where(resourceable_id: id, resourceable_type: "Cookbook") + .includes(:user) + follows_and_collaborations = follows + collaborations - users = followers_or_collaborators.map(&:user).uniq.select { |u| subscribed_user_ids.include?(u.id) } + users = follows_and_collaborations + .map(&:user) + .uniq + .select { |u| subscribed_user_ids.include?(u.id) } users.each do |user| CookbookMailer.cookbook_deleted_email(cookbook["name"], user).deliver_now end - followers_or_collaborators.each(&:destroy) + follows_and_collaborations.each(&:destroy) end end diff --git a/src/supermarket/app/workers/cookbook_deprecated_notifier.rb b/src/supermarket/app/workers/cookbook_deprecated_notifier.rb index 2d0b9e7e77..6959467f58 100644 --- a/src/supermarket/app/workers/cookbook_deprecated_notifier.rb +++ b/src/supermarket/app/workers/cookbook_deprecated_notifier.rb @@ -26,9 +26,10 @@ def perform(cookbook_id) private def users_to_email(cookbook) - subscribed_user_ids = SystemEmail.find_by!(name: "Cookbook deprecated") - .subscribed_users - .pluck(:id) + subscribed_user_ids = SystemEmail + .find_by!(name: "Cookbook deprecated") + .subscribed_users + .pluck(:id) users_to_email = [] users_to_email << cookbook.owner diff --git a/src/supermarket/app/workers/cookbook_notify_worker.rb b/src/supermarket/app/workers/cookbook_notify_worker.rb index b6582fa7c1..437196d5b6 100644 --- a/src/supermarket/app/workers/cookbook_notify_worker.rb +++ b/src/supermarket/app/workers/cookbook_notify_worker.rb @@ -12,22 +12,24 @@ class CookbookNotifyWorker def perform(cookbook_version_id) cookbook_version = CookbookVersion.find(cookbook_version_id) - active_user_ids = User.joins(:accounts) - .where("provider = ? AND oauth_token != ?", "chef_oauth2", "imported") - .pluck(:id) + active_user_ids = User + .joins(:accounts) + .where("provider = ? AND oauth_token != ?", "chef_oauth2", "imported") + .pluck(:id) - subscribed_user_ids = SystemEmail.find_by!(name: "New cookbook version") - .subscribed_users - .pluck(:id) + subscribed_user_ids = SystemEmail + .find_by!(name: "New cookbook version") + .subscribed_users + .pluck(:id) common_user_ids = active_user_ids & subscribed_user_ids return if common_user_ids.blank? - emailable_cookbook_followers = cookbook_version. - cookbook. - cookbook_followers. - joins(:user). - where(users: { id: common_user_ids }) + emailable_cookbook_followers = cookbook_version + .cookbook + .cookbook_followers + .joins(:user) + .where(users: { id: common_user_ids }) emailable_cookbook_followers.each do |cookbook_follower| CookbookMailer.follower_notification_email(cookbook_version, cookbook_follower.user).deliver_now diff --git a/src/supermarket/config/initializers/paperclip.rb b/src/supermarket/config/initializers/paperclip.rb index c37fb1db9c..0f27e5ca2e 100644 --- a/src/supermarket/config/initializers/paperclip.rb +++ b/src/supermarket/config/initializers/paperclip.rb @@ -5,11 +5,12 @@ # Paperclip has a few remote-fetcher adapters for retrieving attachments from some other place. # We don't want to use them. Remove these adapters, if they are present in the adapter registry. remote_adapters = [Paperclip::UriAdapter, Paperclip::HttpUrlProxyAdapter, Paperclip::DataUriAdapter] -Paperclip.io_adapters - .registered_handlers - .delete_if do |_block, handler_class| - remote_adapters.include?(handler_class) - end +Paperclip + .io_adapters + .registered_handlers + .delete_if do |_block, handler_class| + remote_adapters.include?(handler_class) + end ":class/:attachment/:compatible_id/:style/:basename.:extension".tap do |path| if Supermarket::S3ConfigAudit.use_s3?(ENV)