Sha256: ee580e5a587f28e6b1cf23cd2f7f83031e5c392af7f4af2d24185c4e99386a08

Contents?: true

Size: 1.69 KB

Versions: 8

Compression:

Stored size: 1.69 KB

Contents

# -*- encoding : utf-8 -*-

class AddRecaptchaKeyAndAdminInfoCards < Card::Migration::Core
  def up
    create_recaptcha_settings
    Card::Cache.reset_all
    create_admin_cards
    update_machine_output
  end

  def create_admin_cards
    admin_only name: "*admin info",
               codename: "admin_info"
    admin_only name: "*google_analytics_key",
               codename: "google_analytics_key"

    codenames = %w(debugger recaptcha_settings)
    content =
      codenames.map do |cn|
        "[[#{Card[cn.to_sym].name}]]"
      end.join "\n"
    admin_only name: "*admin settings",
               codename: "admin_settings",
               type_id: Card::PointerID,
               content: content
    add_admin_info_to_home_card
  end

  def add_admin_info_to_home_card
    return unless (home = Card[Card[:home].db_content])
    new_content = home.db_content.prepend "{{*admin info|content}}\n"
    home.update! content: new_content
  end

  def create_recaptcha_settings
    admin_only name: "*recaptcha settings",
               codename: :recaptcha_settings, type_id: Card::PointerID,
               content: "[[+public key]]\n" \
                        "[[+private key]]\n" \
                        "[[+proxy]]"
    Card::Cache.reset_all
    %w(public_key private_key proxy).each do |name|
      Card.create!(
        name: "#{Card[:recaptcha_settings].name}+#{name.tr('_', ' ')}",
        codename: "recaptcha_#{name}"
      )
    end
  end

  def admin_only args
    create_or_update! args.reverse_merge(type_id: Card::PhraseID)
    %w(*read *update *delete).each do |perm|
      create_or_update! name: "#{args[:name]}+*self+#{perm}",
                        content: "[[Administrator]]"
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
card-1.100.0 db/migrate_core_cards/20150610180019_add_recaptcha_key_and_admin_info_cards.rb
card-1.99.6 db/migrate_core_cards/20150610180019_add_recaptcha_key_and_admin_info_cards.rb
card-1.99.5 db/migrate_core_cards/20150610180019_add_recaptcha_key_and_admin_info_cards.rb
card-1.99.4 db/migrate_core_cards/20150610180019_add_recaptcha_key_and_admin_info_cards.rb
card-1.99.3 db/migrate_core_cards/20150610180019_add_recaptcha_key_and_admin_info_cards.rb
card-1.99.2 db/migrate_core_cards/20150610180019_add_recaptcha_key_and_admin_info_cards.rb
card-1.99.1 db/migrate_core_cards/20150610180019_add_recaptcha_key_and_admin_info_cards.rb
card-1.99.0 db/migrate_core_cards/20150610180019_add_recaptcha_key_and_admin_info_cards.rb