From ab1ed164358604a2d09cd5d8607a165c9e31086d Mon Sep 17 00:00:00 2001 From: Pierre de Lacroix Date: Wed, 13 Sep 2017 23:01:11 +0200 Subject: [PATCH 1/5] Add a migration to change Spree::Users enterprise_limit default value from 1 to 5 --- ...ange_default_value_of_spree_users_enterprise_limit.rb | 9 +++++++++ db/schema.rb | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20170913205345_change_default_value_of_spree_users_enterprise_limit.rb diff --git a/db/migrate/20170913205345_change_default_value_of_spree_users_enterprise_limit.rb b/db/migrate/20170913205345_change_default_value_of_spree_users_enterprise_limit.rb new file mode 100644 index 0000000000..2db2182d9c --- /dev/null +++ b/db/migrate/20170913205345_change_default_value_of_spree_users_enterprise_limit.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index f87b0009d9..19204bbb1d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" From 5c046b76f0752267998b67278581a1744e887483 Mon Sep 17 00:00:00 2001 From: Pierre de Lacroix Date: Thu, 21 Sep 2017 18:33:55 +0200 Subject: [PATCH 2/5] Fix failing tests --- spec/features/admin/enterprise_user_spec.rb | 2 +- spec/features/admin/enterprises_spec.rb | 2 +- spec/models/enterprise_spec.rb | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/spec/features/admin/enterprise_user_spec.rb b/spec/features/admin/enterprise_user_spec.rb index 232ffb68ae..85a72e0c8f 100644 --- a/spec/features/admin/enterprise_user_spec.rb +++ b/spec/features/admin/enterprise_user_spec.rb @@ -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 + user.enterprise_limit.should == 5 login_to_admin_section click_link 'Users' click_link user.email diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb index 228cce3b1e..8343c03244 100644 --- a/spec/features/admin/enterprises_spec.rb +++ b/spec/features/admin/enterprises_spec.rb @@ -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 diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 560103eaa7..e372550c87 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -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 From d52f9fd43f7694a0802d0dfc3a2a846667da64d7 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley Date: Tue, 23 Jan 2018 20:02:55 +0000 Subject: [PATCH 3/5] Add enterprise limit modal --- .../enterprises/directives/enterprise_limit.js.coffee | 11 +++++++++++ app/views/admin/enterprises/_admin_index.html.haml | 2 +- .../enterprises/_enterprise_user_index.html.haml | 2 +- app/views/admin/enterprises/index.html.haml | 10 +++++++--- config/locales/en.yml | 1 + 5 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 app/assets/javascripts/admin/enterprises/directives/enterprise_limit.js.coffee diff --git a/app/assets/javascripts/admin/enterprises/directives/enterprise_limit.js.coffee b/app/assets/javascripts/admin/enterprises/directives/enterprise_limit.js.coffee new file mode 100644 index 0000000000..6bd2135030 --- /dev/null +++ b/app/assets/javascripts/admin/enterprises/directives/enterprise_limit.js.coffee @@ -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 diff --git a/app/views/admin/enterprises/_admin_index.html.haml b/app/views/admin/enterprises/_admin_index.html.haml index 5e1eb4c92c..3376601aaa 100644 --- a/app/views/admin/enterprises/_admin_index.html.haml +++ b/app/views/admin/enterprises/_admin_index.html.haml @@ -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%;"}/ diff --git a/app/views/admin/enterprises/_enterprise_user_index.html.haml b/app/views/admin/enterprises/_enterprise_user_index.html.haml index b4bc32d2ad..4129da6b93 100644 --- a/app/views/admin/enterprises/_enterprise_user_index.html.haml +++ b/app/views/admin/enterprises/_enterprise_user_index.html.haml @@ -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 diff --git a/app/views/admin/enterprises/index.html.haml b/app/views/admin/enterprises/index.html.haml index a233bc3146..d6e6d0fbb2 100644 --- a/app/views/admin/enterprises/index.html.haml +++ b/app/views/admin/enterprises/index.html.haml @@ -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" diff --git a/config/locales/en.yml b/config/locales/en.yml index c38f528fd7..a00311555a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2203,6 +2203,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using resolve_errors: Please resolve the following errors more_items: "+ %{count} More" admin: + enterprise_limit_reached: "You have reached your enterprise limit. Write to %{contact_email} if you need to increase it." modals: got_it: Got it tag_rule_help: From 3c5b01ece07eb4a892c95e85886f48e1717537f3 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley Date: Tue, 23 Jan 2018 20:47:18 +0000 Subject: [PATCH 4/5] Update enterprise limit spec --- spec/features/admin/enterprises_spec.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb index 8343c03244..448933bac7 100644 --- a/spec/features/admin/enterprises_spec.rb +++ b/spec/features/admin/enterprises_spec.rb @@ -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 From 237854c781a40701b03105e2315a90cd4f138f4f Mon Sep 17 00:00:00 2001 From: Matt-Yorkley Date: Wed, 31 Jan 2018 15:00:02 +0000 Subject: [PATCH 5/5] Update enterprise limit error text and use expect sytnax --- config/locales/en.yml | 2 +- spec/features/admin/enterprise_user_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index a00311555a..bdfc915b86 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2203,7 +2203,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using resolve_errors: Please resolve the following errors more_items: "+ %{count} More" admin: - enterprise_limit_reached: "You have reached your enterprise limit. Write to %{contact_email} if you need to increase it." + 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: diff --git a/spec/features/admin/enterprise_user_spec.rb b/spec/features/admin/enterprise_user_spec.rb index 85a72e0c8f..635b819471 100644 --- a/spec/features/admin/enterprise_user_spec.rb +++ b/spec/features/admin/enterprise_user_spec.rb @@ -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 == 5 + expect(user.enterprise_limit).to eq 5 login_to_admin_section click_link 'Users' click_link user.email