diff --git a/app.rb b/app.rb index 6b827ace..94e67062 100644 --- a/app.rb +++ b/app.rb @@ -557,6 +557,8 @@ end def require_ownership_for_settings @site = Site[username: params[:username]] + not_found if @site.nil? + unless @site.owned_by? parent_site flash[:error] = 'Cannot edit this site, you do not have permission.' redirect request.referrer diff --git a/models/site.rb b/models/site.rb index 6252282e..e791efca 100644 --- a/models/site.rb +++ b/models/site.rb @@ -92,7 +92,7 @@ class Site < Sequel::Model SUGGESTIONS_LIMIT = 32 SUGGESTIONS_VIEWS_MIN = 500 - CHILD_SITES_MAX = 1000 + CHILD_SITES_MAX = 100 PLAN_FEATURES[:catbus] = PLAN_FEATURES[:fatcat].merge( name: 'Cat Bus', @@ -149,7 +149,7 @@ class Site < Sequel::Model one_to_many :children, :key => :parent_site_id, :class => self def account_sites_dataset - Site.where(Sequel.|({id: owner.id}, {parent_site_id: owner.id})) + Site.where(Sequel.|({id: owner.id}, {parent_site_id: owner.id})).order(:parent_site_id.desc, :username) end def account_sites @@ -199,6 +199,8 @@ class Site < Sequel::Model else site = self[username: username_or_email] end + return nil if site.nil? || site.is_banned || site.owner.is_banned + site end end @@ -343,6 +345,12 @@ class Site < Sequel::Model end end + def ban_all_sites_on_account! + DB.transaction { + account_sites.all {|site| site.ban! } + } + end + =begin def follows_dataset super.where(Sequel.~(site_id: blocking_site_ids)) @@ -679,8 +687,8 @@ class Site < Sequel::Model errors.add :domain, "Domain provided is already being used by another site, please choose another." end - if new? && !parent? && CHILD_SITE_MAX == children_dataset.count - errors.add :child_site_id, "Cannot add child site, exceeds #{CHILD_SITE_MAX} limit." + if new? && !parent? && account_sites_dataset.count >= CHILD_SITES_MAX + errors.add :child_site_id, "Cannot add child site, exceeds #{CHILD_SITES_MAX} limit." end end @@ -806,12 +814,12 @@ class Site < Sequel::Model # This returns true even if they end their support plan. def supporter? - !values[:stripe_customer_id].nil? + !owner.values[:stripe_customer_id].nil? end # This will return false if they have ended their plan. def ended_supporter? - values[:plan_ended] + owner.values[:plan_ended] end def plan_name diff --git a/sass/_project-sass/_project-Main.scss b/sass/_project-sass/_project-Main.scss index 6f7c4ee9..7508788d 100644 --- a/sass/_project-sass/_project-Main.scss +++ b/sass/_project-sass/_project-Main.scss @@ -862,4 +862,8 @@ a.tag:hover { .interior .header-Outro.with-columns .col.filter { padding-top: 0px; padding-bottom: 4px; +} + +.dropdown-submenu .dropdown-menu { + width: 1px; } \ No newline at end of file diff --git a/tests/acceptance/settings/site_tests.rb b/tests/acceptance/settings/site_tests.rb index 59c03050..d1bd336d 100644 --- a/tests/acceptance/settings/site_tests.rb +++ b/tests/acceptance/settings/site_tests.rb @@ -80,6 +80,29 @@ def generate_ssl_certs(opts={}) end describe 'site/settings' do + describe 'permissions' do + include Capybara::DSL + + before do + @parent_site = Fabricate :site + @child_site = Fabricate :site, parent_site_id: @parent_site.id + @other_site = Fabricate :site + end + + it 'fails without permissions' do + page.set_rack_session id: @other_site.id + + visit "/settings/#{@parent_site.username}" + page.current_path.must_equal '/' # This could be better + end + + it 'allows child site editing from parent' do + page.set_rack_session id: @parent_site.id + visit "/settings/#{@child_site.username}" + page.current_path.must_equal "/settings/#{@child_site.username}" + end + end + describe 'ssl' do include Capybara::DSL diff --git a/views/_header.erb b/views/_header.erb index 4c6ee1f4..2fa5ab0f 100644 --- a/views/_header.erb +++ b/views/_header.erb @@ -45,7 +45,7 @@ @@ -63,7 +63,6 @@ - <% end %> diff --git a/views/admin.erb b/views/admin.erb index dea9e759..da3a2013 100644 --- a/views/admin.erb +++ b/views/admin.erb @@ -17,7 +17,7 @@
-

Ban User

+

Ban Site

<%== csrf_token_input_html %>

Site Name:

diff --git a/views/settings/account/sites.erb b/views/settings/account/sites.erb index fb061a76..66c73eaf 100644 --- a/views/settings/account/sites.erb +++ b/views/settings/account/sites.erb @@ -1,28 +1,24 @@

Your Sites

-<% if current_site.children_dataset.count == 0 %> -
No other sites are currently linked to this account.
-<% else %> - - <% current_site.owner.account_sites.each do |site| %> - - - - - <% end %> -
- <%= site.title %> - <% if site.parent? %> - (parent account) - <% end %> - - Settings -
-<% end %> + + <% current_site.account_sites_dataset.each do |site| %> + + + + + <% end %> +
+ <%= site.username %> + <% if site.parent? %> + (parent account) + <% end %> + + Settings +

Create New Site

-

You can now create new sites that are linked to this account! Sites will share the free space you have available. You have <%= Site::CHILD_SITES_MAX - current_site.children_dataset.count %> new sites remaining.

+

You can now create new sites that are linked to this account! Sites will share the free space you have available. You have <%= Site::CHILD_SITES_MAX - current_site.account_sites_dataset.count %> new sites remaining.

<%== csrf_token_input_html %> @@ -33,5 +29,4 @@
-
\ No newline at end of file diff --git a/views/settings/site.erb b/views/settings/site.erb index 81ecb94c..a2e744c8 100644 --- a/views/settings/site.erb +++ b/views/settings/site.erb @@ -1,7 +1,7 @@
-

Site Settings

-

<%= @site.username %>

+

Site Settings for <%= @site.username %>

+

Click here to go back to the account menu.