Commit 115f6c107ef8deee52f10b39e5e7d08c8dd329db

Authored by Gabriela Navarro
Committed by Parley
1 parent f19d2ba5
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

more_inst_for_users: Add relation to institution and users.

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
db/migrate/20140818195821_remove_institution_from_user.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class RemoveInstitutionFromUser < ActiveRecord::Migration
  2 + def up
  3 + remove_column :users, :institution_id
  4 + end
  5 +
  6 + def down
  7 + add_column :users, :institution_id
  8 + end
  9 +end
... ...
db/migrate/20140818200738_create_institution_user_relation_table.rb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +class CreateInstitutionUserRelationTable < ActiveRecord::Migration
  2 + def up
  3 + create_table :institutions_users do |t|
  4 + t.belongs_to :user
  5 + t.belongs_to :institution
  6 + end
  7 + end
  8 +
  9 + def down
  10 + drop_table :institutions_users
  11 + end
  12 +end
... ...
lib/ext/user.rb
... ... @@ -2,7 +2,7 @@ require_dependency &#39;user&#39;
2 2  
3 3 class User
4 4  
5   - belongs_to :institution
  5 + has_and_belongs_to_many :institutions
6 6  
7 7 validate :email_different_secondary?, :email_has_already_been_used?,
8 8 :secondary_email_format, :email_suffix_is_gov?
... ...
lib/institution.rb
... ... @@ -5,7 +5,7 @@ class Institution &lt; ActiveRecord::Base
5 5 attr_accessible :name, :acronym, :unit_code, :parent_code, :unit_type,
6 6 :juridical_nature, :sub_juridical_nature, :normalization_level,
7 7 :version, :cnpj, :type, :governmental_power, :governmental_sphere
8   - has_many :users
  8 + has_and_belongs_to_many :users
9 9  
10 10 validates :name, :presence=>true, :uniqueness=>true
11 11  
... ...
lib/institutions_users.rb 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +class InstitutionUser < ActiveRecord::Base
  2 + belongs_to :user
  3 + belongs_to :institution
  4 +end
... ...