diff options
| -rw-r--r-- | app/controllers/users_controller.rb | 6 | ||||
| -rw-r--r-- | app/controllers/v1/users_controller.rb | 8 | ||||
| -rw-r--r-- | app/views/common/_action_buttons.html.haml | 9 | ||||
| -rw-r--r-- | config/defaults.yml | 1 | ||||
| -rw-r--r-- | test/functional/users_controller_test.rb | 7 | ||||
| -rw-r--r-- | test/functional/v1/users_controller_test.rb | 8 | 
6 files changed, 33 insertions, 6 deletions
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5951413..a623653 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -26,7 +26,11 @@ class UsersController < UsersBaseController    end    def new -    @user = User.new +    if APP_CONFIG[:allow_registration] +      @user = User.new +    else +      redirect_to home_path +    end    end    def show diff --git a/app/controllers/v1/users_controller.rb b/app/controllers/v1/users_controller.rb index 006e6d8..881708a 100644 --- a/app/controllers/v1/users_controller.rb +++ b/app/controllers/v1/users_controller.rb @@ -19,8 +19,12 @@ module V1      end      def create -      @user = Account.create(params[:user]) -      respond_with @user # return ID instead? +      if APP_CONFIG[:allow_registration] +        @user = Account.create(params[:user]) +        respond_with @user # return ID instead? +      else +        head :forbidden +      end      end      def update diff --git a/app/views/common/_action_buttons.html.haml b/app/views/common/_action_buttons.html.haml index 266abe1..81ebf67 100644 --- a/app/views/common/_action_buttons.html.haml +++ b/app/views/common/_action_buttons.html.haml @@ -3,9 +3,12 @@      .login.span4        %span.link= btn icon('ok-sign') + t(:login), login_path        %span.info= t(:login_info, default: "") -    .signup.span4 -      %span.link= btn icon('user') + t(:signup), signup_path -      %span.info= t(:signup_info, default: "") +    - if APP_CONFIG[:allow_registration] +      .signup.span4 +        %span.link= btn icon('user') + t(:signup), signup_path +        %span.info= t(:signup_info, default: "") +    - else +      .signup.span4      .help.span4        %span.link= btn icon('question-sign') + t(:get_help), new_ticket_path        %span.info= t(:support_info, default: "") diff --git a/config/defaults.yml b/config/defaults.yml index 0614d1e..42c7be9 100644 --- a/config/defaults.yml +++ b/config/defaults.yml @@ -49,6 +49,7 @@ common: &common    engines:      - support      - billing +  allow_registration: true  service_levels: &service_levels    service_levels: diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 0713836..4af9ca6 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -162,4 +162,11 @@ class UsersControllerTest < ActionController::TestCase      assert !assigns(:user).enabled?    end +  test "new redirects if registration is closed" do +    with_config(allow_registration: false) do +      get :new +      assert_response :redirect +      assert_redirected_to home_path +    end +  end  end diff --git a/test/functional/v1/users_controller_test.rb b/test/functional/v1/users_controller_test.rb index 7cd9b0c..fe3cfe7 100644 --- a/test/functional/v1/users_controller_test.rb +++ b/test/functional/v1/users_controller_test.rb @@ -71,4 +71,12 @@ class V1::UsersControllerTest < ActionController::TestCase      assert assigns(:users)    end +  test "create returns forbidden if registration is closed" do +    user_attribs = record_attributes_for :user +    with_config(allow_registration: false) do +      post :create, :user => user_attribs, :format => :json +      assert_response :forbidden +    end +  end +  end  | 
