diff --git a/db/migrate/20140528193816_add_extra_fields_to_user.rb b/db/migrate/20140528193816_add_extra_fields_to_user.rb new file mode 100644 index 0000000..087fc62 --- /dev/null +++ b/db/migrate/20140528193816_add_extra_fields_to_user.rb @@ -0,0 +1,17 @@ +class AddExtraFieldsToUser < ActiveRecord::Migration + def self.up + change_table :users do |t| + t.string :secondary_email + t.references :institution + t.string :role + end + end + + def self.down + change_table :users do |t| + t.remove :secondary_email + t.remove_references :institution + t.remove :role + end + end +end diff --git a/db/migrate/20150408121921_add_extra_fields_to_gov_user.rb b/db/migrate/20150408121921_add_extra_fields_to_gov_user.rb deleted file mode 100644 index 2979cf5..0000000 --- a/db/migrate/20150408121921_add_extra_fields_to_gov_user.rb +++ /dev/null @@ -1,15 +0,0 @@ -class AddExtraFieldsToGovUser < ActiveRecord::Migration - def self.up - change_table :users do |t| - t.string :secondary_email - t.string :role - end - end - - def self.down - change_table :users do |t| - t.remove :secondary_email - t.remove :role - end - end -end diff --git a/lib/ext/person.rb b/lib/ext/person.rb index 34ea237..08e9614 100644 --- a/lib/ext/person.rb +++ b/lib/ext/person.rb @@ -18,4 +18,14 @@ class Person self.user.secondary_email = value unless self.user.nil? end + def institutions + institutions = [] + unless self.user.institutions.nil? + self.user.institutions.each do |institution| + institutions << institution.name + end + end + institutions + end + end diff --git a/lib/ext/user.rb b/lib/ext/user.rb index 3817c86..7663045 100644 --- a/lib/ext/user.rb +++ b/lib/ext/user.rb @@ -4,6 +4,8 @@ class User GOV_SUFFIX = /^.*@[gov.br|jus.br|leg.br|mp.br]+$/ + has_and_belongs_to_many :institutions + validate :email_different_secondary?, :email_has_already_been_used?, :secondary_email_format, :email_suffix_is_gov? -- libgit2 0.21.2