Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 5e5dd5e

Browse files
authored
Fix broken icons (#985)
* Quick fix for production 500 errors * Update Ruby version * Fix SVG icons
1 parent bb593eb commit 5e5dd5e

File tree

12 files changed

+55
-40
lines changed

12 files changed

+55
-40
lines changed

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.3
1+
2.6.1

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Image name: openfarm-webapp
33
#
44

5-
FROM ruby:2.3.3
5+
FROM ruby:2.6.1
66
MAINTAINER https://github.com/FarmBot/OpenFarm
77

88
ENV PHANTOM_JS_VERSION 1.9.8

app/assets/stylesheets/styles/components/crop_searches/_crop_searches.scss

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
margin: 1em 0;
66
}
77

8-
.crop-results-container {
9-
}
8+
.crop-results-container {}
109

1110
.guide-results-container {
1211
background-color: $openfarm-blue-grey;
@@ -16,6 +15,11 @@
1615
}
1716
}
1817

18+
div.crop-icon-wrapper svg {
19+
width: 26px;
20+
height: 26px;
21+
}
22+
1923
/*@import "crop_searches/_crop_results.css.scss";
2024
@import "crop_searches/_crop_result.css.scss";
2125
@import "crop_searches/_guide_results.css.scss";

app/helpers/application_helper.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module ApplicationHelper
2+
DEFAULT_ICON_PATH = Rails.root.join("app", "assets", "images", "generic-plant.svg")
3+
DEFAULT_ICON = File.read(DEFAULT_ICON_PATH)
4+
25
def load_generic_plant_icon
3-
file_path = Rails.root.join("app", "assets", "images", "generic-plant.svg")
4-
h File.read(file_path)
6+
raw(DEFAULT_ICON)
57
end
68
end

app/models/guide_search.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ def with_user(user)
3737
return self unless user
3838

3939
@order = {
40-
'compatibilities.score' => {
41-
order: 'desc',
42-
nested_filter: {
43-
term: { 'compatibilities.user_id' => user.id }
44-
}
45-
}
40+
# THIS IS CRASHING ON PRODUCTION AND I DONT
41+
# KNOW WHY :( - RC 17 APR 19
42+
#
43+
# 'compatibilities.score' => {
44+
# order: 'desc',
45+
# nested_filter: {
46+
# term: { 'compatibilities.user_id' => user.id }
47+
# }
48+
# }
4649
}
4750

4851
self

app/mutations/crops/create_crop.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ class CreateCrop < Mutations::Command
1313
optional do
1414
array :common_names
1515
string :binomial_name
16-
string :svg_icon
16+
# Temporarily disabled for security reasons (XSS attack vector)
17+
#
18+
# Fix this by:
19+
# * adding a CSP that disallows the use of arbitrary <script/> tags
20+
# * Removing all use of inline <script/> tags
21+
#
22+
# string :svg_icon
1723
string :description
1824
string :sun_requirements
1925
string :sowing_method

app/views/crops/_crop_form.html.erb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,9 @@
225225
<label for="crop[icon]" class="right">Manage icon</label>
226226
</div>
227227
<div class="columns small-8 medium-8">
228-
<img
229-
width="64"
230-
height="64"
231-
ng-src="data:image/svg+xml;utf8,{{ crop.svg_icon }}">
232-
</img>
228+
<div class="crop-icon-wrapper">
229+
<%= raw(@crop.svg_icon ? @crop.svg_icon : load_generic_plant_icon) %>
230+
</div>
233231
<svg-button on-change="addSvg($svg)">
234232
</svg-button>
235233
</div>

app/views/crops/show.html.erb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@
5050
<td><%= render partial: '/crops/exists_or_edit', locals: {obj: @crop.description} %></td>
5151
</tr>
5252
<tr>
53-
<td><%= I18n.t('crops.companions') %></td>
53+
<td>
54+
<%= I18n.t('crops.companions') %>
55+
</td>
5456
<td>
5557
<% @crop.companions.all.each do |comp| %>
5658
<%= link_to comp do %>
57-
<img
58-
width="24"
59-
height="24"
60-
ng-src="data:image/svg+xml;utf8,<%= comp.svg_icon ? comp.svg_icon : load_generic_plant_icon %>">
61-
</img>
59+
<div class="crop-icon-wrapper">
60+
<%= raw(comp.svg_icon ? comp.svg_icon : load_generic_plant_icon) %>
61+
</div>
6262
<%= comp.name %>
6363
<% end %>
6464
<% end %></td>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
Rails.application.config.content_security_policy do |policy|
3+
# policy.default_src :self, :https
4+
# policy.font_src :self, :https, :data
5+
# policy.img_src :self, :https, :data
6+
# policy.object_src :none
7+
8+
# WE SHOULD ENABLE THIS ONE - RC 17 APR 19
9+
# policy.script_src :self, "http://www.google-analytics.com/analytics.js"
10+
11+
# policy.style_src :self, :https, :unsafe_inline
12+
# policy.report_uri "/csp-violation-report-endpoint"
13+
end

scripts/bootstrap.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ echo "--- INSTALLING RVM ---"
1818

1919
gpg --keyserver hkp://pool.sks-keyservers.net:80 --recv-keys D39DC0E3
2020

21-
curl -sSL https://get.rvm.io | bash -s stable --quiet-curl --ruby=2.3.3
21+
curl -sSL https://get.rvm.io | bash -s stable --quiet-curl --ruby=2.6.1
2222

23-
echo "--- INSTALLING RUBY 2.3.3 ---"
23+
echo "--- INSTALLING RUBY 2.6.1 ---"
2424

2525
source /home/vagrant/.rvm/scripts/rvm
2626

2727
rvm reload
28-
rvm --default use 2.3.3
28+
rvm --default use 2.6.1
2929

3030
echo "--- INSTALLING ELASTICSEARCH ---"
3131

0 commit comments

Comments
 (0)