Merge pull request #2053 from Matt-Yorkley/uk/enterprise_limit

Increase default enterprise limit
This commit is contained in:
Enrico Stano
2018-03-01 14:40:24 +01:00
committed by GitHub
10 changed files with 46 additions and 14 deletions

View File

@@ -0,0 +1,11 @@
angular.module('admin.enterprises').directive 'enterpriseLimit', (InfoDialog) ->
restrict: 'A'
scope: {
limit_reached: '=enterpriseLimit',
modal_message: '@modalMessage'
}
link: (scope, element, attr) ->
element.bind 'click', (event)->
if scope.limit_reached
event.preventDefault()
InfoDialog.open 'error', scope.modal_message

View File

@@ -2,7 +2,7 @@
- if flash[:action]
%p= flash[:action]
= form_for @enterprise_set, url: main_app.bulk_update_admin_enterprises_path, html: {"ng-app" => "admin.enterprises"} do |f|
= form_for @enterprise_set, url: main_app.bulk_update_admin_enterprises_path do |f|
%table#listing_enterprises.index
%colgroup
%col{style: "width: 25%;"}/

View File

@@ -1,4 +1,4 @@
%div{ ng: { app: 'admin.enterprises', controller: 'enterprisesCtrl' } }
%div{ ng: { controller: 'enterprisesCtrl' } }
.row{ 'ng-hide' => '!loaded' }
.controls{ :class => "sixteen columns alpha", :style => "margin-bottom: 15px;" }
.four.columns.alpha

View File

@@ -1,12 +1,16 @@
- content_for :page_title do
= t('.title')
- content_for :app_wrapper_attrs do
= "ng-app='admin.enterprises'"
- content_for :page_actions do
= render 'admin/shared/user_guide_link'
- if spree_current_user.can_own_more_enterprises?
%li#new_product_link
= button_link_to t('.new_enterprise'), main_app.new_admin_enterprise_path, icon: 'icon-plus', id: 'admin_new_enterprise_link'
%li#new_product_link
- button_href = spree_current_user.can_own_more_enterprises? ? main_app.new_admin_enterprise_path : '#'
- modal_message = t('js.admin.enterprise_limit_reached', contact_email: ContentConfig.footer_email)
= button_link_to t('.new_enterprise'), button_href, icon: 'icon-plus', id: 'admin_new_enterprise_link', 'enterprise-limit' => !spree_current_user.can_own_more_enterprises?, 'modal-message' => modal_message
= admin_inject_monthly_bill_description
= admin_inject_column_preferences module: 'admin.enterprises', action: "enterprises_index"

View File

@@ -2211,6 +2211,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
closes: closes
closed: closed
admin:
enterprise_limit_reached: "You have reached the standard limit of enterprises per account. Write to %{contact_email} if you need to increase it."
modals:
got_it: Got it
tag_rule_help:

View File

@@ -0,0 +1,9 @@
class ChangeDefaultValueOfSpreeUsersEnterpriseLimit < ActiveRecord::Migration
def up
change_column :spree_users, :enterprise_limit, :integer, default: 5
end
def down
change_column :spree_users, :enterprise_limit, :integer, default: 1
end
end

View File

@@ -1029,7 +1029,7 @@ ActiveRecord::Schema.define(:version => 20180204235108) do
t.string "spree_api_key", :limit => 48
t.datetime "reset_password_sent_at"
t.string "api_key", :limit => 40
t.integer "enterprise_limit", :default => 1, :null => false
t.integer "enterprise_limit", :default => 5, :null => false
t.string "locale", :limit => 5
t.string "confirmation_token"
t.datetime "confirmed_at"

View File

@@ -19,7 +19,7 @@ feature %q{
describe "creating an enterprise user" do
context "with a limitted number of owned enterprises" do
scenario "setting the enterprise ownership limit" do
user.enterprise_limit.should == 1
expect(user.enterprise_limit).to eq 5
login_to_admin_section
click_link 'Users'
click_link user.email

View File

@@ -301,7 +301,7 @@ feature %q{
let(:distributor1) { create(:distributor_enterprise, name: 'First Distributor') }
let(:distributor2) { create(:distributor_enterprise, name: 'Another Distributor') }
let(:distributor3) { create(:distributor_enterprise, name: 'Yet Another Distributor') }
let(:enterprise_user) { create_enterprise_user }
let(:enterprise_user) { create_enterprise_user(enterprise_limit: 1) }
let!(:er) { create(:enterprise_relationship, parent: distributor3, child: distributor1, permissions_list: [:edit_profile]) }
before(:each) do
@@ -312,7 +312,7 @@ feature %q{
end
context "when I have reached my enterprise ownership limit" do
it "does not display the link to create a new enterprise" do
it "shows a 'limit reached' modal message when trying to create a new enterprise" do
supplier1.reload
enterprise_user.owned_enterprises.push [supplier1]
@@ -320,7 +320,13 @@ feature %q{
page.should have_content supplier1.name
page.should have_content distributor1.name
expect(find("#content-header")).to_not have_link "New Enterprise"
within 'li#new_product_link' do
expect(page).to have_link 'New Enterprise', href: '#'
click_link 'New Enterprise'
end
expect(page).to have_content I18n.t('js.admin.enterprise_limit_reached', contact_email: ContentConfig.footer_email)
end
end

View File

@@ -99,13 +99,14 @@ describe Enterprise do
end
it "validates ownership limit" do
expect(u1.enterprise_limit).to be 1
expect(u1.enterprise_limit).to be 5
expect(u1.owned_enterprises(:reload)).to eq [e]
e2 = create(:enterprise, owner: u2 )
expect{
4.times { create(:enterprise, owner: u1) }
e2 = create(:enterprise, owner: u2)
expect {
e2.owner = u1
e2.save!
}.to raise_error ActiveRecord::RecordInvalid, "Validation failed: #{u1.email} is not permitted to own any more enterprises (limit is 1)."
}.to raise_error ActiveRecord::RecordInvalid, "Validation failed: #{u1.email} is not permitted to own any more enterprises (limit is 5)."
end
end
end