mirror of
https://github.com/Growstuff/growstuff.git
synced 2025-12-24 01:57:46 -05:00
Fixed linter issue, empty line after guard clause
This commit is contained in:
@@ -128,6 +128,7 @@ class CropsController < ApplicationController
|
||||
|
||||
def notify_wranglers
|
||||
return if current_member.role? :crop_wrangler
|
||||
|
||||
Role.crop_wranglers.each do |w|
|
||||
Notifier.new_crop_request(w, @crop).deliver_now!
|
||||
end
|
||||
@@ -135,6 +136,7 @@ class CropsController < ApplicationController
|
||||
|
||||
def recreate_names(param_name, name_type)
|
||||
return if params[param_name].blank?
|
||||
|
||||
destroy_names(name_type)
|
||||
params[param_name].each do |_i, value|
|
||||
create_name!(name_type, value) unless value.empty?
|
||||
|
||||
@@ -4,6 +4,7 @@ class PhotoAssociationsController < ApplicationController
|
||||
|
||||
def destroy
|
||||
raise "Photos not supported" unless Photo::PHOTO_CAPABLE.include? item_class
|
||||
|
||||
@photo = Photo.find_by!(id: params[:photo_id], owner: current_member)
|
||||
@item = Photographing.item(item_id, item_class)
|
||||
@item.photos.delete(@photo)
|
||||
|
||||
@@ -36,6 +36,7 @@ class PhotosController < ApplicationController
|
||||
@photo = find_or_create_photo_from_flickr_photo
|
||||
@item = item_to_link_to
|
||||
raise "Could not find this #{type} owned by you" unless @item
|
||||
|
||||
@item.photos << @photo unless @item.photos.include? @photo
|
||||
@photo.save! if @photo.present?
|
||||
end
|
||||
@@ -77,8 +78,10 @@ class PhotosController < ApplicationController
|
||||
def item_to_link_to
|
||||
raise "No item id provided" if item_id.nil?
|
||||
raise "No item type provided" if item_type.nil?
|
||||
|
||||
item_class = item_type.capitalize
|
||||
raise "Photos not supported" unless Photo::PHOTO_CAPABLE.include? item_class
|
||||
|
||||
item_class.constantize.find(params[:id])
|
||||
end
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ module ApplicationHelper
|
||||
#
|
||||
def avatar_uri(member, size = 150)
|
||||
return unless member
|
||||
|
||||
if member.preferred_avatar_uri.present?
|
||||
# Some avatars support different sizes
|
||||
# http://graph.facebook.com/12345678/picture?width=150&height=150
|
||||
|
||||
@@ -24,6 +24,7 @@ module HarvestsHelper
|
||||
|
||||
def display_weight(harvest)
|
||||
return if harvest.weight_quantity.blank? || harvest.weight_quantity <= 0
|
||||
|
||||
"#{number_to_human(harvest.weight_quantity, strip_insignificant_zeros: true)} #{harvest.weight_unit}"
|
||||
end
|
||||
|
||||
|
||||
@@ -35,11 +35,13 @@ module PlantingsHelper
|
||||
|
||||
def days_from_now_to_finished(planting)
|
||||
return unless planting.finish_is_predicatable?
|
||||
|
||||
(planting.finish_predicted_at - Time.zone.today).to_i
|
||||
end
|
||||
|
||||
def days_from_now_to_first_harvest(planting)
|
||||
return unless planting.planted_at.present? && planting.first_harvest_predicted_at.present?
|
||||
|
||||
(planting.first_harvest_predicted_at - Time.zone.today).to_i
|
||||
end
|
||||
|
||||
|
||||
@@ -13,11 +13,13 @@ module PredictHarvest
|
||||
|
||||
def first_harvest_predicted_at
|
||||
return unless crop.median_days_to_first_harvest.present? && planted_at.present?
|
||||
|
||||
planted_at + crop.median_days_to_first_harvest.days
|
||||
end
|
||||
|
||||
def last_harvest_predicted_at
|
||||
return unless crop.median_days_to_last_harvest.present? && planted_at.present?
|
||||
|
||||
planted_at + crop.median_days_to_last_harvest.days
|
||||
end
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ module PredictPlanting
|
||||
|
||||
def actual_lifespan
|
||||
return unless planted_at.present? && finished_at.present?
|
||||
|
||||
(finished_at - planted_at).to_i
|
||||
end
|
||||
|
||||
|
||||
@@ -156,6 +156,7 @@ class Crop < ApplicationRecord
|
||||
min_photos = 3 # needs this many photos to be interesting
|
||||
return false unless photos.size >= min_photos
|
||||
return false unless plantings_count >= min_plantings
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
@@ -181,6 +182,7 @@ class Crop < ApplicationRecord
|
||||
|
||||
def rejection_explanation
|
||||
return rejection_notes if reason_for_rejection == "other"
|
||||
|
||||
reason_for_rejection
|
||||
end
|
||||
|
||||
@@ -222,17 +224,20 @@ class Crop < ApplicationRecord
|
||||
def approval_status_cannot_be_changed_again
|
||||
previous = previous_changes.include?(:approval_status) ? previous_changes.approval_status : {}
|
||||
return unless previous.include?(:rejected) || previous.include?(:approved)
|
||||
|
||||
errors.add(:approval_status, "has already been set to #{approval_status}")
|
||||
end
|
||||
|
||||
def must_be_rejected_if_rejected_reasons_present
|
||||
return if rejected?
|
||||
return unless reason_for_rejection.present? || rejection_notes.present?
|
||||
|
||||
errors.add(:approval_status, "must be rejected if a reason for rejection is present")
|
||||
end
|
||||
|
||||
def must_have_meaningful_reason_for_rejection
|
||||
return unless reason_for_rejection == "other" && rejection_notes.blank?
|
||||
|
||||
errors.add(:rejection_notes, "must be added if the reason for rejection is \"other\"")
|
||||
end
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ class CsvImporter
|
||||
def add_alternate_names(alternate_names)
|
||||
# i.e. we actually passed something in, which isn't a given
|
||||
return if alternate_names.blank?
|
||||
|
||||
alternate_names.split(/,\s*/).each do |name|
|
||||
altname = AlternateName.find_by(name: name, crop: @crop)
|
||||
altname ||= AlternateName.create! name: name, crop: @crop, creator: cropbot
|
||||
|
||||
@@ -70,6 +70,7 @@ class Harvest < ApplicationRecord
|
||||
|
||||
def time_from_planting_to_harvest
|
||||
return if planting.blank?
|
||||
|
||||
harvested_at - planting.planted_at
|
||||
end
|
||||
|
||||
@@ -77,6 +78,7 @@ class Harvest < ApplicationRecord
|
||||
# to make data manipulation easier
|
||||
def set_si_weight
|
||||
return if weight_unit.nil?
|
||||
|
||||
weight_string = "#{weight_quantity} #{weight_unit}"
|
||||
self.si_weight = Unit.new(weight_string).convert_to("kg").to_s("%0.3f").delete(" kg").to_f
|
||||
end
|
||||
@@ -101,11 +103,13 @@ class Harvest < ApplicationRecord
|
||||
|
||||
def quantity_to_human
|
||||
return number_to_human(quantity.to_s, strip_insignificant_zeros: true) if quantity
|
||||
|
||||
""
|
||||
end
|
||||
|
||||
def unit_to_human
|
||||
return "" unless quantity
|
||||
|
||||
if unit == 'individual'
|
||||
'individual'
|
||||
elsif quantity == 1
|
||||
@@ -117,6 +121,7 @@ class Harvest < ApplicationRecord
|
||||
|
||||
def weight_to_human
|
||||
return "" unless weight_quantity
|
||||
|
||||
"weighing #{number_to_human(weight_quantity, strip_insignificant_zeros: true)} #{weight_unit}"
|
||||
end
|
||||
|
||||
@@ -138,17 +143,20 @@ class Harvest < ApplicationRecord
|
||||
|
||||
def crop_must_match_planting
|
||||
return if planting.blank? # only check if we are linked to a planting
|
||||
|
||||
errors.add(:planting, "must be the same crop") unless crop == planting.crop
|
||||
end
|
||||
|
||||
def owner_must_match_planting
|
||||
return if planting.blank? # only check if we are linked to a planting
|
||||
|
||||
errors.add(:owner, "of harvest must be the same as planting") unless owner == planting.owner
|
||||
end
|
||||
|
||||
def harvest_must_be_after_planting
|
||||
# only check if we are linked to a planting
|
||||
return unless harvested_at.present? && planting.present? && planting.planted_at.present?
|
||||
|
||||
errors.add(:planting, "cannot be harvested before planting") unless harvested_at > planting.planted_at
|
||||
end
|
||||
end
|
||||
|
||||
@@ -85,6 +85,7 @@ class Member < ApplicationRecord
|
||||
conditions = warden_conditions.dup
|
||||
login = conditions.delete(:login)
|
||||
return where(conditions).login_name_or_email(login).first if login
|
||||
|
||||
find_by(conditions)
|
||||
end
|
||||
|
||||
@@ -133,6 +134,7 @@ class Member < ApplicationRecord
|
||||
)
|
||||
end
|
||||
return [result.photo, result.total] if result
|
||||
|
||||
[[], 0]
|
||||
end
|
||||
|
||||
@@ -182,6 +184,7 @@ class Member < ApplicationRecord
|
||||
|
||||
def newsletter_subscribe(gibbon = Gibbon::API.new, testing = false)
|
||||
return true if Rails.env.test? && !testing
|
||||
|
||||
gibbon.lists.subscribe(
|
||||
id: Rails.application.config.newsletter_list_id,
|
||||
email: { email: email },
|
||||
@@ -192,6 +195,7 @@ class Member < ApplicationRecord
|
||||
|
||||
def newsletter_unsubscribe(gibbon = Gibbon::API.new, testing = false)
|
||||
return true if Rails.env.test? && !testing
|
||||
|
||||
gibbon.lists.unsubscribe(id: Rails.application.config.newsletter_list_id,
|
||||
email: { email: email })
|
||||
end
|
||||
|
||||
@@ -101,6 +101,7 @@ class Planting < ApplicationRecord
|
||||
# check that any finished_at date occurs after planted_at
|
||||
def finished_must_be_after_planted
|
||||
return unless planted_at && finished_at # only check if we have both
|
||||
|
||||
errors.add(:finished_at, "must be after the planting date") unless planted_at < finished_at
|
||||
end
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ class Post < ApplicationRecord
|
||||
# don't send notifications to yourself
|
||||
recipients.map(&:id).each do |recipient_id|
|
||||
next unless recipient_id != sender
|
||||
|
||||
Notification.create(
|
||||
recipient_id: recipient_id,
|
||||
sender_id: sender,
|
||||
|
||||
@@ -96,6 +96,7 @@ end
|
||||
module CmsDeviseAuth
|
||||
def authenticate
|
||||
return if current_member&.role?(:admin)
|
||||
|
||||
redirect_to root_path, alert: 'Permission denied. Please sign in as an admin user to use the CMS admin area.'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,6 +7,7 @@ module Geocodable
|
||||
|
||||
def empty_unwanted_geocodes
|
||||
return if location.present?
|
||||
|
||||
self.latitude = nil
|
||||
self.longitude = nil
|
||||
end
|
||||
|
||||
@@ -9,6 +9,7 @@ end
|
||||
def output_link(crop, name = nil)
|
||||
url = Rails.application.routes.url_helpers.crop_url(crop, host: Rails.application.config.host)
|
||||
return "<a href=\"#{url}\">#{name}</a>" if name
|
||||
|
||||
"<a href=\"#{url}\">#{crop.name}</a>"
|
||||
end
|
||||
|
||||
@@ -19,6 +20,7 @@ end
|
||||
def output_member_link(member, name = nil)
|
||||
url = Rails.application.routes.url_helpers.member_url(member, only_path: true)
|
||||
return "<a href=\"#{url}\">#{name}</a>" if name
|
||||
|
||||
"<a href=\"#{url}\">#{member.login_name}</a>"
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module ElasticsearchHelpers
|
||||
def sync_elasticsearch(crops)
|
||||
return unless ENV['GROWSTUFF_ELASTICSEARCH'] == "true"
|
||||
|
||||
crops.each { |crop| crop.__elasticsearch__.index_document }
|
||||
Crop.__elasticsearch__.refresh_index!
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user