Commit af5fb41d7f5e1cf69e8680eada08c2e24865a7cd

Authored by Rodrigo Souto
1 parent 94e57dec

[licenses] Adding default licenses

(ActionItem2379)
app/models/environment.rb
... ... @@ -737,9 +737,14 @@ class Environment < ActiveRecord::Base
737 737  
738 738 after_create :create_default_licenses
739 739 def create_default_licenses
740   - #TODO Must create here the default licenses. Also needs to create a
741   - # migration to create these licenses to environments that alaready
742   - # exists
  740 + License.create!(:name => 'CC (by)', :url => 'http://creativecommons.org/licenses/by/3.0/legalcode', :environment => self)
  741 + License.create!(:name => 'CC (by-nd)', :url => 'http://creativecommons.org/licenses/by-nd/3.0/legalcode', :environment => self)
  742 + License.create!(:name => 'CC (by-sa)', :url => 'http://creativecommons.org/licenses/by-sa/3.0/legalcode', :environment => self)
  743 + License.create!(:name => 'CC (by-nc)', :url => 'http://creativecommons.org/licenses/by-nc/3.0/legalcode', :environment => self)
  744 + License.create!(:name => 'CC (by-nc-nd)', :url => 'http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode', :environment => self)
  745 + License.create!(:name => 'CC (by-nc-sa)', :url => 'http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode', :environment => self)
  746 + License.create!(:name => 'Free Art', :url => 'http://artlibre.org/licence/lal/en', :environment => self)
  747 + License.create!(:name => 'GNU FDL', :url => 'http://www.gnu.org/licenses/fdl-1.3.txt', :environment => self)
743 748 end
744 749  
745 750 def highlighted_products_with_image(options = {})
... ...
db/migrate/20120718162001_create_default_licenses.rb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +class CreateDefaultLicenses < ActiveRecord::Migration
  2 + def self.up
  3 + Environment.all.each do |environment|
  4 + License.create!(:name => 'CC (by)', :url => 'http://creativecommons.org/licenses/by/3.0/legalcode', :environment => environment)
  5 + License.create!(:name => 'CC (by-nd)', :url => 'http://creativecommons.org/licenses/by-nd/3.0/legalcode', :environment => environment)
  6 + License.create!(:name => 'CC (by-sa)', :url => 'http://creativecommons.org/licenses/by-sa/3.0/legalcode', :environment => environment)
  7 + License.create!(:name => 'CC (by-nc)', :url => 'http://creativecommons.org/licenses/by-nc/3.0/legalcode', :environment => environment)
  8 + License.create!(:name => 'CC (by-nc-nd)', :url => 'http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode', :environment => environment)
  9 + License.create!(:name => 'CC (by-nc-sa)', :url => 'http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode', :environment => environment)
  10 + License.create!(:name => 'Free Art', :url => 'http://artlibre.org/licence/lal/en', :environment => environment)
  11 + License.create!(:name => 'GNU FDL', :url => 'http://www.gnu.org/licenses/fdl-1.3.txt', :environment => environment)
  12 + end
  13 + end
  14 +
  15 + def self.down
  16 + licenses = []
  17 + licenses += License.find(:all, :conditions => {:name => 'CC (by)'})
  18 + licenses += License.find(:all, :conditions => {:name => 'CC (by-nd)'})
  19 + licenses += License.find(:all, :conditions => {:name => 'CC (by-sa)'})
  20 + licenses += License.find(:all, :conditions => {:name => 'CC (by-nc)'})
  21 + licenses += License.find(:all, :conditions => {:name => 'CC (by-nc-nd)'})
  22 + licenses += License.find(:all, :conditions => {:name => 'CC (by-nc-sa)'})
  23 + licenses += License.find(:all, :conditions => {:name => 'Free Art'})
  24 + licenses += License.find(:all, :conditions => {:name => 'GNU FDL'})
  25 + licenses.compact.map(&:destroy)
  26 + end
  27 +end
... ...