Skip to content

Commit 9e76fab

Browse files
committed
Revert "Remove dead staff applications code"
This reverts commit d7604c5.
1 parent d7604c5 commit 9e76fab

5 files changed

Lines changed: 161 additions & 1 deletion

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
- user_app = current_user.staff_applications.find_by(name: staff_application.key)
2+
3+
%div.staff-application{ id: "staff_application_#{staff_application.key}" }
4+
- if user_app
5+
- oauth_app = user_app.application
6+
7+
.title
8+
%h4= link_to(staff_application.name, oauth_app.uri)
9+
10+
.info
11+
.app-config{ data: { controller: 'clipboard' } }
12+
.path
13+
.app-path
14+
== #{staff_application.name.chomp(' (Local)').downcase.gsub(' ', '_')}/
15+
= staff_application.config_path
16+
.config-content
17+
.blocker{ onclick: "this.style.display = 'none'" }
18+
%span.button
19+
= inline_svg 'hero/20/pointer-click.svg'
20+
Click to view config
21+
%button.copy{ data: { action: 'clipboard#copy', clipboard_target: 'button' }, aria: { label: 'Copy' } }
22+
= inline_svg 'hero/20/duplicate.svg'
23+
Copy
24+
.copied.hidden{ data: { clipboard_target: 'notice' } }
25+
= inline_svg 'hero/20/circle-check.svg'
26+
Copied
27+
- if staff_application.config_prologue
28+
%pre.faded
29+
= format_staff_config(staff_application.config_prologue, oauth_app)
30+
31+
%pre{ data: { clipboard_target: 'source' } }
32+
= format_staff_config(staff_application.config_content, oauth_app)
33+
34+
- if staff_application.config_epilogue
35+
%pre.faded
36+
= format_staff_config(staff_application.config_epilogue, oauth_app)
37+
.reminder
38+
= inline_svg_tag 'hero/20/exclamation.svg'
39+
== Restart the #{staff_application.name.chomp(' (Local)')} application after changing the config!
40+
41+
.attributes
42+
%dl
43+
%dt Run command…
44+
%dd{ data: { controller: 'clipboard' }, style: 'display: flex; align-items: center; gap: 0.25rem' }
45+
%code{ data: { clipboard_target: 'source' } }= format_staff_run_command(staff_application.run_command, oauth_app)
46+
.command-copy
47+
%button.copy{ data: { action: 'clipboard#copy', clipboard_target: 'button' }, aria: { label: 'Copy' } }
48+
= inline_svg 'hero/20/duplicate.svg'
49+
Copy
50+
.copied{ data: { clipboard_target: 'notice' }, class: 'hidden' }
51+
= inline_svg 'hero/20/circle-check.svg'
52+
Copied!
53+
%dt
54+
= label_tag "staff_application_#{staff_application.key}_uri", 'Hosted at'
55+
%dd
56+
= form_tag inspect_staff_application_path(staff_application.key), method: :put do
57+
= text_field_tag :uri, oauth_app.uri, style: 'margin: 0', id: "staff_application_#{staff_application.key}_uri"
58+
%button.btn{ type: 'submit' } Change
59+
60+
%p.host-help
61+
If you run the application at a different address, you must set the correct address
62+
here for authentication to work correctly.
63+
64+
%p.host-help
65+
%mark If you change the address, you must also update the config file.
66+
- else
67+
.title
68+
%h4= staff_application.name
69+
70+
%p
71+
This application is not configured. Set the location where you run the app.
72+
You can change this later.
73+
74+
= form_tag inspect_staff_application_path(staff_application.key), method: :put do
75+
= label_tag "staff_application_#{staff_application.key}_uri", 'Hosted at'
76+
= text_field_tag :uri, staff_application.uri, style: 'margin: 0', id: "staff_application_#{staff_application.key}_uri"
77+
%button.btn{ type: 'submit' } Create application

bin/import-db

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ end
7575
# DB file.
7676
def import_db_commands(import_command, file)
7777
[
78+
['Dump staff applications', 'bundle exec rails RAILS_ENV=development db:dump_staff_applications > /dev/null'],
7879
['Remove and recreate DB', 'bundle exec rails RAILS_ENV=development db:environment:set db:drop db:create > /dev/null'],
7980
['Import DB', Kernel.format(import_command, file.path.shellescape)],
80-
['Set DB environment', 'bundle exec rails RAILS_ENV=development db:environment:set > /dev/null']
81+
['Set DB environment', 'bundle exec rails RAILS_ENV=development db:environment:set > /dev/null'],
82+
['Load staff applications', 'bundle exec rails RAILS_ENV=development db:load_staff_applications']
8183
]
8284
end
8385

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@
155155
get '/' => 'pages#start_inspect'
156156
get '/redirect' => 'base#redirect', as: 'redirect'
157157

158+
put '/staff_application/:id' => 'staff_applications#update', as: :staff_application
159+
158160
get 'search.js' => 'search#index', as: :search_autocomplete
159161

160162
resources :scenarios, only: [] do
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class CreateStaffApplications < ActiveRecord::Migration[7.0]
2+
def change
3+
create_table :staff_applications do |t|
4+
t.string :name, null: false
5+
t.references :user, null: false, foreign_key: true
6+
t.bigint :application_id, null: false
7+
8+
t.index [:user_id, :name], unique: true
9+
end
10+
11+
add_foreign_key :staff_applications, :oauth_applications, column: :application_id
12+
end
13+
end

lib/tasks/dump_db.rake

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,70 @@ namespace :db do
1717

1818
puts "tmp/#{ dump_to }"
1919
end
20+
21+
desc 'Dumps staff applications to be reloaded later'
22+
task dump_staff_applications: :environment do
23+
FileUtils.rm_rf('tmp/staff_applications.yml')
24+
25+
applications = []
26+
staff_applications = []
27+
tokens = []
28+
29+
StaffApplication.all.includes(:application).map do |app|
30+
applications.push(app.application.attributes)
31+
staff_applications.push(app.attributes)
32+
tokens.push(*app.application.access_tokens.map(&:attributes))
33+
end
34+
35+
File.write(
36+
'tmp/staff_applications.yml',
37+
{
38+
'applications' => applications,
39+
'staff_applications' => staff_applications,
40+
'tokens' => tokens
41+
}.to_yaml
42+
)
43+
44+
FileUtils.chmod(0o600, 'tmp/staff_applications.yml')
45+
rescue StandardError
46+
FileUtils.rm('tmp/staff_applications.yml') if File.exist?('tmp/staff_applications.yml')
47+
end
48+
49+
desc 'Loads staff applications from a dump'
50+
task load_staff_applications: :environment do
51+
unless File.exist?('tmp/staff_applications.yml')
52+
puts 'No staff applications dump found'
53+
exit
54+
end
55+
56+
apps = YAML.unsafe_load_file('tmp/staff_applications.yml')
57+
58+
StaffApplication.transaction do
59+
StaffApplication.destroy_all
60+
61+
OAuthApplication.insert_all!(apps['applications']) if apps['applications'].any?
62+
StaffApplication.insert_all!(apps['staff_applications']) if apps['staff_applications'].any?
63+
Doorkeeper::AccessToken.insert_all!(apps['tokens']) if apps['tokens'].any?
64+
65+
FileUtils.rm('tmp/staff_applications.yml')
66+
rescue StandardError
67+
puts <<~MESSAGE
68+
┌─────────────────────────────────────────────────────────────────────────┐
69+
│ !!!️ CONNECTING ETMODEL AND TRANSITION PATHS !!!️ │
70+
├─────────────────────────────────────────────────────────────────────────┤
71+
│ Importing a database dump removed the credentials used to connect your │
72+
│ local ETModel or Transition Paths app with ETEngine. │
73+
│ │
74+
│ If you wish you connect ETModel or Transition Paths with your local │
75+
│ ETEngine: │
76+
│ │
77+
│ 1. Start ETEngine: bundle exec rails server. │
78+
│ 2. Sign in to your account at http://localhost:3000. │
79+
│ 3. Scroll down and create a new ETModel or Transition Path application. │
80+
│ 4. Copy the generated config to the other application. │
81+
│ 5. Restart the other application. │
82+
└─────────────────────────────────────────────────────────────────────────┘
83+
MESSAGE
84+
end
85+
end
2086
end

0 commit comments

Comments
 (0)