2 desc "Register the built-in apps with specified user as owner; append necessary changes to settings file"
3 task :register_apps, [:display_name] => :environment do |task, args|
4 already_defined_keys = [:id_application, :oauth_application, :oauth_key] & Settings.keys
5 settings_filename = Rails.root.join("config/settings.local.yml")
6 settings_file_exists = File.file?(settings_filename)
8 unless already_defined_keys.empty?
9 if settings_file_exists
10 puts "The following settings are already defined (likely in #{settings_filename}):"
12 puts "The following settings are already defined:"
14 already_defined_keys.each do |key|
18 puts "Delete or comment them out to proceed."
20 raise "App settings already defined"
23 user = User.find_by! :display_name => args.display_name
25 model = Doorkeeper.config.application_model
27 id_application = model.create :name => "Local iD",
28 :redirect_uri => "http://localhost:3000",
29 :scopes => %w[read_prefs write_prefs write_api read_gpx write_gpx write_notes],
30 :confidential => false,
33 web_application = model.create :name => "OpenStreetMap Web Site",
34 :redirect_uri => "http://localhost:3000",
35 :scopes => %w[write_api write_notes],
38 File.open settings_filename, "a" do |file|
39 file << "\n" if settings_file_exists
41 # generated by #{task} rake task
42 # OAuth 2 Client ID for iD
43 id_application: "#{id_application.uid}"
44 # OAuth 2 Client ID for the web site
45 oauth_application: "#{web_application.uid}"
46 # OAuth 2 Client Secret for the web site
47 oauth_key: "#{web_application.plaintext_secret}"
51 puts "Updated settings in #{settings_filename}"