Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Do not use current_mailbox as begin of association chain for domain, …
Browse files Browse the repository at this point in the history
…again.
  • Loading branch information
nning committed Feb 4, 2014
1 parent d9c227e commit e9fe9d7
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 25 deletions.
13 changes: 5 additions & 8 deletions app/controllers/admin/domains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions app/models/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 0 additions & 12 deletions app/models/mailbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/aliases/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/domains/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

%p
Got
= pluralize domains.count, 'domain'
= pluralize collection.count, 'domain'

%table.table.table-striped
%thead
Expand All @@ -22,4 +22,4 @@
%th Catch-All
%th
%tbody
= render collection
= render collection.all
2 changes: 1 addition & 1 deletion app/views/admin/mailboxes/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e9fe9d7

Please sign in to comment.