[UNSTABLE] Revert public sequence stuff for now
parent
ed440585bd
commit
80a502a7c8
|
@ -1,12 +1,5 @@
|
|||
module Api
|
||||
class SequencesController < Api::AbstractController
|
||||
PUBLIC_SEQUENCES = Sequence
|
||||
.with_usage_reports
|
||||
.where(is_public: true)
|
||||
SERIALIZED_PUBLIC_SEQUENCES = PUBLIC_SEQUENCES.to_a.map do |s|
|
||||
CeleryScript::FetchCelery.run!(sequence: s)
|
||||
end
|
||||
|
||||
before_action :clean_expired_farm_events, only: [:destroy]
|
||||
|
||||
def index
|
||||
|
@ -16,9 +9,8 @@ module Api
|
|||
.concat(PUBLIC_SEQUENCES)
|
||||
end
|
||||
|
||||
def show # TODO:
|
||||
s = sequences.or(PUBLIC_SEQUENCES).find(params[:id])
|
||||
render json: CeleryScript::FetchCelery.run!(sequence: s)
|
||||
def show
|
||||
render json: CeleryScript::FetchCelery.run!(sequence: sequence)
|
||||
end
|
||||
|
||||
def create
|
||||
|
|
|
@ -92,8 +92,7 @@ module CeleryScript
|
|||
updated_at: sequence.updated_at,
|
||||
args: Sequence::DEFAULT_ARGS,
|
||||
color: sequence.color,
|
||||
name: sequence.name,
|
||||
public: (sequence.is_public || false),
|
||||
name: sequence.name
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -10,16 +10,15 @@ module CeleryScriptSettingsBag
|
|||
PLANT_STAGES = %w(planned planted harvested)
|
||||
ALLOWED_PIN_MODES = [DIGITAL = 0, ANALOG = 1]
|
||||
ALLOWED_PIN_TYPES = [Peripheral, Sensor].map(&:name)
|
||||
RPCS = %w(_if calibrate change_ownership check_updates
|
||||
config_update dump_info emergency_lock
|
||||
emergency_unlock execute execute_script
|
||||
factory_reset find_home home install_farmware
|
||||
install_first_party_farmware move_absolute
|
||||
move_relative power_off read_pin read_status
|
||||
reboot register_gpio remove_farmware send_message
|
||||
set_servo_angle set_user_env sync take_photo
|
||||
toggle_pin unregister_gpio update_farmware wait
|
||||
write_pin zero)
|
||||
ALLOWED_RPC_NODES = %w(home emergency_lock emergency_unlock read_status
|
||||
sync check_updates power_off reboot toggle_pin
|
||||
config_update calibrate execute move_absolute
|
||||
move_relative write_pin read_pin send_message
|
||||
factory_reset execute_script set_user_env wait
|
||||
install_farmware update_farmware take_photo zero
|
||||
install_first_party_farmware remove_farmware
|
||||
find_home register_gpio unregister_gpio
|
||||
set_servo_angle change_ownership dump_info)
|
||||
ALLOWED_PACKAGES = %w(farmbot_os arduino_firmware)
|
||||
ALLOWED_CHAGES = %w(add remove update)
|
||||
RESOURCE_NAME = %w(images plants regimens peripherals
|
||||
|
@ -33,6 +32,9 @@ module CeleryScriptSettingsBag
|
|||
ALLOWED_AXIS = %w(x y z all)
|
||||
ALLOWED_LHS_TYPES = [String, :named_pin]
|
||||
ALLOWED_LHS_STRINGS = [*(0..69)].map{|x| "pin#{x}"}.concat(%w(x y z))
|
||||
STEPS = %w(_if execute execute_script find_home move_absolute
|
||||
move_relative read_pin send_message take_photo wait
|
||||
write_pin )
|
||||
BAD_ALLOWED_PIN_MODES = '"%s" is not a valid pin_mode. Allowed values: %s'
|
||||
BAD_LHS = 'Can not put "%s" into a left hand side (LHS) '\
|
||||
'argument. Allowed values: %s'
|
||||
|
@ -190,7 +192,7 @@ module CeleryScriptSettingsBag
|
|||
.node(:send_message, [:message, :message_type], [:channel])
|
||||
.node(:execute, [:sequence_id])
|
||||
.node(:_if, [:lhs, :op, :rhs, :_then, :_else], [:pair])
|
||||
.node(:sequence, [:version, :locals], RPCS)
|
||||
.node(:sequence, [:version, :locals], STEPS)
|
||||
.node(:home, [:speed, :axis], [])
|
||||
.node(:find_home, [:speed, :axis], [])
|
||||
.node(:zero, [:axis], [])
|
||||
|
@ -203,7 +205,7 @@ module CeleryScriptSettingsBag
|
|||
.node(:reboot, [], [])
|
||||
.node(:toggle_pin, [:pin_number], [])
|
||||
.node(:explanation, [:message], [])
|
||||
.node(:rpc_request, [:label], RPCS)
|
||||
.node(:rpc_request, [:label], ALLOWED_RPC_NODES)
|
||||
.node(:rpc_ok, [:label], [])
|
||||
.node(:rpc_error, [:label], [:explanation])
|
||||
.node(:calibrate, [:axis], [])
|
||||
|
|
|
@ -34,7 +34,6 @@ class Device < ApplicationRecord
|
|||
has_many :in_use_tools
|
||||
has_many :in_use_points
|
||||
has_many :users
|
||||
has_and_belongs_to_many :permissions
|
||||
|
||||
validates_presence_of :name
|
||||
validates :timezone,
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
class Permission < ApplicationRecord
|
||||
has_and_belongs_to_many :devices
|
||||
|
||||
# Device is allowed to create public sequences when granted.
|
||||
PUBLIC_SEQUENCES = "public_sequences"
|
||||
# dev = Device.joins(:permissions).find_or_create_by!(permissions: {name: Permission::PUBLIC_SEQUENCES})
|
||||
|
||||
def broadcast?
|
||||
false
|
||||
end
|
||||
|
||||
def self.to_create_public_sequences
|
||||
@to_create_public_sequences ||= \
|
||||
Permission.find_or_create_by!(name: Permission::PUBLIC_SEQUENCES)
|
||||
end
|
||||
end
|
|
@ -55,7 +55,7 @@ class Sequence < ApplicationRecord
|
|||
end
|
||||
|
||||
def manually_sync!
|
||||
device.auto_sync_transaction { broadcast! } if device # && !self.is_public
|
||||
device.auto_sync_transaction { broadcast! } if device
|
||||
end
|
||||
|
||||
# THIS IS AN OVERRIDE - See Sequence#body_as_json
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
module Sequences
|
||||
class MaybeBootstrap
|
||||
PATH = File.join File.dirname(__FILE__), "public_sequences.json"
|
||||
PUBLIC_SEQUENCES = JSON.parse(File.read(PATH))
|
||||
|
||||
def self.run!
|
||||
Sequence.transaction do
|
||||
PUBLIC_SEQUENCES
|
||||
.reject { |p| Sequence.where(is_public: true, name: p["name"]).any? }
|
||||
.map { |p| p[:device] = public_device; p }
|
||||
.map { |p| Sequences::Create.run!(p) }
|
||||
.pluck(:id)
|
||||
.map { |id| Sequence.find(id).update_attributes!(is_public: true) }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.public_device
|
||||
@public_device ||= maybe_create_public_device
|
||||
end
|
||||
|
||||
def self.maybe_create_public_device
|
||||
perm = Permission.to_create_public_sequences
|
||||
dev = perm.devices.last
|
||||
dev || Device.create!(name: "Sequence Publisher", permissions: [perm])
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,38 +0,0 @@
|
|||
[
|
||||
{
|
||||
"name": "Sync",
|
||||
"body": [
|
||||
{
|
||||
"kind": "sync",
|
||||
"args": {}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "E-stop",
|
||||
"body": [
|
||||
{
|
||||
"kind": "emergency_lock",
|
||||
"args": {}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Shutdown",
|
||||
"body": [
|
||||
{
|
||||
"kind": "power_off",
|
||||
"args": {}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Reboot",
|
||||
"body": [
|
||||
{
|
||||
"kind": "reboot",
|
||||
"args": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -1 +0,0 @@
|
|||
# Sequences::MaybeBootstrap.run!
|
|
@ -1,5 +0,0 @@
|
|||
class AddPublicToSequences < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :sequences, :is_public, :boolean, default: false
|
||||
end
|
||||
end
|
|
@ -1,13 +0,0 @@
|
|||
class CreatePermissions < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :permissions do |t|
|
||||
t.timestamps
|
||||
t.string :name, limit: 16, unique: true, null: false
|
||||
end
|
||||
|
||||
create_join_table :devices, :permissions do |t|
|
||||
t.index [:device_id, :permission_id]
|
||||
t.index [:permission_id, :device_id]
|
||||
end
|
||||
end
|
||||
end
|
43
db/schema.rb
43
db/schema.rb
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2018_07_11_143520) do
|
||||
ActiveRecord::Schema.define(version: 2018_05_20_201349) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "hstore"
|
||||
|
@ -48,32 +48,10 @@ ActiveRecord::Schema.define(version: 2018_07_11_143520) do
|
|||
t.datetime "last_saw_api"
|
||||
t.datetime "last_saw_mq"
|
||||
t.string "fbos_version", limit: 15
|
||||
t.datetime "throttled_until"
|
||||
t.datetime "throttled_at"
|
||||
t.index ["timezone"], name: "index_devices_on_timezone"
|
||||
end
|
||||
|
||||
create_table "devices_permissions", id: false, force: :cascade do |t|
|
||||
t.bigint "device_id", null: false
|
||||
t.bigint "permission_id", null: false
|
||||
t.index ["device_id", "permission_id"], name: "index_devices_permissions_on_device_id_and_permission_id"
|
||||
t.index ["permission_id", "device_id"], name: "index_devices_permissions_on_permission_id_and_device_id"
|
||||
end
|
||||
|
||||
create_table "diagnostic_dumps", force: :cascade do |t|
|
||||
t.bigint "device_id", null: false
|
||||
t.string "ticket_identifier", null: false
|
||||
t.string "fbos_commit", null: false
|
||||
t.string "fbos_version", null: false
|
||||
t.string "firmware_commit", null: false
|
||||
t.string "firmware_state", null: false
|
||||
t.string "network_interface", null: false
|
||||
t.text "fbos_dmesg_dump", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["device_id"], name: "index_diagnostic_dumps_on_device_id"
|
||||
end
|
||||
|
||||
create_table "edge_nodes", force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
|
@ -248,6 +226,14 @@ ActiveRecord::Schema.define(version: 2018_07_11_143520) do
|
|||
t.index ["device_id"], name: "index_images_on_device_id"
|
||||
end
|
||||
|
||||
create_table "log_dispatches", force: :cascade do |t|
|
||||
t.bigint "device_id"
|
||||
t.bigint "log_id"
|
||||
t.datetime "sent_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "logs", id: :serial, force: :cascade do |t|
|
||||
t.text "message"
|
||||
t.text "meta"
|
||||
|
@ -262,7 +248,6 @@ ActiveRecord::Schema.define(version: 2018_07_11_143520) do
|
|||
t.integer "x"
|
||||
t.integer "y"
|
||||
t.integer "z"
|
||||
t.datetime "sent_at"
|
||||
t.index ["created_at"], name: "index_logs_on_created_at"
|
||||
t.index ["device_id"], name: "index_logs_on_device_id"
|
||||
t.index ["type"], name: "index_logs_on_type"
|
||||
|
@ -280,12 +265,6 @@ ActiveRecord::Schema.define(version: 2018_07_11_143520) do
|
|||
t.index ["mode"], name: "index_peripherals_on_mode"
|
||||
end
|
||||
|
||||
create_table "permissions", force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "name", limit: 16, null: false
|
||||
end
|
||||
|
||||
create_table "pin_bindings", force: :cascade do |t|
|
||||
t.bigint "device_id"
|
||||
t.integer "pin_num"
|
||||
|
@ -344,7 +323,7 @@ ActiveRecord::Schema.define(version: 2018_07_11_143520) do
|
|||
t.string "parent_arg_name", limit: 50
|
||||
t.bigint "next_id"
|
||||
t.bigint "body_id"
|
||||
t.string "comment", limit: 240
|
||||
t.string "comment", limit: 80
|
||||
t.index ["body_id"], name: "index_primary_nodes_on_body_id"
|
||||
t.index ["child_id"], name: "index_primary_nodes_on_child_id"
|
||||
t.index ["next_id"], name: "index_primary_nodes_on_next_id"
|
||||
|
@ -406,7 +385,6 @@ ActiveRecord::Schema.define(version: 2018_07_11_143520) do
|
|||
t.datetime "updated_at"
|
||||
t.datetime "created_at"
|
||||
t.boolean "migrated_nodes", default: false
|
||||
t.boolean "is_public", default: false
|
||||
t.index ["created_at"], name: "index_sequences_on_created_at"
|
||||
t.index ["device_id"], name: "index_sequences_on_device_id"
|
||||
end
|
||||
|
@ -506,7 +484,6 @@ ActiveRecord::Schema.define(version: 2018_07_11_143520) do
|
|||
end
|
||||
|
||||
add_foreign_key "device_configs", "devices"
|
||||
add_foreign_key "diagnostic_dumps", "devices"
|
||||
add_foreign_key "edge_nodes", "sequences"
|
||||
add_foreign_key "farmware_installations", "devices"
|
||||
add_foreign_key "peripherals", "devices"
|
||||
|
|
|
@ -127,7 +127,7 @@ class CorpusEmitter
|
|||
result.push(enum_type :Color, Sequence::COLORS)
|
||||
result.push(enum_type :LegalArgString, HASH[:args].map{ |x| x[:name] }.sort.uniq)
|
||||
result.push(enum_type :LegalKindString, HASH[:nodes].map{ |x| x[:name] }.sort.uniq)
|
||||
result.push(enum_type :LegalSequenceKind, CeleryScriptSettingsBag::RPCS.sort)
|
||||
result.push(enum_type :LegalSequenceKind, CeleryScriptSettingsBag::STEPS.sort)
|
||||
result.push(enum_type :DataChangeType, CeleryScriptSettingsBag::ALLOWED_CHAGES)
|
||||
result.push(enum_type :PointType, CeleryScriptSettingsBag::ALLOWED_POINTER_TYPE)
|
||||
result.push(enum_type :AllowedPinTypes, CeleryScriptSettingsBag::ALLOWED_PIN_TYPES)
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
FactoryBot.define do
|
||||
factory :permission do
|
||||
|
||||
end
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe Permission, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe Sequences::MaybeBootstrap do
|
||||
it "bootstraps a list of public sequences (only once)" do
|
||||
Point.destroy_all
|
||||
TokenIssuance.destroy_all
|
||||
Device.destroy_all
|
||||
Sequence.destroy_all
|
||||
ps = Sequences::MaybeBootstrap::PUBLIC_SEQUENCES
|
||||
|
||||
Sequences::MaybeBootstrap.run!
|
||||
expect(Device.count).to eq(1)
|
||||
expect(Sequence.count).to eq(ps.count)
|
||||
|
||||
Sequences::MaybeBootstrap.run!
|
||||
expect(Device.count).to eq(1)
|
||||
expect(Sequence.count).to eq(ps.count)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue