Commit 4c67982418a4546b98bc599c573e2777f354dcf5
Committed by
Joenio Costa
1 parent
ca8b44f6
Exists in
master
and in
22 other branches
Add the possibility to create an enterprise by interface
(ActionItem1542)
Showing
8 changed files
with
54 additions
and
4 deletions
Show diff stats
app/controllers/public/enterprise_registration_controller.rb
| ... | ... | @@ -15,14 +15,16 @@ class EnterpriseRegistrationController < ApplicationController |
| 15 | 15 | if params[:create_enterprise] && params[:create_enterprise][:target_id] |
| 16 | 16 | @create_enterprise.target = Profile.find(params[:create_enterprise][:target_id]) |
| 17 | 17 | end |
| 18 | - elsif @validation == :admin | |
| 18 | + elsif @validation == :admin || @validation == :none | |
| 19 | 19 | @create_enterprise.target = @create_enterprise.environment |
| 20 | 20 | end |
| 21 | 21 | @create_enterprise.requestor = current_user.person |
| 22 | 22 | the_action = |
| 23 | 23 | if request.post? |
| 24 | 24 | if @create_enterprise.valid_before_selecting_target? |
| 25 | - if @create_enterprise.valid? || @validation == :admin | |
| 25 | + if @create_enterprise.valid? && @validation == :none | |
| 26 | + :creation | |
| 27 | + elsif @create_enterprise.valid? || @validation == :admin | |
| 26 | 28 | :confirmation |
| 27 | 29 | else |
| 28 | 30 | :select_validator |
| ... | ... | @@ -63,4 +65,11 @@ class EnterpriseRegistrationController < ApplicationController |
| 63 | 65 | @create_enterprise.save! |
| 64 | 66 | end |
| 65 | 67 | |
| 68 | + # Records the enterprise and presents a confirmation message | |
| 69 | + # saying to the user that the enterprise was created. | |
| 70 | + def creation | |
| 71 | + @create_enterprise.perform | |
| 72 | + @enterprise = @create_enterprise.target.profiles.find_by_identifier(@create_enterprise.identifier) | |
| 73 | + end | |
| 74 | + | |
| 66 | 75 | end | ... | ... |
app/helpers/features_helper.rb
| ... | ... | @@ -3,6 +3,7 @@ module FeaturesHelper |
| 3 | 3 | choices = [ |
| 4 | 4 | [ _('Administrator must approve all new organizations'), 'admin'], |
| 5 | 5 | [ _('Administrator assigns validator organizations per region.'), 'region'], |
| 6 | + [ _('All new organizations are approve by default'), 'none'], | |
| 6 | 7 | ] |
| 7 | 8 | value = instance_variable_get("@#{object}").send(method).to_s |
| 8 | 9 | select_tag("#{object}[#{method}]", options_for_select(choices, value)) | ... | ... |
app/models/environment.rb
| ... | ... | @@ -275,6 +275,7 @@ class Environment < ActiveRecord::Base |
| 275 | 275 | # * <tt>:region</tt>: organization registering must be approved by some other |
| 276 | 276 | # organization asssigned as validator to the Region the new organization |
| 277 | 277 | # belongs to. |
| 278 | + # * <tt>:none</tt>: organization registration is approved by default. | |
| 278 | 279 | # |
| 279 | 280 | # Trying to set organization_approval_method to any other value will raise an |
| 280 | 281 | # ArgumentError. |
| ... | ... | @@ -287,6 +288,7 @@ class Environment < ActiveRecord::Base |
| 287 | 288 | accepted_values = %w[ |
| 288 | 289 | admin |
| 289 | 290 | region |
| 291 | + none | |
| 290 | 292 | ].map(&:to_sym) |
| 291 | 293 | raise ArgumentError unless accepted_values.include?(actual_value) |
| 292 | 294 | ... | ... |
app/views/search/enterprises.rhtml
| ... | ... | @@ -15,6 +15,12 @@ |
| 15 | 15 | |
| 16 | 16 | <%= render :partial => 'search_form', :locals => { :form_title => _("Refine your search"), :simple_search => true } %> |
| 17 | 17 | |
| 18 | +<% if logged_in? && environment.enabled?('enterprise_registration') %> | |
| 19 | + <% button_bar do %> | |
| 20 | + <%= button(:add, __('New enterprise'), {:controller => 'enterprise_registration'}) %> | |
| 21 | + <% end %> | |
| 22 | +<% end %> | |
| 23 | + | |
| 18 | 24 | <% if @categories_menu %> |
| 19 | 25 | <div class="has_cat_list"> |
| 20 | 26 | <% end %> | ... | ... |
features/register_enterprise.feature
| ... | ... | @@ -192,3 +192,12 @@ Feature: register enterprise |
| 192 | 192 | And I am on Joao Silva's control panel |
| 193 | 193 | When I follow "Manage my groups" |
| 194 | 194 | Then I should not see "My Enterprise" |
| 195 | + | |
| 196 | + Scenario: a user can see button to register new enterprise | |
| 197 | + When I am on /assets/enterprises | |
| 198 | + Then I should see "New enterprise" link | |
| 199 | + | |
| 200 | + Scenario: a user cant see button to register new enterprise if enterprise_registration disabled | |
| 201 | + Given feature "enterprise_registration" is disabled on environment | |
| 202 | + When I am on /assets/enterprises | |
| 203 | + Then I should not see "New enterprise" link | ... | ... |
test/functional/enterprise_registration_controller_test.rb
| ... | ... | @@ -49,6 +49,19 @@ all_fixtures |
| 49 | 49 | assert_template 'confirmation' |
| 50 | 50 | end |
| 51 | 51 | |
| 52 | + should 'skip prompt for selection validator if approval method is none' do | |
| 53 | + env = Environment.default | |
| 54 | + env.organization_approval_method = :none | |
| 55 | + env.save | |
| 56 | + region = fast_create(Region) | |
| 57 | + | |
| 58 | + data = { :name => 'My new enterprise', :identifier => 'mynew', :region => region } | |
| 59 | + create_enterprise = CreateEnterprise.new(data) | |
| 60 | + | |
| 61 | + post :index, :create_enterprise => data | |
| 62 | + assert_template 'creation' | |
| 63 | + end | |
| 64 | + | |
| 52 | 65 | should 'prompt for selecting validator if approval method is region' do |
| 53 | 66 | env = Environment.default |
| 54 | 67 | env.organization_approval_method = :region |
| ... | ... | @@ -77,7 +90,7 @@ all_fixtures |
| 77 | 90 | |
| 78 | 91 | # all data but validator selected |
| 79 | 92 | create_enterprise.expects(:valid_before_selecting_target?).returns(true) |
| 80 | - create_enterprise.expects(:valid?).returns(false) | |
| 93 | + create_enterprise.stubs(:valid?).returns(false) | |
| 81 | 94 | |
| 82 | 95 | post :index, :create_enterprise => data |
| 83 | 96 | assert_template 'select_validator' |
| ... | ... | @@ -93,7 +106,7 @@ all_fixtures |
| 93 | 106 | validator = mock() |
| 94 | 107 | validator.stubs(:name).returns("lalala") |
| 95 | 108 | create_enterprise.expects(:valid_before_selecting_target?).returns(true) |
| 96 | - create_enterprise.expects(:valid?).returns(true) # validator already selected | |
| 109 | + create_enterprise.stubs(:valid?).returns(true) # validator already selected | |
| 97 | 110 | create_enterprise.expects(:save!) |
| 98 | 111 | create_enterprise.expects(:target).returns(validator) |
| 99 | 112 | ... | ... |
test/unit/environment_test.rb