Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scope updates #63

Merged
merged 2 commits into from
Aug 11, 2022
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
15 changes: 15 additions & 0 deletions openc3-cmd-tlm-api/app/controllers/scopes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,19 @@ class ScopesController < ModelController
def initialize
@model_class = OpenC3::ScopeModel
end

def create(update_model = false)
return unless authorization('superadmin')
super(update_model)
end

def destroy
return unless authorization('superadmin')
begin
result = OpenC3::ProcessManager.instance.spawn(["ruby", "/openc3/bin/openc3cli", "destroyscope", params[:id]], "scope_uninstall", params[:id], Time.now + 2.hours, scope: 'DEFAULT')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems weird to have to give a scope: 'DEFAULT' to the process to destroy scopes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DEFAULT scope is also going to be the kindof "global scope" that owns Scopes and Roles.

render :json => result
rescue Exception => e
render(:json => { :status => 'error', :message => e.message }, :status => 500) and return
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ export default {
'openc3-tool-tablemanager',
'openc3-tool-tlmgrapher',
'openc3-tool-tlmviewer',
'openc3-enterprise-tool-base',
'openc3-enterprise-tool-admin',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these should be here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative is copy this whole file into enterprise and then add in the differences, or come up with some sort of included subfile. This is the simplest for now and we can cleanup later.

],
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@
</template>

<script>
import Scopes from '../util/scopes.js'

export default {
mixins: [Scopes],
data: function () {
return {
scopes: [], // gets set in the mixin
scopes: ['DEFAULT'],
scope: localStorage.scope,
}
},
Expand Down

This file was deleted.

4 changes: 4 additions & 0 deletions openc3/bin/openc3cli
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,10 @@ if not ARGV[0].nil? # argument(s) given
end
end

when 'destroyscope'
scope = OpenC3::ScopeModel.get_model(name: ARGV[1])
scope.destroy

else # Unknown task
print_usage()
abort("Unknown task: #{ARGV[0]}")
Expand Down
37 changes: 37 additions & 0 deletions openc3/lib/openc3/models/scope_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,47 @@ def self.all(scope: nil)
super(PRIMARY_KEY)
end

def self.from_json(json, scope: nil)
json = JSON.parse(json, :allow_nan => true, :create_additions => true) if String === json
raise "json data is nil" if json.nil?

json.transform_keys!(&:to_sym)
self.new(**json, scope: scope)
end

def self.get_model(name:, scope: nil)
json = get(name: name)
if json
return from_json(json)
else
return nil
end
end

def initialize(name:, updated_at: nil, scope: nil)
super(PRIMARY_KEY, name: name, scope: name, updated_at: updated_at)
end

def create(update: false, force: false)
# Ensure there are no "." in the scope name - prevents gems accidently becoming scope names
raise "Invalid scope name: #{@name}" if @name !~ /^[a-zA-Z0-9_-]+$/
@name = @name.upcase
super(update: update, force: force)
end

def destroy
if @name != 'DEFAULT'
# Remove all the plugins for this scope
plugins = PluginModel.get_all_models(scope: @name)
plugins.each do |plugin_name, plugin|
plugin.destroy
end
super()
else
raise "DEFAULT scope cannot be destroyed"
end
end

def as_json(*a)
{ 'name' => @name,
'updated_at' => @updated_at }
Expand Down