Sfoglia il codice sorgente

Clean up the way user corp checking is handled.

old-ruby
Ben Kurtovic 9 anni fa
parent
commit
bfdbaa3ad9
5 ha cambiato i file con 41 aggiunte e 13 eliminazioni
  1. +4
    -1
      app/models/user.rb
  2. +5
    -0
      db/migrate/20150316234044_remove_is_corp_from_user.rb
  3. +1
    -2
      db/schema.rb
  4. +1
    -1
      db/seeds.rb
  5. +30
    -9
      lib/tasks/calefaction.rake

+ 4
- 1
app/models/user.rb Vedi File

@@ -3,7 +3,6 @@ require 'eaal'
class User < ActiveRecord::Base
has_secure_password
alias_attribute :admin?, :is_admin
alias_attribute :corp?, :is_corp

def char_names
ensure_api_user
@@ -14,6 +13,10 @@ class User < ActiveRecord::Base
end
end

def in_corp?
member_of? AdminSettings.get(:corp_id)
end

def member_of?(corp_id)
ensure_api_user
@api.scope = 'char'


+ 5
- 0
db/migrate/20150316234044_remove_is_corp_from_user.rb Vedi File

@@ -0,0 +1,5 @@
class RemoveIsCorpFromUser < ActiveRecord::Migration
def change
remove_column :users, :is_corp, :boolean
end
end

+ 1
- 2
db/schema.rb Vedi File

@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150314013929) do
ActiveRecord::Schema.define(version: 20150316234044) do

create_table "admin_settings", force: :cascade do |t|
t.string "key"
@@ -25,7 +25,6 @@ ActiveRecord::Schema.define(version: 20150314013929) do
t.string "api_key"
t.string "api_verify"
t.boolean "is_admin"
t.boolean "is_corp"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end


+ 1
- 1
db/seeds.rb Vedi File

@@ -8,7 +8,7 @@

AdminSetting.add(:site_name, 'Your Corporation\'s Site')
AdminSetting.add(:corp_name, 'Your Corporation')
AdminSetting.add(:corp_id, '1')
AdminSetting.add(:corp_id, '0')
AdminSetting.add(:copyright, 'Your Corporation/Your Name')
AdminSetting.add(:description,
'Welcome to your corporation\'s website! This message can be changed in the admin settings panel.')


+ 30
- 9
lib/tasks/calefaction.rake Vedi File

@@ -1,8 +1,29 @@
require 'io/console'

namespace :calefaction do
desc "Sets some initial database values and creates an admin user"
desc "Set some initial database values and creates an admin user"
task setup: :environment do
begin
AdminSetting.get(:test)
rescue ActiveRecord::StatementInvalid
puts "The database has not been set up properly. You need to run\n"\
"`rake db:setup` first."
next
end

if AdminSetting.get(:corp_id).nil?
puts "The database does not contain the correct seed values. You need "\
"to run\n`rake db:reset db:setup` first."
next
end

if AdminSetting.get(:corp_id).to_i > 0
puts "The database is not empty; you should change settings from "\
"within the\napplication. Alternatively, you can start over with\n"\
"`rake db:reset db:setup calefaction:setup`."
next
end

print "Enter your corporation's name: "
corp_name = STDIN.gets.chomp

@@ -16,13 +37,12 @@ namespace :calefaction do

print "\nEnter your character's API key ID (create one at\n"\
"https://community.eveonline.com/support/api-key/createpredefined?accessMask=8): "
user_api_key = STDIN.gets.chomp
api_key = STDIN.gets.chomp

print "\nEnter the verification code for the key you just entered: "
user_api_verify = STDIN.gets.chomp
api_verify = STDIN.gets.chomp

user = User.new(api_key: user_api_key, api_verify: user_api_verify,
is_admin: true, is_corp: true)
user = User.new(api_key: api_key, api_verify: api_verify, admin?: true)
chars = user.char_names
if chars.empty?
puts "The given API key is invalid, has no characters, or something "\
@@ -32,6 +52,7 @@ namespace :calefaction do

if chars.length == 1
user.name = chars.first
puts "\nUsing character: #{user.name}"
else
puts "\nChoose a character:"
chars.each_with_index do |name, i|
@@ -40,7 +61,7 @@ namespace :calefaction do
puts "Enter the number next to your chosen character: "
loop do
index = STDIN.gets.to_i
break unless index >= chars.length || index < 0
break if index >= 0 && index < chars.length
puts "Bad input; try again: "
end
user.name = chars[index]
@@ -66,10 +87,10 @@ namespace :calefaction do
end
puts

AdminSetting.where(key: %w(corp_name site_name)).update_all(value: corp_name)
AdminSetting.find_by(key: 'corp_id').update(value: corp_id)
AdminSetting.set(:corp_name, corp_name)
AdminSetting.set(:site_name, corp_name)
AdminSetting.set(:corp_id, corp_id)
user.save

puts "\nDone!"
end
end

Caricamento…
Annulla
Salva