From e9fe9d72a0d4e69e4bd23b5bb23544912319ec61 Mon Sep 17 00:00:00 2001 From: henning mueller Date: Tue, 4 Feb 2014 03:13:57 +0100 Subject: [PATCH] Do not use current_mailbox as begin of association chain for domain, again. --- app/controllers/admin/domains_controller.rb | 13 +++++-------- app/helpers/application_helper.rb | 2 +- app/models/domain.rb | 12 ++++++++++++ app/models/mailbox.rb | 12 ------------ app/views/admin/aliases/edit.html.haml | 2 +- app/views/admin/domains/index.html.haml | 4 ++-- app/views/admin/mailboxes/edit.html.haml | 2 +- 7 files changed, 22 insertions(+), 25 deletions(-) diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index fd03106..5752d6f 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -4,7 +4,7 @@ class Admin::DomainsController < AdminController inherit_resources - actions :all, except: :show + actions :all, except: [:show, :index] def create create! do |success, error| @@ -25,17 +25,14 @@ def destroy end =end + def index + @domains = Domain.managable current_mailbox + end + def update update! do |success, error| success.html { redirect_to [:edit, :admin, resource] } end end - - private - - def begin_of_association_chain - current_mailbox - end - end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 439b7e7..1ebf012 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -5,7 +5,7 @@ def active_navigation(controller) end def domains - @domains ||= current_mailbox.domains + @domains ||= Domain.managable current_mailbox end def flash_class(type) diff --git a/app/models/domain.rb b/app/models/domain.rb index b90b98a..4ea406d 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -62,4 +62,16 @@ def self.default domain end + def self.managable(mailbox) + if mailbox.admin? + Domain + else + Domain.includes(:permissions).where(' + (permissions.role = "editor" or permissions.role = "owner") + and subject_id = ?', + mailbox.id + ) + end + end + end diff --git a/app/models/mailbox.rb b/app/models/mailbox.rb index 43cca0c..bde26ee 100644 --- a/app/models/mailbox.rb +++ b/app/models/mailbox.rb @@ -62,18 +62,6 @@ def mailboxes_for_select domains.map(&:mailboxes_for_select).flatten(1) end - def domains - if admin? - Domain - else - Domain.includes(:permissions).where(' - (permissions.role = "editor" or permissions.role = "owner") - and subject_id = ?', - id - ) - end - end - def manager? permissions.any? || admin? end diff --git a/app/views/admin/aliases/edit.html.haml b/app/views/admin/aliases/edit.html.haml index 1308335..4a98a08 100644 --- a/app/views/admin/aliases/edit.html.haml +++ b/app/views/admin/aliases/edit.html.haml @@ -15,7 +15,7 @@ .col-md-6 = f.input :id, disabled: true, label: 'ID' = f.input :username - = f.association :domain, include_blank: false + = f.association :domain, collection: domains.all, include_blank: false = f.input :description = f.input :active .col-md-6 diff --git a/app/views/admin/domains/index.html.haml b/app/views/admin/domains/index.html.haml index 457455e..cad5d8c 100644 --- a/app/views/admin/domains/index.html.haml +++ b/app/views/admin/domains/index.html.haml @@ -5,7 +5,7 @@ %p Got - = pluralize domains.count, 'domain' + = pluralize collection.count, 'domain' %table.table.table-striped %thead @@ -22,4 +22,4 @@ %th Catch-All %th %tbody - = render collection + = render collection.all diff --git a/app/views/admin/mailboxes/edit.html.haml b/app/views/admin/mailboxes/edit.html.haml index b7f1bea..d973af8 100644 --- a/app/views/admin/mailboxes/edit.html.haml +++ b/app/views/admin/mailboxes/edit.html.haml @@ -14,7 +14,7 @@ %legend Account Information = f.input :id, disabled: true, label: 'ID' = f.input :username, hint: 'Note, that changing the username or domain currently requires manually moving the mail_location!' - = f.association :domain, include_blank: false + = f.association :domain, collection: domains.all, include_blank: false = f.input :name .well