diff --git a/app/controllers/public/enterprise_registration_controller.rb b/app/controllers/public/enterprise_registration_controller.rb index 31b2281..289bee4 100644 --- a/app/controllers/public/enterprise_registration_controller.rb +++ b/app/controllers/public/enterprise_registration_controller.rb @@ -15,14 +15,16 @@ class EnterpriseRegistrationController < ApplicationController if params[:create_enterprise] && params[:create_enterprise][:target_id] @create_enterprise.target = Profile.find(params[:create_enterprise][:target_id]) end - elsif @validation == :admin + elsif @validation == :admin || @validation == :none @create_enterprise.target = @create_enterprise.environment end @create_enterprise.requestor = current_user.person the_action = if request.post? if @create_enterprise.valid_before_selecting_target? - if @create_enterprise.valid? || @validation == :admin + if @create_enterprise.valid? && @validation == :none + :creation + elsif @create_enterprise.valid? || @validation == :admin :confirmation else :select_validator @@ -63,4 +65,11 @@ class EnterpriseRegistrationController < ApplicationController @create_enterprise.save! end + # Records the enterprise and presents a confirmation message + # saying to the user that the enterprise was created. + def creation + @create_enterprise.perform + @enterprise = @create_enterprise.target.profiles.find_by_identifier(@create_enterprise.identifier) + end + end diff --git a/app/helpers/features_helper.rb b/app/helpers/features_helper.rb index 98a79bb..25c6ac8 100644 --- a/app/helpers/features_helper.rb +++ b/app/helpers/features_helper.rb @@ -3,6 +3,7 @@ module FeaturesHelper choices = [ [ _('Administrator must approve all new organizations'), 'admin'], [ _('Administrator assigns validator organizations per region.'), 'region'], + [ _('All new organizations are approve by default'), 'none'], ] value = instance_variable_get("@#{object}").send(method).to_s select_tag("#{object}[#{method}]", options_for_select(choices, value)) diff --git a/app/models/environment.rb b/app/models/environment.rb index af3280b..977a1f0 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -275,6 +275,7 @@ class Environment < ActiveRecord::Base # * :region: organization registering must be approved by some other # organization asssigned as validator to the Region the new organization # belongs to. + # * :none: organization registration is approved by default. # # Trying to set organization_approval_method to any other value will raise an # ArgumentError. @@ -287,6 +288,7 @@ class Environment < ActiveRecord::Base accepted_values = %w[ admin region + none ].map(&:to_sym) raise ArgumentError unless accepted_values.include?(actual_value) diff --git a/app/views/enterprise_registration/creation.rhtml b/app/views/enterprise_registration/creation.rhtml new file mode 100644 index 0000000..aae75da --- /dev/null +++ b/app/views/enterprise_registration/creation.rhtml @@ -0,0 +1,9 @@ +

<%= _('Enterprise registration completed') %>

+ +

+<%= _("Your enterprise (%s) was successfully registered.") % @enterprise.name %> +

+ +

+<%= link_to _('You can manage your enterprise now.'), @enterprise.admin_url %> +

diff --git a/app/views/search/enterprises.rhtml b/app/views/search/enterprises.rhtml index 4ee954f..846e406 100644 --- a/app/views/search/enterprises.rhtml +++ b/app/views/search/enterprises.rhtml @@ -15,6 +15,12 @@ <%= render :partial => 'search_form', :locals => { :form_title => _("Refine your search"), :simple_search => true } %> +<% if logged_in? && environment.enabled?('enterprise_registration') %> + <% button_bar do %> + <%= button(:add, __('New enterprise'), {:controller => 'enterprise_registration'}) %> + <% end %> +<% end %> + <% if @categories_menu %>
<% end %> diff --git a/features/register_enterprise.feature b/features/register_enterprise.feature index 3e0d887..23b2c37 100644 --- a/features/register_enterprise.feature +++ b/features/register_enterprise.feature @@ -192,3 +192,12 @@ Feature: register enterprise And I am on Joao Silva's control panel When I follow "Manage my groups" Then I should not see "My Enterprise" + + Scenario: a user can see button to register new enterprise + When I am on /assets/enterprises + Then I should see "New enterprise" link + + Scenario: a user cant see button to register new enterprise if enterprise_registration disabled + Given feature "enterprise_registration" is disabled on environment + When I am on /assets/enterprises + Then I should not see "New enterprise" link diff --git a/test/functional/enterprise_registration_controller_test.rb b/test/functional/enterprise_registration_controller_test.rb index f323d34..1adc76c 100644 --- a/test/functional/enterprise_registration_controller_test.rb +++ b/test/functional/enterprise_registration_controller_test.rb @@ -49,6 +49,19 @@ all_fixtures assert_template 'confirmation' end + should 'skip prompt for selection validator if approval method is none' do + env = Environment.default + env.organization_approval_method = :none + env.save + region = fast_create(Region) + + data = { :name => 'My new enterprise', :identifier => 'mynew', :region => region } + create_enterprise = CreateEnterprise.new(data) + + post :index, :create_enterprise => data + assert_template 'creation' + end + should 'prompt for selecting validator if approval method is region' do env = Environment.default env.organization_approval_method = :region @@ -77,7 +90,7 @@ all_fixtures # all data but validator selected create_enterprise.expects(:valid_before_selecting_target?).returns(true) - create_enterprise.expects(:valid?).returns(false) + create_enterprise.stubs(:valid?).returns(false) post :index, :create_enterprise => data assert_template 'select_validator' @@ -93,7 +106,7 @@ all_fixtures validator = mock() validator.stubs(:name).returns("lalala") create_enterprise.expects(:valid_before_selecting_target?).returns(true) - create_enterprise.expects(:valid?).returns(true) # validator already selected + create_enterprise.stubs(:valid?).returns(true) # validator already selected create_enterprise.expects(:save!) create_enterprise.expects(:target).returns(validator) diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index a6cff84..a2a6a31 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -241,6 +241,7 @@ class EnvironmentTest < Test::Unit::TestCase valid = %w[ admin region + none ].each do |item| env.organization_approval_method = item env.organization_approval_method = item.to_sym -- libgit2 0.21.2