-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathscreens_controller.rb
More file actions
52 lines (47 loc) · 1.76 KB
/
screens_controller.rb
File metadata and controls
52 lines (47 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# encoding: ascii-8bit
# Copyright 2023 OpenC3, Inc.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
# under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.
class ScreensController < ApplicationController
def index
return unless authorization('system')
render :json => Screen.all(*params.require([:scope]))
end
def show
return unless authorization('system')
screen = Screen.find(*params.require([:scope, :target, :screen]))
if screen
render :json => screen
else
head :not_found
end
end
def create
return unless authorization('system_set')
screen = Screen.create(*params.require([:scope, :target, :screen, :text]))
OpenC3::Logger.info("Screen saved: #{params[:target]} #{params[:screen]}", scope: params[:scope], user: username())
render :json => screen
rescue => e
render(json: { status: 'error', message: e.message }, status: 500)
end
def destroy
return unless authorization('system_set')
screen = Screen.destroy(*params.require([:scope, :target, :screen]))
OpenC3::Logger.info("Screen deleted: #{params[:target]} #{params[:screen]}", scope: params[:scope], user: username())
head :ok
rescue => e
render(json: { status: 'error', message: e.message }, status: 500)
end
end