Authorization
parent
dc2bcd1747
commit
ce2cfcfb0b
2
Gemfile
2
Gemfile
|
@ -18,7 +18,7 @@ group :development, :test do
|
||||||
gem "pry"
|
gem "pry"
|
||||||
gem "factory_girl_rails"
|
gem "factory_girl_rails"
|
||||||
gem "faker"
|
gem "faker"
|
||||||
gem "smarf_doc", github: "RickCarlino/smarf_doc"
|
gem "smarf_doc", git: "https://github.com/RickCarlino/smarf_doc.git"
|
||||||
gem "rails-erd"
|
gem "rails-erd"
|
||||||
gem "rspec"
|
gem "rspec"
|
||||||
gem "rspec-rails"
|
gem "rspec-rails"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
GIT
|
GIT
|
||||||
remote: git://github.com/RickCarlino/smarf_doc.git
|
remote: https://github.com/RickCarlino/smarf_doc.git
|
||||||
revision: 40dc733363431c6153ccebbeb80df942a77f0b02
|
revision: 40dc733363431c6153ccebbeb80df942a77f0b02
|
||||||
specs:
|
specs:
|
||||||
smarf_doc (1.0.0)
|
smarf_doc (1.0.0)
|
||||||
|
@ -90,6 +90,7 @@ GEM
|
||||||
mutations (0.8.0)
|
mutations (0.8.0)
|
||||||
activesupport
|
activesupport
|
||||||
mysql (2.9.1)
|
mysql (2.9.1)
|
||||||
|
mysql2 (0.4.5)
|
||||||
nio4r (1.2.1)
|
nio4r (1.2.1)
|
||||||
nokogiri (1.6.8.1)
|
nokogiri (1.6.8.1)
|
||||||
mini_portile2 (~> 2.1.0)
|
mini_portile2 (~> 2.1.0)
|
||||||
|
@ -202,6 +203,7 @@ DEPENDENCIES
|
||||||
jwt
|
jwt
|
||||||
mutations
|
mutations
|
||||||
mysql
|
mysql
|
||||||
|
mysql2
|
||||||
pg
|
pg
|
||||||
pry
|
pry
|
||||||
rack-cors
|
rack-cors
|
||||||
|
|
|
@ -25,8 +25,8 @@ private
|
||||||
|
|
||||||
def update_params
|
def update_params
|
||||||
output = {tool: tool}
|
output = {tool: tool}
|
||||||
output[:name] = params[:name] if params[:name]
|
output[:name] = params[:name] if params[:name]
|
||||||
output[:tool_slot] = tool_slot if params[:tool_slot_id]
|
output[:tool_slot] = params[:tool_slot_id] if params[:tool_slot_id]
|
||||||
output
|
output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -34,9 +34,9 @@ private
|
||||||
if @create_params
|
if @create_params
|
||||||
@create_params
|
@create_params
|
||||||
else
|
else
|
||||||
tsid = params[:tool_slot_id]
|
|
||||||
@create_params = { name: params[:name],
|
@create_params = { name: params[:name],
|
||||||
device: current_device }
|
device: current_device }
|
||||||
|
tsid = params[:tool_slot_id]
|
||||||
@create_params[:tool_slot_id] = tsid if tsid
|
@create_params[:tool_slot_id] = tsid if tsid
|
||||||
@create_params
|
@create_params
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
module Tools
|
||||||
|
class Base < Mutations::Command
|
||||||
|
def it_is_your_tool_slot
|
||||||
|
(tool_slot.tool_bay.device_id == device.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def tool_slot
|
||||||
|
@tool_slot ||= ToolSlot.find_by(id: tool_slot_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def forbidden!
|
||||||
|
raise Errors::Forbidden
|
||||||
|
end
|
||||||
|
|
||||||
|
def bad_tool_slot_id!
|
||||||
|
add_error :tool_slot, :bad, "Bad tool slot ID"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,5 +1,5 @@
|
||||||
module Tools
|
module Tools
|
||||||
class Create < Mutations::Command
|
class Create < Tools::Base
|
||||||
required do
|
required do
|
||||||
string :name
|
string :name
|
||||||
model :device, class: Device
|
model :device, class: Device
|
||||||
|
@ -10,17 +10,12 @@ module Tools
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
puts "TODO: Validate user authorizations"
|
bad_tool_slot_id! unless tool_slot
|
||||||
|
forbidden! if tool_slot_id && !it_is_your_tool_slot
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
Tool.create!(inputs)
|
Tool.create!(inputs)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def query
|
|
||||||
@query ||= ToolBay::DeviceQuery.new(device)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
module Tools
|
module Tools
|
||||||
class Update < Mutations::Command
|
class Update < Tools::Base
|
||||||
required do
|
required do
|
||||||
model :tool, class: Tool
|
model :tool, class: Tool
|
||||||
end
|
end
|
||||||
|
|
||||||
optional do
|
optional do
|
||||||
string :name
|
string :name
|
||||||
model :tool_slot, class: ToolSlot
|
integer :tool_slot_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate
|
||||||
|
bad_tool_slot_id! if tool_slot_id && !tool_slot
|
||||||
|
forbidden! if tool_slot_id && !it_is_your_tool_slot
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
|
|
Loading…
Reference in New Issue