Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions spec/controllers/modules_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -469,5 +469,43 @@ module PlaceOS::Api
end
end
end

describe "POST /:id/start and POST /:id/stop" do
it "allows support users to start and stop modules" do
control_system = Model::Generator.control_system
control_system.zones << Spec::Authentication.org_zone.id.as(String)
control_system.zones_will_change!
control_system.save!

driver = Model::Generator.driver(role: Model::Driver::Role::Logic).save!
mod = Model::Generator.module(driver: driver, control_system: control_system)
mod.running = false
mod.save!

id = mod.id.as(String)
start_path = File.join(Modules.base_route, id, "start")
stop_path = File.join(Modules.base_route, id, "stop")

# Test that admin user can start a module
result = client.post(
path: start_path,
headers: Spec::Authentication.headers(sys_admin: false, support: true),
)

result.status_code.should eq 200
mod.reload!
mod.running.should be_true

# Test that admin user can stop a module
result = client.post(
path: stop_path,
headers: Spec::Authentication.headers(sys_admin: false, support: true),
)

result.status_code.should eq 200
mod.reload!
mod.running.should be_false
end
end
end
end
6 changes: 3 additions & 3 deletions src/placeos-rest-api/controllers/modules.cr
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module PlaceOS::Api
before_action :can_write, only: [:create, :update, :destroy, :remove]

before_action :check_admin, except: [:index, :create, :update, :destroy, :state, :show, :ping, :start, :stop]
before_action :check_support, only: [:state, :show, :ping, :show_error]
before_action :check_support, only: [:state, :show, :ping, :show_error, :start, :stop]

###############################################################################################

Expand Down Expand Up @@ -298,7 +298,7 @@ module PlaceOS::Api
@[AC::Route::POST("/:id/start")]
def start : Nil
return if current_module.running == true
can_modify?(current_module)
can_modify?(current_module) unless user_support?
current_module.update_fields(running: true)

# Changes cleared on a successful update
Expand All @@ -312,7 +312,7 @@ module PlaceOS::Api
@[AC::Route::POST("/:id/stop")]
def stop : Nil
return unless current_module.running
can_modify?(current_module)
can_modify?(current_module) unless user_support?
current_module.update_fields(running: false)

# Changes cleared on a successful update
Expand Down
Loading