diff --git a/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb b/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb
index 2e6b477..fdbc0e7 100644
--- a/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb
+++ b/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb
@@ -120,7 +120,7 @@ class GovUserPluginController < ApplicationController
params[:community] ||= {}
params[:institutions] ||= {}
- @show_sisp_field = user.is_admin?
+ @show_admin_fields = user.is_admin?
@governmental_sphere = get_governmental_spheres()
@governmental_power = get_governmental_powers()
@juridical_nature = get_juridical_natures()
diff --git a/src/noosfero-spb/gov_user/controllers/gov_user_plugin_myprofile_controller.rb b/src/noosfero-spb/gov_user/controllers/gov_user_plugin_myprofile_controller.rb
index 84bd92b..9fab36c 100644
--- a/src/noosfero-spb/gov_user/controllers/gov_user_plugin_myprofile_controller.rb
+++ b/src/noosfero-spb/gov_user/controllers/gov_user_plugin_myprofile_controller.rb
@@ -7,7 +7,7 @@ class GovUserPluginMyprofileController < MyProfileController
end
def edit_institution
- @show_sisp_field = user.is_admin?
+ @show_admin_fields = user.is_admin?
@state_list = NationalRegion.find(
:all,
:conditions => { :national_region_type_id => 2 },
diff --git a/src/noosfero-spb/gov_user/db/migrate/20160525181858_change_siorg_column_type.rb b/src/noosfero-spb/gov_user/db/migrate/20160525181858_change_siorg_column_type.rb
new file mode 100644
index 0000000..fdbd0ab
--- /dev/null
+++ b/src/noosfero-spb/gov_user/db/migrate/20160525181858_change_siorg_column_type.rb
@@ -0,0 +1,9 @@
+class ChangeSiorgColumnType < ActiveRecord::Migration
+ def self.up
+ change_column :institutions, :siorg_code, :string
+ end
+
+ def self.down
+ change_column :institutions, :siorg_code, :integer
+ end
+end
diff --git a/src/noosfero-spb/gov_user/features/institution_registration.feature b/src/noosfero-spb/gov_user/features/institution_registration.feature
index 1778592..82a9181 100644
--- a/src/noosfero-spb/gov_user/features/institution_registration.feature
+++ b/src/noosfero-spb/gov_user/features/institution_registration.feature
@@ -47,3 +47,25 @@ Feature: Institution Field
And I should not see "community_city"
And I select "Brazil" from "community_country"
Then I should not see "Gama"
+
+ @selenium
+ Scenario: Show sisp and siorg field to admin on create new institution form
+ Given I follow "Control panel"
+ And I follow "Edit Profile"
+ When I follow "Create new institution"
+ And I choose "Public Institution"
+ Then I should see "SISP?"
+ And I should see "SIORG Code"
+
+ @selenium
+ Scenario: Not show sisp and siorg field to regular user on create new institution form
+ Given the following users
+ | login |
+ | zombie |
+ And I am logged in as "zombie"
+ When I follow "Control panel"
+ And I follow "Edit Profile"
+ And I follow "Create new institution"
+ And I choose "Public Institution"
+ Then I should not see "SISP?"
+ And I should not see "SIORG Code"
diff --git a/src/noosfero-spb/gov_user/lib/institution.rb b/src/noosfero-spb/gov_user/lib/institution.rb
index 70ea0e1..a9fc63d 100644
--- a/src/noosfero-spb/gov_user/lib/institution.rb
+++ b/src/noosfero-spb/gov_user/lib/institution.rb
@@ -46,8 +46,18 @@ class Institution < ActiveRecord::Base
}
validate :validate_country, :validate_state, :validate_city,
- :verify_institution_type
+ :verify_institution_type, :verify_siorg_code
+ def verify_siorg_code
+ if (self.siorg_code.present? && (self.siorg_code =~ /^[0-9]+$/).nil?)
+ self.errors.add(
+ :siorg_code,
+ _("invalid, only numbers are allowed.")
+ )
+ return false
+ end
+ true
+ end
def has_accepted_rating? user_rating
rating_ids = OrganizationRating.where(institution_id: self.id, organization_id: user_rating.organization_id).map(&:id)
diff --git a/src/noosfero-spb/gov_user/public/views/create-institution.js b/src/noosfero-spb/gov_user/public/views/create-institution.js
index 1c7ea9f..96c08f1 100644
--- a/src/noosfero-spb/gov_user/public/views/create-institution.js
+++ b/src/noosfero-spb/gov_user/public/views/create-institution.js
@@ -45,6 +45,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement']
function get_institution_post_data() {
+
return {
cnpj: $("#institutions_cnpj").val(),
type: $("input[name='institutions[type]']:checked").val(),
@@ -52,7 +53,9 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement']
governmental_power: $("#institutions_governmental_power").selected().val(),
governmental_sphere: $("#institutions_governmental_sphere").selected().val(),
juridical_nature: $("#institutions_juridical_nature").selected().val(),
- corporate_name: $("#institutions_corporate_name").val()
+ corporate_name: $("#institutions_corporate_name").val(),
+ siorg_code: $("#institutions_siorg_code").val(),
+ sisp: $('input[name="institutions[sisp]"]:checked').val()
};
}
diff --git a/src/noosfero-spb/gov_user/views/gov_user_plugin/_institution.html.erb b/src/noosfero-spb/gov_user/views/gov_user_plugin/_institution.html.erb
index 6901a38..f52d967 100644
--- a/src/noosfero-spb/gov_user/views/gov_user_plugin/_institution.html.erb
+++ b/src/noosfero-spb/gov_user/views/gov_user_plugin/_institution.html.erb
@@ -30,37 +30,48 @@
<%= hidden_field_tag "edit_institution_page", false %>
<%= fields_for :institutions do |inst| %>