mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-06-04 22:27:18 -04:00
Compare commits
5 Commits
mainline
...
refactor-h
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ee86b6b38 | ||
|
|
dc11a1674d | ||
|
|
4085014e06 | ||
|
|
18986ee133 | ||
|
|
f5a4ba60fe |
10
.github/workflows/docker-build-push.yml
vendored
10
.github/workflows/docker-build-push.yml
vendored
@@ -14,13 +14,13 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v4
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Log in to the Container registry
|
- name: Log in to the Container registry
|
||||||
uses: docker/login-action@v4
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
@@ -28,12 +28,12 @@ jobs:
|
|||||||
|
|
||||||
- name: Extract metadata (tags, labels) for Docker
|
- name: Extract metadata (tags, labels) for Docker
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v6
|
uses: docker/metadata-action@v5
|
||||||
with:
|
with:
|
||||||
images: ghcr.io/${{ github.repository }}
|
images: ghcr.io/${{ github.repository }}
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v7
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: true
|
push: true
|
||||||
|
|||||||
2
Gemfile
2
Gemfile
@@ -116,8 +116,6 @@ gem 'xmlrpc' # fixes rake error - can be removed if not needed later
|
|||||||
|
|
||||||
gem 'puma'
|
gem 'puma'
|
||||||
|
|
||||||
gem 'rack-attack'
|
|
||||||
|
|
||||||
gem 'loofah', '>= 2.19.1'
|
gem 'loofah', '>= 2.19.1'
|
||||||
gem 'rack-protection', '>= 2.0.1'
|
gem 'rack-protection', '>= 2.0.1'
|
||||||
|
|
||||||
|
|||||||
@@ -498,13 +498,11 @@ GEM
|
|||||||
date
|
date
|
||||||
stringio
|
stringio
|
||||||
public_suffix (7.0.5)
|
public_suffix (7.0.5)
|
||||||
puma (8.0.1)
|
puma (8.0.0)
|
||||||
nio4r (~> 2.0)
|
nio4r (~> 2.0)
|
||||||
query_diet (0.7.3)
|
query_diet (0.7.3)
|
||||||
racc (1.8.1)
|
racc (1.8.1)
|
||||||
rack (2.2.23)
|
rack (2.2.23)
|
||||||
rack-attack (6.8.0)
|
|
||||||
rack (>= 1.0, < 4)
|
|
||||||
rack-cors (2.0.2)
|
rack-cors (2.0.2)
|
||||||
rack (>= 2.0.0)
|
rack (>= 2.0.0)
|
||||||
rack-protection (3.2.0)
|
rack-protection (3.2.0)
|
||||||
@@ -843,7 +841,6 @@ DEPENDENCIES
|
|||||||
pry
|
pry
|
||||||
puma
|
puma
|
||||||
query_diet
|
query_diet
|
||||||
rack-attack
|
|
||||||
rack-cors
|
rack-cors
|
||||||
rack-protection (>= 2.0.1)
|
rack-protection (>= 2.0.1)
|
||||||
rails (~> 7.2.0)
|
rails (~> 7.2.0)
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ class ActivitiesController < DataController
|
|||||||
where = {}
|
where = {}
|
||||||
where['active'] = true unless @show_all
|
where['active'] = true unless @show_all
|
||||||
|
|
||||||
if params[:member_slug].present?
|
if params[:member_slug]
|
||||||
@owner = Member.find_by!(slug: params[:member_slug])
|
@owner = Member.find_by(slug: params[:member_slug])
|
||||||
where['owner_id'] = @owner.id
|
where['owner_id'] = @owner.id unless @owner.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
@activities = Activity.search(
|
@activities = Activity.search(
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
module Charts
|
module Charts
|
||||||
class CropsController < ApplicationController
|
class CropsController < ApplicationController
|
||||||
respond_to :json
|
respond_to :json
|
||||||
before_action :set_crop
|
|
||||||
|
|
||||||
def sunniness
|
def sunniness
|
||||||
pie_chart_query 'sunniness'
|
pie_chart_query 'sunniness'
|
||||||
@@ -14,28 +13,20 @@ module Charts
|
|||||||
end
|
end
|
||||||
|
|
||||||
def harvested_for
|
def harvested_for
|
||||||
data = Rails.cache.fetch("#{@crop.cache_key_with_version}/harvested_for", expires_in: 1.day) do
|
@crop = Crop.find_by!(slug: params[:crop_slug])
|
||||||
Harvest.joins(:plant_part)
|
render json: Harvest.joins(:plant_part)
|
||||||
.where(crop: @crop)
|
.where(crop: @crop)
|
||||||
.group("plant_parts.name").count(:id)
|
.group("plant_parts.name").count(:id)
|
||||||
end
|
|
||||||
render json: data
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_crop
|
|
||||||
@crop = Crop.find_by!(slug: params[:crop_slug])
|
|
||||||
end
|
|
||||||
|
|
||||||
def pie_chart_query(field)
|
def pie_chart_query(field)
|
||||||
data = Rails.cache.fetch("#{@crop.cache_key_with_version}/#{field}", expires_in: 1.day) do
|
@crop = Crop.find_by!(slug: params[:crop_slug])
|
||||||
Planting.where(crop: @crop)
|
render json: Planting.where(crop: @crop)
|
||||||
.where.not(field.to_sym => nil)
|
.where.not(field.to_sym => nil)
|
||||||
.where.not(field.to_sym => '')
|
.where.not(field.to_sym => '')
|
||||||
.group(field.to_sym).count(:id)
|
.group(field.to_sym).count(:id)
|
||||||
end
|
|
||||||
render json: data
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
class GardensController < DataController
|
class GardensController < DataController
|
||||||
def index
|
def index
|
||||||
@owner = Member.find_by!(slug: params[:member_slug]) if params[:member_slug].present?
|
@owner = Member.find_by(slug: params[:member_slug])
|
||||||
@show_all = params[:all] == '1'
|
@show_all = params[:all] == '1'
|
||||||
@show_jump_to = params[:member_slug].present? || false
|
@show_jump_to = params[:member_slug].present? || false
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ class HarvestsController < DataController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
where = {}
|
where = {}
|
||||||
if params[:member_slug].present?
|
if params[:member_slug]
|
||||||
@owner = Member.find_by!(slug: params[:member_slug])
|
@owner = Member.find_by(slug: params[:member_slug])
|
||||||
where['owner_id'] = @owner.id
|
where['owner_id'] = @owner.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -102,12 +102,11 @@ class PhotosController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
@current_set = params[:set]
|
@current_set = params[:set]
|
||||||
@current_tag = params[:tag]
|
|
||||||
|
|
||||||
page = params[:page] || 1
|
page = params[:page] || 1
|
||||||
|
|
||||||
@sets = current_member.flickr_sets
|
@sets = current_member.flickr_sets
|
||||||
photos, total = current_member.flickr_photos(page, @current_set, @current_tag)
|
photos, total = current_member.flickr_photos(page, @current_set)
|
||||||
|
|
||||||
@photos = WillPaginate::Collection.create(page, 30, total) do |pager|
|
@photos = WillPaginate::Collection.create(page, 30, total) do |pager|
|
||||||
pager.replace photos
|
pager.replace photos
|
||||||
@@ -119,8 +118,6 @@ class PhotosController < ApplicationController
|
|||||||
{ crops: @crop.id }
|
{ crops: @crop.id }
|
||||||
elsif params[:planting_id]
|
elsif params[:planting_id]
|
||||||
{ planting_id: @planting.id }
|
{ planting_id: @planting.id }
|
||||||
elsif params[:planting_slug]
|
|
||||||
{ plantings: @planting.id }
|
|
||||||
else
|
else
|
||||||
{}
|
{}
|
||||||
end
|
end
|
||||||
@@ -129,6 +126,5 @@ class PhotosController < ApplicationController
|
|||||||
def set_crop_and_planting
|
def set_crop_and_planting
|
||||||
@crop = Crop.find params[:crop_slug] if params[:crop_slug]
|
@crop = Crop.find params[:crop_slug] if params[:crop_slug]
|
||||||
@planting = Planting.find params[:planting_id] if params[:planting_id]
|
@planting = Planting.find params[:planting_id] if params[:planting_id]
|
||||||
@planting ||= Planting.find params[:planting_slug] if params[:planting_slug]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ class PlantingsController < DataController
|
|||||||
where = {}
|
where = {}
|
||||||
where['active'] = true unless @show_all
|
where['active'] = true unless @show_all
|
||||||
|
|
||||||
if params[:member_slug].present?
|
if params[:member_slug]
|
||||||
@owner = Member.find_by!(slug: params[:member_slug])
|
@owner = Member.find_by(slug: params[:member_slug])
|
||||||
where['owner_id'] = @owner.id
|
where['owner_id'] = @owner.id unless @owner.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:crop_slug]
|
if params[:crop_slug]
|
||||||
@@ -160,7 +160,7 @@ class PlantingsController < DataController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def matching_seeds
|
def matching_seeds
|
||||||
@matching_seeds ||= Seed.where(crop: @planting.crop, owner: @planting.owner)
|
Seed.where(crop: @planting.crop, owner: @planting.owner)
|
||||||
.where('(finished_at IS NULL OR finished_at >= ?)', @planting.planted_at)
|
.where('(finished_at IS NULL OR finished_at >= ?)', @planting.planted_at)
|
||||||
.where('(saved_at IS NULL OR saved_at <= ?)', @planting.planted_at)
|
.where('(saved_at IS NULL OR saved_at <= ?)', @planting.planted_at)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class PostsController < ApplicationController
|
|||||||
respond_to :rss, only: %i(index show)
|
respond_to :rss, only: %i(index show)
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@author = Member.find_by!(slug: params[:member_slug]) if params[:member_slug].present?
|
@author = Member.find_by(slug: params[:member_slug])
|
||||||
@posts = posts
|
@posts = posts
|
||||||
respond_with(@posts)
|
respond_with(@posts)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ class SeedsController < DataController
|
|||||||
where = {}
|
where = {}
|
||||||
|
|
||||||
if params[:member_slug].present?
|
if params[:member_slug].present?
|
||||||
@owner = Member.find_by!(slug: params[:member_slug])
|
@owner = Member.find_by(slug: params[:member_slug])
|
||||||
where['owner_id'] = @owner.id
|
where['owner_id'] = @owner.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -2,47 +2,28 @@
|
|||||||
|
|
||||||
module CropsHelper
|
module CropsHelper
|
||||||
def crop_or_parent(crop, attribute)
|
def crop_or_parent(crop, attribute)
|
||||||
@crop_or_parent_cache ||= {}
|
default = crop.send(attribute)
|
||||||
cache_key = [crop.persisted? ? crop.id : crop.object_id, attribute]
|
return default if default.present?
|
||||||
return @crop_or_parent_cache[cache_key] if @crop_or_parent_cache.key?(cache_key)
|
|
||||||
|
|
||||||
@crop_or_parent_cache[cache_key] = begin
|
parent = crop
|
||||||
value = crop.send(attribute)
|
while parent = parent.parent
|
||||||
if value.blank?
|
return parent.send(attribute) if parent&.send(attribute).present?
|
||||||
parent = crop
|
|
||||||
while (parent = parent.parent)
|
|
||||||
parent_value = parent.send(attribute)
|
|
||||||
if parent_value.present?
|
|
||||||
value = parent_value
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
value
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# For scopes, arrays, etc return the empty value
|
||||||
|
default
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_seed_availability(member, crop)
|
def display_seed_availability(member, crop)
|
||||||
@seed_availability_cache ||= {}
|
seeds = member.seeds.where(crop:)
|
||||||
cache_key = [
|
total_quantity = seeds.where.not(quantity: nil).sum(:quantity)
|
||||||
member.persisted? ? member.id : member.object_id,
|
|
||||||
crop.persisted? ? crop.id : crop.object_id
|
|
||||||
]
|
|
||||||
return @seed_availability_cache[cache_key] if @seed_availability_cache.key?(cache_key)
|
|
||||||
|
|
||||||
@seed_availability_cache[cache_key] = begin
|
return "You don't have any seeds of this crop." if seeds.none?
|
||||||
seeds = member.seeds.where(crop:)
|
|
||||||
|
|
||||||
if seeds.none?
|
if total_quantity == 0
|
||||||
"You don't have any seeds of this crop."
|
"You have an unknown quantity of seeds of this crop."
|
||||||
else
|
else
|
||||||
total_quantity = seeds.where.not(quantity: nil).sum(:quantity)
|
"You have #{total_quantity} #{Seed.model_name.human(count: total_quantity)} of this crop."
|
||||||
if total_quantity == 0
|
|
||||||
"You have an unknown quantity of seeds of this crop."
|
|
||||||
else
|
|
||||||
"You have #{total_quantity} #{Seed.model_name.human(count: total_quantity)} of this crop."
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -59,57 +40,53 @@ module CropsHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def crop_jsonld_data(crop, full_attributes: true)
|
def crop_jsonld_data(crop, full_attributes: true)
|
||||||
Rails.cache.fetch([crop.cache_key_with_version, "jsonld", full_attributes]) do
|
same_as_urls = [crop.en_wikipedia_url]
|
||||||
same_as_urls = [crop.en_wikipedia_url]
|
crop.scientific_names.each do |scientific_name|
|
||||||
crop.scientific_names.each do |scientific_name|
|
same_as_urls << "https://www.wikidata.org/wiki/#{scientific_name.wikidata_id}" if scientific_name.wikidata_id.present?
|
||||||
if scientific_name.wikidata_id.present?
|
|
||||||
same_as_urls << "https://www.wikidata.org/wiki/#{scientific_name.wikidata_id}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
subject_of_entities = []
|
|
||||||
images = []
|
|
||||||
if full_attributes
|
|
||||||
if crop.en_youtube_url.present?
|
|
||||||
subject_of_entities << {
|
|
||||||
'@type': "VideoObject",
|
|
||||||
url: crop.en_youtube_url
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
crop.posts.each do |post|
|
|
||||||
subject_of_entities << {
|
|
||||||
'@type': "SocialMediaPosting",
|
|
||||||
url: post_url(post),
|
|
||||||
author: {
|
|
||||||
'@type': 'Person',
|
|
||||||
name: post.author.login_name
|
|
||||||
},
|
|
||||||
datePublished: post.created_at
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
crop.photos.each do |photo|
|
|
||||||
images << photo.fullsize_url
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# TODO: Review plantings, seeds, harvests as a subtype of social media post or event that ended? Or creative work?
|
|
||||||
# has_many :plantings, dependent: :destroy
|
|
||||||
# has_many :seeds, dependent: :destroy
|
|
||||||
# has_many :harvests, dependent: :destroy
|
|
||||||
|
|
||||||
{
|
|
||||||
'@context': "https://schema.org",
|
|
||||||
'@type': "BioChemEntity",
|
|
||||||
name: crop.name,
|
|
||||||
taxonomicRange: crop.scientific_names.map(&:name),
|
|
||||||
description: crop.description,
|
|
||||||
sameAs: same_as_urls,
|
|
||||||
alternateName: crop.alternate_names.map(&:name),
|
|
||||||
subjectOf: subject_of_entities,
|
|
||||||
image: images
|
|
||||||
}.compact
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
subject_of_entities = []
|
||||||
|
if full_attributes
|
||||||
|
if crop.en_youtube_url.present?
|
||||||
|
subject_of_entities << {
|
||||||
|
'@type': "VideoObject",
|
||||||
|
url: crop.en_youtube_url
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
crop.posts.each do |post|
|
||||||
|
subject_of_entities << {
|
||||||
|
'@type': "SocialMediaPosting",
|
||||||
|
url: post_url(post),
|
||||||
|
author: {
|
||||||
|
'@type': 'Person',
|
||||||
|
name: post.author.login_name
|
||||||
|
},
|
||||||
|
datePublished: post.created_at
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
images = []
|
||||||
|
crop.photos.each do |photo|
|
||||||
|
images << photo.fullsize_url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO: Review plantings, seeds, harvests as a subtype of social media post or event that ended? Or creative work?
|
||||||
|
# has_many :plantings, dependent: :destroy
|
||||||
|
# has_many :seeds, dependent: :destroy
|
||||||
|
# has_many :harvests, dependent: :destroy
|
||||||
|
|
||||||
|
{
|
||||||
|
'@context': "https://schema.org",
|
||||||
|
'@type': "BioChemEntity",
|
||||||
|
name: crop.name,
|
||||||
|
taxonomicRange: crop.scientific_names.map(&:name),
|
||||||
|
description: crop.description,
|
||||||
|
sameAs: same_as_urls,
|
||||||
|
alternateName: crop.alternate_names.map(&:name),
|
||||||
|
subjectOf: subject_of_entities,
|
||||||
|
image: images
|
||||||
|
}.compact
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -46,13 +46,9 @@ module PlantingsHelper
|
|||||||
# Returns a list of gardens the planting can be transplanted to
|
# Returns a list of gardens the planting can be transplanted to
|
||||||
# based on the planting's owner.
|
# based on the planting's owner.
|
||||||
def transplantable_gardens_by_owner(planting)
|
def transplantable_gardens_by_owner(planting)
|
||||||
@transplantable_gardens ||= {}
|
garden_ids = planting.owner.gardens.select(:id).to_a + GardenCollaborator.where(member_id: planting.owner.id).select(:garden_id).to_a
|
||||||
cache_key = planting.id || planting.object_id
|
|
||||||
@transplantable_gardens[cache_key] ||= begin
|
|
||||||
garden_ids = planting.owner.gardens.select(:id).to_a + GardenCollaborator.where(member_id: planting.owner.id).select(:garden_id).to_a
|
|
||||||
|
|
||||||
Garden.active.where.not(id: planting.garden_id).where(id: garden_ids)
|
Garden.active.where.not(id: planting.garden_id).where(id: garden_ids)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def days_from_now_to_last_harvest(planting)
|
def days_from_now_to_last_harvest(planting)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ApplicationMailer < ActionMailer::Base
|
class ApplicationMailer < ActionMailer::Base
|
||||||
default from: 'from@example.com'
|
default from: "Growstuff <#{Rails.configuration.x.email[:from]}>"
|
||||||
layout 'mailer'
|
layout 'mailer'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
class NotifierMailer < ApplicationMailer
|
class NotifierMailer < ApplicationMailer
|
||||||
# include NotificationsHelper
|
# include NotificationsHelper
|
||||||
default from: "Growstuff <#{ENV.fetch('GROWSTUFF_EMAIL', nil)}>"
|
default from: "Growstuff <#{Rails.configuration.x.email[:from]}>"
|
||||||
|
|
||||||
def verifier
|
def verifier
|
||||||
unless ENV['RAILS_SECRET_TOKEN']
|
unless ENV['RAILS_SECRET_TOKEN']
|
||||||
|
|||||||
@@ -40,15 +40,8 @@ module MemberFlickr
|
|||||||
# Fetches a collection of photos from Flickr
|
# Fetches a collection of photos from Flickr
|
||||||
# Returns a [[page of photos], total] pair.
|
# Returns a [[page of photos], total] pair.
|
||||||
# Total is needed for pagination.
|
# Total is needed for pagination.
|
||||||
def flickr_photos(page_num = 1, set = nil, tags = nil)
|
def flickr_photos(page_num = 1, set = nil)
|
||||||
result = if tags.present?
|
result = if set
|
||||||
flickr.photos.search(
|
|
||||||
user_id: 'me',
|
|
||||||
tags: tags,
|
|
||||||
page: page_num,
|
|
||||||
per_page: 30
|
|
||||||
)
|
|
||||||
elsif set.present?
|
|
||||||
flickr.photosets.getPhotos(
|
flickr.photosets.getPhotos(
|
||||||
photoset_id: set,
|
photoset_id: set,
|
||||||
page: page_num,
|
page: page_num,
|
||||||
|
|||||||
@@ -6,31 +6,23 @@ module PredictHarvest
|
|||||||
included do
|
included do
|
||||||
# dates
|
# dates
|
||||||
def first_harvest_date
|
def first_harvest_date
|
||||||
return @first_harvest_date if defined?(@first_harvest_date)
|
harvests_with_dates.minimum(:harvested_at)
|
||||||
|
|
||||||
@first_harvest_date = harvests_with_dates.minimum(:harvested_at)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def last_harvest_date
|
def last_harvest_date
|
||||||
return @last_harvest_date if defined?(@last_harvest_date)
|
harvests_with_dates.maximum(:harvested_at)
|
||||||
|
|
||||||
@last_harvest_date = harvests_with_dates.maximum(:harvested_at)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def first_harvest_predicted_at
|
def first_harvest_predicted_at
|
||||||
return @first_harvest_predicted_at if defined?(@first_harvest_predicted_at)
|
return unless crop.median_days_to_first_harvest.present? && planted_at.present?
|
||||||
|
|
||||||
@first_harvest_predicted_at = if crop.median_days_to_first_harvest.present? && planted_at.present?
|
planted_at + crop.median_days_to_first_harvest.days
|
||||||
planted_at + crop.median_days_to_first_harvest.days
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def last_harvest_predicted_at
|
def last_harvest_predicted_at
|
||||||
return @last_harvest_predicted_at if defined?(@last_harvest_predicted_at)
|
return unless crop.median_days_to_last_harvest.present? && planted_at.present?
|
||||||
|
|
||||||
@last_harvest_predicted_at = if crop.median_days_to_last_harvest.present? && planted_at.present?
|
planted_at + crop.median_days_to_last_harvest.days
|
||||||
planted_at + crop.median_days_to_last_harvest.days
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# actions
|
# actions
|
||||||
@@ -73,18 +65,16 @@ module PredictHarvest
|
|||||||
end
|
end
|
||||||
|
|
||||||
def neighbours_for_harvest_predictions
|
def neighbours_for_harvest_predictions
|
||||||
@neighbours_for_harvest_predictions ||= begin
|
# use this planting's harvest if any
|
||||||
# use this planting's harvest if any
|
return harvests if harvests.size.positive?
|
||||||
if harvests.size.positive?
|
|
||||||
harvests
|
# otherwise use nearby plantings
|
||||||
# otherwise use nearby plantings
|
if location
|
||||||
elsif location
|
return Harvest.where(planting: nearby_same_crop.has_harvests)
|
||||||
Harvest.where(planting: nearby_same_crop.has_harvests)
|
.where.not(planting_id: nil)
|
||||||
.where.not(planting_id: nil)
|
|
||||||
else
|
|
||||||
Harvest.none
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Harvest.none
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -13,49 +13,40 @@ module PredictPlanting
|
|||||||
|
|
||||||
# dates
|
# dates
|
||||||
def finish_predicted_at
|
def finish_predicted_at
|
||||||
return @finish_predicted_at if defined?(@finish_predicted_at)
|
if planted_at.blank? || failed?
|
||||||
|
nil
|
||||||
@finish_predicted_at = if planted_at.blank? || failed?
|
elsif crop.median_lifespan.present?
|
||||||
nil
|
planted_at + crop.median_lifespan.days
|
||||||
elsif crop.median_lifespan.present?
|
elsif crop.parent.present? && crop.parent.median_lifespan.present?
|
||||||
planted_at + crop.median_lifespan.days
|
planted_at + crop.parent.median_lifespan.days
|
||||||
elsif crop.parent.present? && crop.parent.median_lifespan.present?
|
end
|
||||||
planted_at + crop.parent.median_lifespan.days
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# days
|
# days
|
||||||
def expected_lifespan
|
def expected_lifespan
|
||||||
return @expected_lifespan if defined?(@expected_lifespan)
|
if actual_lifespan.present?
|
||||||
|
actual_lifespan
|
||||||
@expected_lifespan = if actual_lifespan.present?
|
elsif crop.median_lifespan.present?
|
||||||
actual_lifespan
|
crop.median_lifespan
|
||||||
elsif crop.median_lifespan.present?
|
elsif crop.parent.present? && crop.parent.median_lifespan.present?
|
||||||
crop.median_lifespan
|
crop.parent.median_lifespan
|
||||||
elsif crop.parent.present? && crop.parent.median_lifespan.present?
|
end
|
||||||
crop.parent.median_lifespan
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def actual_lifespan
|
def actual_lifespan
|
||||||
return @actual_lifespan if defined?(@actual_lifespan)
|
return unless planted_at.present? && finished_at.present? && !failed?
|
||||||
|
|
||||||
@actual_lifespan = if planted_at.present? && finished_at.present? && !failed?
|
(finished_at - planted_at).to_i
|
||||||
(finished_at - planted_at).to_i
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def age_in_days
|
def age_in_days
|
||||||
return @age_in_days if defined?(@age_in_days)
|
return if planted_at.blank?
|
||||||
|
return if failed?
|
||||||
|
|
||||||
@age_in_days = if planted_at.blank? || failed?
|
known_last_day ||= finished_at || Time.zone.today
|
||||||
nil
|
known_last_day = Time.zone.today if known_last_day > Time.zone.today
|
||||||
else
|
|
||||||
known_last_day = finished_at || Time.zone.today
|
|
||||||
known_last_day = Time.zone.today if known_last_day > Time.zone.today
|
|
||||||
|
|
||||||
(known_last_day - planted_at).to_i
|
(known_last_day - planted_at).to_i
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def percentage_grown
|
def percentage_grown
|
||||||
|
|||||||
@@ -109,49 +109,37 @@ class Harvest < ApplicationRecord
|
|||||||
def to_s
|
def to_s
|
||||||
# 50 individual apples, weighing 3lb
|
# 50 individual apples, weighing 3lb
|
||||||
# 2 buckets of apricots, weighing 10kg
|
# 2 buckets of apricots, weighing 10kg
|
||||||
@to_s ||= "#{quantity_to_human} #{unit_to_human} #{crop_name_to_human} #{weight_to_human}".strip
|
"#{quantity_to_human} #{unit_to_human} #{crop_name_to_human} #{weight_to_human}".strip
|
||||||
end
|
end
|
||||||
|
|
||||||
def quantity_to_human
|
def quantity_to_human
|
||||||
@quantity_to_human ||= if quantity
|
return number_to_human(quantity.to_s, strip_insignificant_zeros: true) if quantity
|
||||||
number_to_human(quantity.to_s, strip_insignificant_zeros: true)
|
|
||||||
else
|
""
|
||||||
""
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def unit_to_human
|
def unit_to_human
|
||||||
@unit_to_human ||= begin
|
return "" unless quantity && unit
|
||||||
if !quantity || !unit
|
return 'individual' if unit == 'individual'
|
||||||
""
|
return "#{unit} of" if quantity == 1
|
||||||
elsif unit == 'individual'
|
|
||||||
'individual'
|
"#{unit.pluralize} of"
|
||||||
elsif quantity == 1
|
|
||||||
"#{unit} of"
|
|
||||||
else
|
|
||||||
"#{unit.pluralize} of"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def weight_to_human
|
def weight_to_human
|
||||||
@weight_to_human ||= if weight_quantity
|
return "" unless weight_quantity
|
||||||
"weighing #{number_to_human(weight_quantity, strip_insignificant_zeros: true)} #{weight_unit}"
|
|
||||||
else
|
"weighing #{number_to_human(weight_quantity, strip_insignificant_zeros: true)} #{weight_unit}"
|
||||||
""
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def crop_name_to_human
|
def crop_name_to_human
|
||||||
@crop_name_to_human ||= begin
|
if unit != 'individual' # buckets of apricot*s*
|
||||||
if unit != 'individual' # buckets of apricot*s*
|
crop.name.pluralize
|
||||||
crop.name.pluralize
|
elsif quantity == 1
|
||||||
elsif quantity == 1
|
crop.name
|
||||||
crop.name
|
else
|
||||||
else
|
crop.name.pluralize
|
||||||
crop.name.pluralize
|
end.to_s
|
||||||
end.to_s
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -196,25 +196,4 @@ class Member < ApplicationRecord
|
|||||||
def get_block(member)
|
def get_block(member)
|
||||||
blocks.find_by(blocked_id: member.id) if already_blocking?(member)
|
blocks.find_by(blocked_id: member.id) if already_blocking?(member)
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_activity?
|
|
||||||
(gardens.exists? && gardens.count > 1) ||
|
|
||||||
plantings.exists? ||
|
|
||||||
harvests.exists? ||
|
|
||||||
seeds.exists? ||
|
|
||||||
photos.exists? ||
|
|
||||||
forums.exists? ||
|
|
||||||
activities.exists? ||
|
|
||||||
posts.exists? ||
|
|
||||||
comments.exists? ||
|
|
||||||
requested_crops.exists? ||
|
|
||||||
created_crops.exists? ||
|
|
||||||
likes.exists? ||
|
|
||||||
created_alternate_names.exists? ||
|
|
||||||
created_scientific_names.exists? ||
|
|
||||||
follows.exists? ||
|
|
||||||
inverse_follows.exists? ||
|
|
||||||
blocks.exists? ||
|
|
||||||
inverse_blocks.exists?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -119,18 +119,14 @@ class Planting < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def nearby_same_crop
|
def nearby_same_crop
|
||||||
return @nearby_same_crop if defined?(@nearby_same_crop)
|
return Planting.none if location.blank? || latitude.blank? || longitude.blank?
|
||||||
|
|
||||||
@nearby_same_crop = if location.blank? || latitude.blank? || longitude.blank?
|
# latitude, longitude = Geocoder.coordinates(location, params: { limit: 1 })
|
||||||
Planting.none
|
Planting.joins(:garden)
|
||||||
else
|
.where(crop:)
|
||||||
# latitude, longitude = Geocoder.coordinates(location, params: { limit: 1 })
|
.located
|
||||||
Planting.joins(:garden)
|
.where('gardens.latitude < ? AND gardens.latitude > ?',
|
||||||
.where(crop:)
|
latitude + 10, latitude - 10)
|
||||||
.located
|
|
||||||
.where('gardens.latitude < ? AND gardens.latitude > ?',
|
|
||||||
latitude + 10, latitude - 10)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
- content_for :breadcrumbs do
|
- content_for :breadcrumbs do
|
||||||
- if @owner
|
- if @owner
|
||||||
%li.breadcrumb-item= link_to 'Activities', activities_path
|
%li.breadcrumb-item= link_to 'Activities', activities_path
|
||||||
%li.breadcrumb-item.active= link_to "#{@owner}'s activities", member_activities_path(@owner)
|
%li.breadcrumb-item.active= link_to "#{@owner}'s activities", activities_path(owner: @owner)
|
||||||
- else
|
- else
|
||||||
%li.breadcrumb-item.active= link_to 'Activities', activities_path
|
%li.breadcrumb-item.active= link_to 'Activities', activities_path
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,8 @@
|
|||||||
.form-group
|
.form-group
|
||||||
= f.label :crop_id, class: 'control-label col-md-2'
|
= f.label :crop_id, class: 'control-label col-md-2'
|
||||||
.col-md-8
|
.col-md-8
|
||||||
= select(:alternate_name, :crop_id,
|
= collection_select(:alternate_name, :crop_id,
|
||||||
Crop.order(:name).pluck(:name, :id),
|
Crop.all, :id, :name,
|
||||||
{ selected: @alternate_name.crop_id || @crop.id },
|
{ selected: @alternate_name.crop_id || @crop.id },
|
||||||
class: 'form-control')
|
class: 'form-control')
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@
|
|||||||
|
|
||||||
-# Only crop wranglers see the crop hierarchy (for now)
|
-# Only crop wranglers see the crop hierarchy (for now)
|
||||||
- if can? :wrangle, @crop
|
- if can? :wrangle, @crop
|
||||||
= f.select(:parent_id, Crop.order(:name).pluck(:name, :id),
|
= f.collection_select(:parent_id, Crop.all.order(:name), :id, :name,
|
||||||
{ include_blank: true, label: 'Parent crop'})
|
{ include_blank: true, label: 'Parent crop'})
|
||||||
%span.help-block Optional. For setting up crop hierarchies for varieties etc.
|
%span.help-block Optional. For setting up crop hierarchies for varieties etc.
|
||||||
|
|
||||||
|
|||||||
@@ -5,15 +5,14 @@
|
|||||||
%p Nobody has harvested this crop yet.
|
%p Nobody has harvested this crop yet.
|
||||||
- unless crop.harvests.empty?
|
- unless crop.harvests.empty?
|
||||||
%ul.list-group.list-group-flush
|
%ul.list-group.list-group-flush
|
||||||
- Rails.cache.fetch([crop, "recent_harvests", Time.zone.today]) do
|
- Harvest.where(crop: crop).includes(:owner).order(harvested_at: :desc).limit(3).each do |harvest|
|
||||||
- Harvest.where(crop: crop).includes(:owner).order(harvested_at: :desc).limit(3).each do |harvest|
|
%li.list-group-item
|
||||||
%li.list-group-item
|
= link_to harvest_path(harvest), class: 'card-link' do
|
||||||
= link_to harvest_path(harvest), class: 'card-link' do
|
= harvest_icon
|
||||||
= harvest_icon
|
#{harvest.owner} harvested #{display_quantity(harvest)}.
|
||||||
#{harvest.owner} harvested #{display_quantity(harvest)}.
|
.float-right= render 'members/location', member: harvest.owner
|
||||||
.float-right= render 'members/location', member: harvest.owner
|
.harvest-timeago
|
||||||
.harvest-timeago
|
%small #{standard_time_distance(harvest.harvested_at, Time.zone.now.to_date)}
|
||||||
%small #{standard_time_distance(harvest.harvested_at, Time.zone.now.to_date)}
|
|
||||||
%li.list-group-item= link_to "View all #{crop.name} harvests", crop_harvests_path(crop), class: 'card-link'
|
%li.list-group-item= link_to "View all #{crop.name} harvests", crop_harvests_path(crop), class: 'card-link'
|
||||||
- if crop.approved?
|
- if crop.approved?
|
||||||
- if current_member
|
- if current_member
|
||||||
|
|||||||
@@ -73,11 +73,10 @@
|
|||||||
= pie_chart crop_harvested_for_path(@crop, format: :json), legend: "bottom"
|
= pie_chart crop_harvested_for_path(@crop, format: :json), legend: "bottom"
|
||||||
|
|
||||||
- if @crop.varieties.any?
|
- if @crop.varieties.any?
|
||||||
- cache [@crop, 'varieties'] do
|
%section.varieties
|
||||||
%section.varieties
|
%h2 Varieties
|
||||||
%h2 Varieties
|
.index-cards
|
||||||
.index-cards
|
= render 'varieties', crop: @crop
|
||||||
= render 'varieties', crop: @crop
|
|
||||||
|
|
||||||
%section.crop-map
|
%section.crop-map
|
||||||
%h2
|
%h2
|
||||||
@@ -135,11 +134,9 @@
|
|||||||
= render 'harvests', crop: @crop
|
= render 'harvests', crop: @crop
|
||||||
= render 'find_seeds', crop: @crop
|
= render 'find_seeds', crop: @crop
|
||||||
|
|
||||||
- cache [@crop, 'openfarm_data'] do
|
= render 'openfarm_data', crop: @crop
|
||||||
= render 'openfarm_data', crop: @crop
|
|
||||||
|
|
||||||
- cache [@crop, 'nutritional_data'] do
|
= render 'nutritional_data', crop: @crop
|
||||||
= render 'nutritional_data', crop: @crop
|
|
||||||
|
|
||||||
= cute_icon
|
= cute_icon
|
||||||
.card
|
.card
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
- cache harvest do
|
%p
|
||||||
%p
|
%small
|
||||||
%small
|
= harvest.harvested_at
|
||||||
= harvest.harvested_at
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
- content_for :breadcrumbs do
|
- content_for :breadcrumbs do
|
||||||
- if @owner
|
- if @owner
|
||||||
%li.breadcrumb-item= link_to 'Harvests', harvests_path
|
%li.breadcrumb-item= link_to 'Harvests', harvests_path
|
||||||
%li.breadcrumb-item.active= link_to "#{@owner}'s harvests", member_harvests_path(@owner)
|
%li.breadcrumb-item.active= link_to "#{@owner}'s harvests", harvests_path(owner: @owner)
|
||||||
- else
|
- else
|
||||||
%li.breadcrumb-item.active= link_to "Harvests", harvests_path
|
%li.breadcrumb-item.active= link_to "Harvests", harvests_path
|
||||||
.row
|
.row
|
||||||
|
|||||||
@@ -21,14 +21,13 @@
|
|||||||
Please select a photo from your recent uploads.
|
Please select a photo from your recent uploads.
|
||||||
|
|
||||||
|
|
||||||
%p
|
- if @sets && !@sets.empty?
|
||||||
= bootstrap_form_tag(url: new_photo_path, method: :get, layout: :inline) do |f|
|
%p
|
||||||
- if @sets && !@sets.empty?
|
= bootstrap_form_tag(url: new_photo_path, method: :get, layout: :inline) do |f|
|
||||||
= f.select :set, options_for_select(@sets, @current_set), label: "Choose a photo album", include_blank: true
|
= f.select :set, options_for_select(@sets, @current_set), label: "Choose a photo album"
|
||||||
= f.text_field :tag, value: @current_tag, label: "or search by tag"
|
= hidden_field_tag :type, @type
|
||||||
= hidden_field_tag :type, @type
|
= hidden_field_tag :id, @id
|
||||||
= hidden_field_tag :id, @id
|
= f.submit "Search", class: "btn btn-success"
|
||||||
= f.submit "Search", class: "btn btn-success"
|
|
||||||
|
|
||||||
- if @sets && @current_set
|
- if @sets && @current_set
|
||||||
%h2= @sets.key(@current_set)
|
%h2= @sets.key(@current_set)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
- content_for :breadcrumbs do
|
- content_for :breadcrumbs do
|
||||||
- if @owner
|
- if @owner
|
||||||
%li.breadcrumb-item= link_to 'Plantings', plantings_path
|
%li.breadcrumb-item= link_to 'Plantings', plantings_path
|
||||||
%li.breadcrumb-item.active= link_to "#{@owner}'s plantings", member_plantings_path(@owner)
|
%li.breadcrumb-item.active= link_to "#{@owner}'s plantings", plantings_path(owner: @owner)
|
||||||
- else
|
- else
|
||||||
%li.breadcrumb-item.active= link_to 'Plantings', plantings_path
|
%li.breadcrumb-item.active= link_to 'Plantings', plantings_path
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
.form-group
|
.form-group
|
||||||
= f.label :crop_id, class: 'control-label col-md-2'
|
= f.label :crop_id, class: 'control-label col-md-2'
|
||||||
.col-md-8
|
.col-md-8
|
||||||
= select(:scientific_name, :crop_id, Crop.order(:name).pluck(:name, :id),
|
= collection_select(:scientific_name, :crop_id, Crop.all.order(:name), :id,
|
||||||
{ selected: @scientific_name.crop_id || @crop.id },
|
:name, { selected: @scientific_name.crop_id || @crop.id },
|
||||||
class: 'form-control')
|
class: 'form-control')
|
||||||
.form-group
|
.form-group
|
||||||
= f.label :name, class: 'control-label col-md-2'
|
= f.label :name, class: 'control-label col-md-2'
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
- content_for :breadcrumbs do
|
- content_for :breadcrumbs do
|
||||||
- if @owner
|
- if @owner
|
||||||
%li.breadcrumb-item= link_to 'Seeds', seeds_path
|
%li.breadcrumb-item= link_to 'Seeds', seeds_path
|
||||||
%li.breadcrumb-item.active= link_to "#{@owner}'s seeds", member_seeds_path(@owner)
|
%li.breadcrumb-item.active= link_to "#{@owner}'s seeds", seeds_path(owner: @owner)
|
||||||
- else
|
- else
|
||||||
%li.breadcrumb-item.active= link_to 'Seeds', seeds_path
|
%li.breadcrumb-item.active= link_to 'Seeds', seeds_path
|
||||||
|
|
||||||
|
|||||||
@@ -62,9 +62,9 @@ module Growstuff
|
|||||||
|
|
||||||
# Growstuff-specific configuration variables
|
# Growstuff-specific configuration variables
|
||||||
config.currency = 'AUD'
|
config.currency = 'AUD'
|
||||||
config.bot_email = ENV.fetch('GROWSTUFF_EMAIL', nil)
|
config.bot_email = Rails.configuration.x.email[:from]
|
||||||
config.user_agent = 'Growstuff'
|
config.user_agent = 'Growstuff'
|
||||||
config.user_agent_email = "info@growstuff.org"
|
config.user_agent_email = Rails.configuration.x.email[:from]
|
||||||
|
|
||||||
Gibbon::API.api_key = ENV['GROWSTUFF_MAILCHIMP_APIKEY'] || 'notarealkey'
|
Gibbon::API.api_key = ENV['GROWSTUFF_MAILCHIMP_APIKEY'] || 'notarealkey'
|
||||||
# API key can't be blank or tests fail
|
# API key can't be blank or tests fail
|
||||||
@@ -73,8 +73,6 @@ module Growstuff
|
|||||||
config.newsletter_list_id = ENV.fetch('GROWSTUFF_MAILCHIMP_NEWSLETTER_ID', nil)
|
config.newsletter_list_id = ENV.fetch('GROWSTUFF_MAILCHIMP_NEWSLETTER_ID', nil)
|
||||||
|
|
||||||
# config.active_record.raise_in_transactional_callbacks = true
|
# config.active_record.raise_in_transactional_callbacks = true
|
||||||
config.middleware.insert_before 0, Rack::Attack
|
|
||||||
|
|
||||||
config.middleware.insert_before 0, Rack::Cors do
|
config.middleware.insert_before 0, Rack::Cors do
|
||||||
allow do
|
allow do
|
||||||
origins '*'
|
origins '*'
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ Devise.setup do |config|
|
|||||||
# ==> Mailer Configuration
|
# ==> Mailer Configuration
|
||||||
# Configure the e-mail address which will be shown in Devise::Mailer,
|
# Configure the e-mail address which will be shown in Devise::Mailer,
|
||||||
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
|
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
|
||||||
config.mailer_sender = "Growstuff <#{ENV.fetch('GROWSTUFF_EMAIL', nil)}>"
|
config.mailer_sender = "Growstuff <#{Rails.configuration.x.email[:from]}>"
|
||||||
|
|
||||||
config.secret_key = ENV.fetch('RAILS_SECRET_TOKEN', nil)
|
config.secret_key = ENV.fetch('RAILS_SECRET_TOKEN', nil)
|
||||||
|
|
||||||
|
|||||||
9
config/initializers/email.rb
Normal file
9
config/initializers/email.rb
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
module Growstuff
|
||||||
|
class Application < Rails::Application
|
||||||
|
config.x.email = {
|
||||||
|
from: ENV.fetch('GROWSTUFF_EMAIL', 'info@growstuff.org'),
|
||||||
|
admin: ENV.fetch('GROWSTUFF_ADMIN_EMAIL', 'sysadmin@growstuff.org'),
|
||||||
|
support: ENV.fetch('GROWSTUFF_SUPPORT_EMAIL', 'info@growstuff.org')
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
class Rack::Attack
|
|
||||||
### Throttle Config ###
|
|
||||||
|
|
||||||
if Rails.env.production?
|
|
||||||
# Throttle requests to /plantings, /harvests, and /members to 10 per minute per IP
|
|
||||||
# Includes API routes
|
|
||||||
throttle('req/ip/restricted_routes', limit: 20, period: 1.minute) do |req|
|
|
||||||
if req.path =~ %r{^/(plantings|harvests|members)(/|$)} || req.path =~ %r{^/api/v1/(plantings|harvests|members)(/|$)}
|
|
||||||
req.ip
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
### Fail2Ban Config ###
|
|
||||||
|
|
||||||
# Block IPs that make too many requests to suspicious paths
|
|
||||||
# After 5 "bad" requests in 10 minutes, block the IP for 1 hour
|
|
||||||
blocklist('fail2ban/pentesters') do |req|
|
|
||||||
Fail2Ban.filter("pentesters-#{req.ip}", maxretry: 5, findtime: 10.minutes, bantime: 1.hour) do
|
|
||||||
# The count for the IP is incremented if the return value is truthy.
|
|
||||||
req.path.include?('wp-admin') ||
|
|
||||||
req.path.include?('wp-login') ||
|
|
||||||
req.path.include?('cgi-bin') ||
|
|
||||||
req.path.end_with?('.php', '.asp', '.aspx', '.jsp', '.exe', '.env', '.git')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
### Custom Response Headers ###
|
|
||||||
|
|
||||||
# Add Retry-After header to throttled responses
|
|
||||||
self.throttled_response_retry_after_header = true
|
|
||||||
end
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
namespace :members do
|
|
||||||
desc "Remove inactive members with no activity and last login > 24 months ago"
|
|
||||||
# usage: rake members:cleanup_inactive
|
|
||||||
# usage: DRY_RUN=true rake members:cleanup_inactive
|
|
||||||
task cleanup_inactive: :environment do
|
|
||||||
limit_date = 3.years.ago
|
|
||||||
dry_run = ENV.fetch('DRY_RUN', 'false') == 'true'
|
|
||||||
|
|
||||||
inactive_members = Member.where("last_sign_in_at < ? OR (last_sign_in_at IS NULL AND created_at < ?)", limit_date, limit_date)
|
|
||||||
|
|
||||||
count = 0
|
|
||||||
inactive_members.find_each do |member|
|
|
||||||
# Check for activity using the model method
|
|
||||||
unless member.has_activity?
|
|
||||||
if dry_run
|
|
||||||
puts "[DRY RUN] Would delete inactive member: #{member.login_name} (ID: #{member.id}, Last login: #{member.last_sign_in_at || 'Never'}, Created: #{member.created_at})"
|
|
||||||
else
|
|
||||||
puts "Deleting inactive member: #{member.login_name} (ID: #{member.id}, Last login: #{member.last_sign_in_at || 'Never'}, Created: #{member.created_at})"
|
|
||||||
member.destroy
|
|
||||||
end
|
|
||||||
count += 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if dry_run
|
|
||||||
puts "Total inactive members that would be deleted: #{count}"
|
|
||||||
else
|
|
||||||
puts "Total inactive members deleted: #{count}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -123,27 +123,13 @@ Disallow: /
|
|||||||
User-agent: WebReaper
|
User-agent: WebReaper
|
||||||
Disallow: /
|
Disallow: /
|
||||||
|
|
||||||
# Semrush seem to crawl everything.
|
# Per their statement, semrushbot respects crawl-delay directives
|
||||||
|
# We want them to overall stay within reasonable request rates to
|
||||||
|
# the backend (20 rps); keeping in mind that the crawl-delay will
|
||||||
|
# be applied by site and not globally by the bot, 5 seconds seem
|
||||||
|
# like a reasonable approximation
|
||||||
User-agent: SemrushBot
|
User-agent: SemrushBot
|
||||||
Disallow: /
|
Crawl-delay: 5
|
||||||
|
|
||||||
User-agent: SiteAuditBot
|
|
||||||
Disallow: /
|
|
||||||
|
|
||||||
User-agent: SemrushBot-BA
|
|
||||||
Disallow: /
|
|
||||||
|
|
||||||
User-agent: SemrushBot-SI
|
|
||||||
Disallow: /
|
|
||||||
|
|
||||||
User-agent: SemrushBot-SWA
|
|
||||||
Disallow: /
|
|
||||||
|
|
||||||
User-agent: SplitSignalBot
|
|
||||||
Disallow: /
|
|
||||||
|
|
||||||
User-agent: SemrushBot-OCOB
|
|
||||||
Disallow: /
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Friendly, low-speed bots are welcome viewing pages, but not
|
# Friendly, low-speed bots are welcome viewing pages, but not
|
||||||
|
|||||||
@@ -7,42 +7,21 @@ describe Charts::CropsController do
|
|||||||
let(:crop) { create(:crop) }
|
let(:crop) { create(:crop) }
|
||||||
|
|
||||||
describe 'sunniness' do
|
describe 'sunniness' do
|
||||||
it "returns a successful response" do
|
before { get :sunniness, params: { crop_slug: crop.to_param } }
|
||||||
get :sunniness, params: { crop_slug: crop.to_param }
|
|
||||||
expect(response).to be_successful
|
|
||||||
end
|
|
||||||
|
|
||||||
it "caches the result" do
|
it { expect(response).to be_successful }
|
||||||
cache_key = "#{crop.cache_key_with_version}/sunniness"
|
|
||||||
expect(Rails.cache).to receive(:fetch).with(cache_key, expires_in: 1.day).and_call_original
|
|
||||||
get :sunniness, params: { crop_slug: crop.to_param }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'planted_from' do
|
describe 'planted_from' do
|
||||||
it "returns a successful response" do
|
before { get :planted_from, params: { crop_slug: crop.to_param } }
|
||||||
get :planted_from, params: { crop_slug: crop.to_param }
|
|
||||||
expect(response).to be_successful
|
|
||||||
end
|
|
||||||
|
|
||||||
it "caches the result" do
|
it { expect(response).to be_successful }
|
||||||
cache_key = "#{crop.cache_key_with_version}/planted_from"
|
|
||||||
expect(Rails.cache).to receive(:fetch).with(cache_key, expires_in: 1.day).and_call_original
|
|
||||||
get :planted_from, params: { crop_slug: crop.to_param }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'harvested_for' do
|
describe 'harvested_for' do
|
||||||
it "returns a successful response" do
|
before { get :harvested_for, params: { crop_slug: crop.to_param } }
|
||||||
get :harvested_for, params: { crop_slug: crop.to_param }
|
|
||||||
expect(response).to be_successful
|
|
||||||
end
|
|
||||||
|
|
||||||
it "caches the result" do
|
it { expect(response).to be_successful }
|
||||||
cache_key = "#{crop.cache_key_with_version}/harvested_for"
|
|
||||||
expect(Rails.cache).to receive(:fetch).with(cache_key, expires_in: 1.day).and_call_original
|
|
||||||
get :harvested_for, params: { crop_slug: crop.to_param }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ describe PhotosController, :search do
|
|||||||
sign_in member
|
sign_in member
|
||||||
member.stub(:flickr_photos) { [[], 0] }
|
member.stub(:flickr_photos) { [[], 0] }
|
||||||
member.stub(:flickr_sets) { { "foo" => "bar" } }
|
member.stub(:flickr_sets) { { "foo" => "bar" } }
|
||||||
member.stub(:flickr_auth_valid?) { true }
|
|
||||||
controller.stub(:current_member) { member }
|
controller.stub(:current_member) { member }
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -86,16 +85,6 @@ describe PhotosController, :search do
|
|||||||
it { expect(assigns(:item)).to eq garden }
|
it { expect(assigns(:item)).to eq garden }
|
||||||
it { expect(flash[:alert]).not_to be_present }
|
it { expect(flash[:alert]).not_to be_present }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "filtering by tag" do
|
|
||||||
let(:tag) { "tomato" }
|
|
||||||
|
|
||||||
it "passes the tag to flickr_photos" do
|
|
||||||
expect(member).to receive(:flickr_photos).with(anything, nil, tag).and_return([[], 0])
|
|
||||||
get :new, params: { type: "planting", id: planting.id, tag: tag }
|
|
||||||
expect(assigns(:current_tag)).to eq tag
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "POST create" do
|
describe "POST create" do
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
require 'rake'
|
|
||||||
|
|
||||||
describe 'members:cleanup_inactive' do
|
|
||||||
before :all do
|
|
||||||
Rails.application.load_tasks
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:cleanup_task) { Rake::Task['members:cleanup_inactive'] }
|
|
||||||
|
|
||||||
before do
|
|
||||||
cleanup_task.reenable
|
|
||||||
end
|
|
||||||
|
|
||||||
it "deletes inactive members with no gardens and no other activity" do
|
|
||||||
inactive_no_activity = create(:member, last_sign_in_at: 25.months.ago)
|
|
||||||
|
|
||||||
# We must explicitly remove the default garden to test the "no gardens" condition
|
|
||||||
inactive_no_activity.gardens.destroy_all
|
|
||||||
expect(inactive_no_activity.gardens.count).to eq(0)
|
|
||||||
|
|
||||||
cleanup_task.invoke
|
|
||||||
|
|
||||||
expect(Member.exists?(inactive_no_activity.id)).to be_falsey
|
|
||||||
end
|
|
||||||
|
|
||||||
it "does not delete inactive members with a garden (even if empty)" do
|
|
||||||
inactive_with_garden = create(:member, last_sign_in_at: 25.months.ago)
|
|
||||||
# They have 1 default garden
|
|
||||||
expect(inactive_with_garden.gardens.count).to eq(1)
|
|
||||||
|
|
||||||
cleanup_task.invoke
|
|
||||||
|
|
||||||
expect(Member.exists?(inactive_with_garden.id)).to be_truthy
|
|
||||||
end
|
|
||||||
|
|
||||||
it "does not delete members with recent login" do
|
|
||||||
recent_member = create(:member, last_sign_in_at: 1.month.ago)
|
|
||||||
recent_member.gardens.destroy_all
|
|
||||||
|
|
||||||
cleanup_task.invoke
|
|
||||||
|
|
||||||
expect(Member.exists?(recent_member.id)).to be_truthy
|
|
||||||
end
|
|
||||||
|
|
||||||
it "does not delete inactive members with activity (posts)" do
|
|
||||||
inactive_with_post = create(:member, last_sign_in_at: 25.months.ago)
|
|
||||||
inactive_with_post.gardens.destroy_all
|
|
||||||
create(:post, author: inactive_with_post)
|
|
||||||
|
|
||||||
cleanup_task.invoke
|
|
||||||
|
|
||||||
expect(Member.exists?(inactive_with_post.id)).to be_truthy
|
|
||||||
end
|
|
||||||
|
|
||||||
it "honors DRY_RUN environment variable" do
|
|
||||||
inactive_no_activity = create(:member, last_sign_in_at: 25.months.ago)
|
|
||||||
inactive_no_activity.gardens.destroy_all
|
|
||||||
|
|
||||||
ENV['DRY_RUN'] = 'true'
|
|
||||||
cleanup_task.invoke
|
|
||||||
ENV['DRY_RUN'] = nil
|
|
||||||
|
|
||||||
expect(Member.exists?(inactive_no_activity.id)).to be_truthy
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Reference in New Issue
Block a user