Skip to content

Commit

Permalink
Merge branch 'staging' into french-translation
Browse files Browse the repository at this point in the history
  • Loading branch information
RickCarlino committed May 6, 2019
2 parents bbdf511 + 4744300 commit a1df77c
Show file tree
Hide file tree
Showing 96 changed files with 2,819 additions and 473 deletions.
14 changes: 7 additions & 7 deletions Gemfile.lock
Expand Up @@ -59,7 +59,7 @@ GEM
arel (9.0.0)
bcrypt (3.1.12)
builder (3.2.3)
bunny (2.14.1)
bunny (2.14.2)
amq-protocol (~> 2.3, >= 2.3.0)
case_transform (0.2)
activesupport
Expand Down Expand Up @@ -147,7 +147,7 @@ GEM
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (~> 0.7)
hashdiff (0.3.8)
hashdiff (0.3.9)
hashie (3.6.0)
httpclient (2.8.3)
i18n (1.6.0)
Expand Down Expand Up @@ -184,10 +184,10 @@ GEM
mutations (0.9.0)
activesupport
nio4r (2.3.1)
nokogiri (1.10.2)
nokogiri (1.10.3)
mini_portile2 (~> 2.4.0)
orm_adapter (0.5.0)
os (1.0.0)
os (1.0.1)
paperclip (6.1.0)
activemodel (>= 4.2.0)
activesupport (>= 4.2.0)
Expand All @@ -212,7 +212,7 @@ GEM
hashie (~> 3.6)
multi_json (~> 1.13.1)
rack (2.0.7)
rack-attack (5.4.2)
rack-attack (6.0.0)
rack (>= 1.0, < 3)
rack-cors (1.0.3)
rack-test (1.1.0)
Expand Down Expand Up @@ -271,7 +271,7 @@ GEM
rspec-mocks (~> 3.8.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.2)
rspec-expectations (3.8.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
Expand All @@ -292,7 +292,7 @@ GEM
activerecord (>= 4.0.0)
railties (>= 4.0.0)
secure_headers (6.1.0)
selenium-webdriver (3.141.5926)
selenium-webdriver (3.142.0)
childprocess (>= 0.5, < 2.0)
rubyzip (~> 1.2, >= 1.2.2)
signet (0.11.0)
Expand Down
7 changes: 5 additions & 2 deletions app/controllers/api/devices_controller.rb
Expand Up @@ -35,8 +35,11 @@ def sync
end

def seed
Devices::CreateSeedData.delay.run!(params.as_json, device: current_device)
render json: { done: "Loading resources now." }
mutate Devices::CreateSeedData.run params.as_json, device: current_device
end

def reset
mutate Devices::Reset.run(params.as_json, device: current_device)
end

private
Expand Down
13 changes: 7 additions & 6 deletions app/models/alert.rb
@@ -1,12 +1,13 @@
class Alert < ApplicationRecord
belongs_to :device
PROBLEM_TAGS = [
SEED_DATA = "api.seed_data.missing",
TOUR = "api.tour.not_taken",
USER = "api.user.not_welcomed",
DOCUMENTATION = "api.documentation.unread",
BULLETIN = "api.bulletin.unread"
DEFAULTS = [
SEED_DATA = { problem_tag: "api.seed_data.missing", priority: 400 },
DOCUMENTATION = { problem_tag: "api.documentation.unread", priority: 300 },
TOUR = { problem_tag: "api.tour.not_taken", priority: 200 },
USER = { problem_tag: "api.user.not_welcomed", priority: 100 },
]

PROBLEM_TAGS = DEFAULTS.map { |x| x.fetch(:problem_tag) }

validates_inclusion_of :problem_tag, in: PROBLEM_TAGS
end
6 changes: 3 additions & 3 deletions app/models/celery_script_settings_bag.rb
Expand Up @@ -20,7 +20,7 @@ def self.exists?(id)
"BoxLed3" => BoxLed,
"BoxLed4" => BoxLed }
ALLOWED_AXIS = %w(x y z all)
ALLOWED_CHAGES = %w(add remove update)
ALLOWED_CHANGES = %w(add remove update)
ALLOWED_CHANNEL_NAMES = %w(ticker toast email espeak)
ALLOWED_LHS_STRINGS = [*(0..69)].map { |x| "pin#{x}" }.concat(%w(x y z))
ALLOWED_LHS_TYPES = [String, :named_pin]
Expand Down Expand Up @@ -94,7 +94,7 @@ def self.exists?(id)
ALLOWED_PIN_MODES: [ALLOWED_PIN_MODES, BAD_ALLOWED_PIN_MODES],
AllowedPinTypes: [ALLOWED_PIN_TYPES, BAD_PIN_TYPE],
Color: [Sequence::COLORS, MISC_ENUM_ERR],
DataChangeType: [ALLOWED_CHAGES, MISC_ENUM_ERR],
DataChangeType: [ALLOWED_CHANGES, MISC_ENUM_ERR],
LegalSequenceKind: [ALLOWED_RPC_NODES.sort, MISC_ENUM_ERR],
lhs: [ALLOWED_LHS_STRINGS, BAD_LHS],
PlantStage: [PLANT_STAGES, MISC_ENUM_ERR],
Expand Down Expand Up @@ -211,7 +211,7 @@ def self.v(symbol)
blk: ->(node) do
x = [ALLOWED_LHS_STRINGS, node, BAD_LHS]
# This would never have happened if we hadn't allowed
# heterogenus args :(
# heterogenous args :(
manual_enum(*x) unless node.is_a?(CeleryScript::AstNode)
end,
},
Expand Down
60 changes: 32 additions & 28 deletions app/models/device.rb
Expand Up @@ -12,39 +12,35 @@ class Device < ApplicationRecord
"Resuming log storage."
CACHE_KEY = "devices.%s"

has_many :alerts, dependent: :destroy
has_many :farmware_envs, dependent: :destroy
has_many :farm_events, dependent: :destroy
has_many :farmware_installations, dependent: :destroy
has_many :images, dependent: :destroy
has_many :logs, dependent: :destroy
has_many :peripherals, dependent: :destroy
has_many :pin_bindings, dependent: :destroy
has_many :plant_templates, dependent: :destroy
has_many :points, dependent: :destroy
has_many :regimens, dependent: :destroy
has_many :saved_gardens, dependent: :destroy
has_many :sensor_readings, dependent: :destroy
has_many :sensors, dependent: :destroy
has_many :sequences, dependent: :destroy
has_many :token_issuances, dependent: :destroy
has_many :tools, dependent: :destroy
has_many :webcam_feeds, dependent: :destroy
has_many :diagnostic_dumps, dependent: :destroy
has_many :fragments, dependent: :destroy
has_one :fbos_config, dependent: :destroy
PLURAL_RESOURCES = %i(alerts farmware_envs farm_events farmware_installations
images logs peripherals pin_bindings plant_templates
points regimens saved_gardens sensor_readings sensors
sequences token_issuances tools webcam_feeds
diagnostic_dumps fragments)

PLURAL_RESOURCES.map { |resources| has_many resources, dependent: :destroy }

SINGULAR_RESOURCES = {
fbos_config: FbosConfig,
firmware_config: FirmwareConfig,
web_app_config: WebAppConfig,
}

SINGULAR_RESOURCES.map do |(name, klass)|
has_one name, dependent: :destroy
define_method(name) { super() || klass.create!(device: self) }
end

has_many :in_use_tools
has_many :in_use_points
has_many :users

validates_presence_of :name
validates :timezone,
inclusion: { in: TIMEZONES, message: BAD_TZ, allow_nil: true }
[FbosConfig, FirmwareConfig, WebAppConfig].map do |klass|
name = klass.table_name.singularize.to_sym
has_one name, dependent: :destroy
define_method(name) { super() || klass.create!(device: self) }
end
validates :timezone, inclusion: {
in: TIMEZONES,
message: BAD_TZ,
allow_nil: true,
}

# Give the user back the amount of logs they are allowed to view.
def limited_log_list
Expand Down Expand Up @@ -88,6 +84,14 @@ def plants
points.where(pointer_type: "Plant")
end

def tool_slots
points.where(pointer_type: "ToolSlot")
end

def generic_pointers
points.where(pointer_type: "GenericPointer")
end

TIMEOUT = 150.seconds

# Like Device.find, but with 150 seconds of caching to avoid DB calls.
Expand Down
4 changes: 2 additions & 2 deletions app/models/farmware_env.rb
Expand Up @@ -7,10 +7,10 @@ class FarmwareEnv < ApplicationRecord
PRIMITIVES_ONLY = "`value` must be a string, number or boolean"

def primitives_only
errors.add(:value, PRIMITIVES_ONLY) unless is_primitve
errors.add(:value, PRIMITIVES_ONLY) unless is_primitive
end

def is_primitve
def is_primitive
[String, Integer, Float, TrueClass, FalseClass].include?(value.class)
end
end
7 changes: 7 additions & 0 deletions app/models/fbos_config.rb
Expand Up @@ -5,6 +5,13 @@ class MissingSerial < StandardError; end
belongs_to :device
after_save :maybe_sync_nerves, on: [:create, :update]

FIRMWARE_HARDWARE = [
ARDUINO = "arduino",
FARMDUINO = "farmduino",
FARMDUINO_K14 = "farmduino_k14",
EXPRESS_K10 = "express_k10",
]

NERVES_FIELD = "update_channel"

def push_changes_to_nerves_hub(serial_number, channel)
Expand Down
1 change: 1 addition & 0 deletions app/models/log_delivery_stuff.rb
Expand Up @@ -3,6 +3,7 @@
# Also helps group "fast" messages into a digest.
module LogDeliveryStuff
class RateLimitError < StandardError; end

module ClassMethods
# If this method grows, create a mutation.
def deliver(device, log)
Expand Down
9 changes: 5 additions & 4 deletions app/mutations/alerts/create.rb
Expand Up @@ -5,12 +5,13 @@ class Create < Mutations::Command
string :problem_tag, in: Alert::PROBLEM_TAGS
end

optional { string :slug }
optional do
string :slug
integer :priority, default: 99
end

def execute
Alert.create!(device: device,
problem_tag: problem_tag,
slug: slug || SecureRandom.uuid)
Alert.create!({ slug: slug || SecureRandom.uuid }.merge(inputs))
end
end
end
18 changes: 7 additions & 11 deletions app/mutations/devices/create.rb
Expand Up @@ -12,15 +12,11 @@ class Create < Mutations::Command

def execute
merge_default_values
device = Device.create!({name: "Farmbot"}.merge(inputs.except(:user)))
Alerts::Create.run!(device: device,
problem_tag: Alert::SEED_DATA)
Alerts::Create.run!(device: device,
problem_tag: Alert::TOUR)
Alerts::Create.run!(device: device,
problem_tag: Alert::USER)
Alerts::Create.run!(device: device,
problem_tag: Alert::DOCUMENTATION)
device = Device.create!({ name: "Farmbot" }.merge(inputs.except(:user)))
Alerts::Create.run!(Alert::SEED_DATA.merge(device: device))
Alerts::Create.run!(Alert::TOUR.merge(device: device))
Alerts::Create.run!(Alert::USER.merge(device: device))
Alerts::Create.run!(Alert::DOCUMENTATION.merge(device: device))

ActiveRecord::Base.transaction do
# TODO: This is a really, really, really old
Expand All @@ -35,10 +31,10 @@ def execute
device
end

private
private

def merge_default_values
inputs[:name] ||= "Farmbot"
inputs[:name] ||= "Farmbot"
end
end
end
12 changes: 6 additions & 6 deletions app/mutations/devices/create_seed_data.rb
Expand Up @@ -7,29 +7,29 @@ class CreateSeedData < Mutations::Command
"genesis_1.2" => Devices::Seeders::GenesisOneTwo,
"genesis_1.3" => Devices::Seeders::GenesisOneThree,
"genesis_1.4" => Devices::Seeders::GenesisOneFour,

"xl_1.4" => Devices::Seeders::XlOneFour,
"genesis_xl_1.4" => Devices::Seeders::XlOneFour,

"none" => Devices::Seeders::None,
}

COMMANDS = Devices::Seeders::Abstract.instance_methods(false).sort

required do
model :device
string :product_line, in: PRODUCT_LINES.keys
end

def execute
run_seeds!
self.delay.run_seeds!
{ done: "Loading resources now." }
end

def seeder
@seeder ||= PRODUCT_LINES.fetch(product_line).new(device)
end

def run_seeds!
COMMANDS.map { |cmd| seeder.send(cmd) }
seeder.class::COMMAND_ORDER.map do |cmd|
seeder.send(cmd)
end
end
end
end
35 changes: 35 additions & 0 deletions app/mutations/devices/reset.rb
@@ -0,0 +1,35 @@
module Devices
class Reset < Mutations::Command
include Users::PasswordHelpers

required do
model :device
string :password
end

def validate
confirm_password(user, password)
end

def execute
self.delay.run_it
{ ok: "OK" }
end

private

def run_it
Device::SINGULAR_RESOURCES.keys.map do |resource|
device.send(resource).destroy!
end

Device::PLURAL_RESOURCES.map do |resources|
device.send(resources).destroy_all
end
end

def user
@user ||= User.find_by!(device: device)
end
end
end

0 comments on commit a1df77c

Please sign in to comment.