From d07ac84711325ae1720debee47dcb43341a3cb47 Mon Sep 17 00:00:00 2001 From: henning mueller Date: Tue, 25 Feb 2014 12:23:43 +0100 Subject: [PATCH 1/2] Fixed bug which became transparent with rails4 deprecation warning. --- app/models/mailbox.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/mailbox.rb b/app/models/mailbox.rb index 8fde7d6..0184486 100644 --- a/app/models/mailbox.rb +++ b/app/models/mailbox.rb @@ -63,7 +63,7 @@ def manager? # Checks if Mailbox has permissions on associated domain (for spam Aliases). def manager_of_address_domain? - Domain.managable(self).all.include? domain + Domain.managable(self).where(id: domain.id).any? end # Salt of the password hash. From 970cb59f916c30e5aa350f76597a909d52449a2f Mon Sep 17 00:00:00 2001 From: henning mueller Date: Tue, 25 Feb 2014 14:22:38 +0100 Subject: [PATCH 2/2] Fixed some issues raised by pullreview.com. --- app/controllers/admin/aliases_controller.rb | 3 +++ app/controllers/admin/domains_controller.rb | 3 +++ app/controllers/admin/mailboxes_controller.rb | 1 + app/helpers/aliases_helper.rb | 4 +++- app/models/ability.rb | 3 +-- app/models/permission.rb | 4 ++-- app/models/permission/scopes.rb | 2 +- config/deploy.rb | 2 +- config/initializers/devise.rb | 6 +++--- config/initializers/simple_form.rb | 4 ++-- db/seeds.rb | 17 +++++++++-------- lib/permissionable.rb | 4 +++- test/factories/permission.rb | 6 +++--- test/functional/mailboxes_controller_test.rb | 2 +- test/test_helper.rb | 2 +- 15 files changed, 37 insertions(+), 26 deletions(-) diff --git a/app/controllers/admin/aliases_controller.rb b/app/controllers/admin/aliases_controller.rb index f53c7af..d21d933 100644 --- a/app/controllers/admin/aliases_controller.rb +++ b/app/controllers/admin/aliases_controller.rb @@ -1,6 +1,9 @@ +# Aliases controller. class Admin::AliasesController < Admin::AddressesController load_and_authorize_resource :alias, through: :domain + # Build Alias resource (and fill with some defaults, if it should be a spam + # alias). def new if spam? @alias = parent.aliases.build \ diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index 6e56057..f263659 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -6,6 +6,7 @@ class Admin::DomainsController < AdminController actions :all, except: [:show, :index] + # Create Domain and redirect to index. def create super do |success, error| success.html { redirect_to collection_url } @@ -25,10 +26,12 @@ def destroy end =end + # Return only managable domains. def index @domains = Domain.managable current_mailbox end + # Update Domain and redirect to edit form. def update super do |success, error| success.html { redirect_to [:edit, :admin, resource] } diff --git a/app/controllers/admin/mailboxes_controller.rb b/app/controllers/admin/mailboxes_controller.rb index e696add..9242139 100644 --- a/app/controllers/admin/mailboxes_controller.rb +++ b/app/controllers/admin/mailboxes_controller.rb @@ -1,3 +1,4 @@ +# Mailboxes controller. class Admin::MailboxesController < Admin::AddressesController load_and_authorize_resource :mailbox, through: :domain end diff --git a/app/helpers/aliases_helper.rb b/app/helpers/aliases_helper.rb index a490c36..6db6724 100644 --- a/app/helpers/aliases_helper.rb +++ b/app/helpers/aliases_helper.rb @@ -7,12 +7,14 @@ module AliasesHelper def address_list(string) addresses = string.split(',') html = [] - + addresses.each do |a| begin o = Lookup.by_email(a) a = link_to a, [:edit, :admin, o.domain, o] rescue Lookup::Error + # No link, if no Alias or Mailbox is found. + nil end a = content_tag :p, a, class: 'alias-goto-list-item' diff --git a/app/models/ability.rb b/app/models/ability.rb index e2e6c57..e609ab0 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -2,9 +2,8 @@ class Ability include CanCan::Ability + # Define abilities for the passed in mailbox here. def initialize(mailbox) - # Define abilities for the passed in mailbox here. - mailbox ||= Mailbox.new # Not logged in if mailbox.admin? diff --git a/app/models/permission.rb b/app/models/permission.rb index d45e674..0943de3 100644 --- a/app/models/permission.rb +++ b/app/models/permission.rb @@ -4,9 +4,9 @@ class Permission < ActiveRecord::Base include Permission::Validations has_paper_trail - + attr_accessible :subject, :subject_id, :subject_type, :role - + belongs_to :subject, polymorphic: true belongs_to :item, polymorphic: true belongs_to :creator, class_name: 'Mailbox' diff --git a/app/models/permission/scopes.rb b/app/models/permission/scopes.rb index dbbc378..bda460a 100644 --- a/app/models/permission/scopes.rb +++ b/app/models/permission/scopes.rb @@ -8,7 +8,7 @@ module Permission::Scopes item_id: item.id, item_type: item.class.to_s } - + scope :subject, ->(subject) { where \ subject_id: subject.id, diff --git a/config/deploy.rb b/config/deploy.rb index 7d9114b..8bc1a87 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,5 +1,5 @@ require File.expand_path('../../config/environment', __FILE__) - + set :application, Rails.application.class.parent_name.downcase set :hostname, Settings.host diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 7e52b52..a60b26d 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -23,7 +23,7 @@ # session. If you need permissions, you should implement that in a before filter. # You can also supply a hash where the value is a boolean determining whether # or not authentication should be aborted when the value is not present. - config.authentication_keys = [ :username, :domain_id ] + config.authentication_keys = [:username, :domain_id] # Configure parameters from the request object used for authentication. Each entry # given should be a request method and it will automatically be passed to the @@ -35,12 +35,12 @@ # Configure which authentication keys should be case-insensitive. # These keys will be downcased upon creating or modifying a user and when used # to authenticate or find a user. Default is :email. - config.case_insensitive_keys = [ :username ] + config.case_insensitive_keys = [:username] # Configure which authentication keys should have whitespace stripped. # These keys will have whitespace before and after removed upon creating or # modifying a user and when used to authenticate or find a user. Default is :email. - config.strip_whitespace_keys = [ :username ] + config.strip_whitespace_keys = [:username] # Tell if authentication through request.params is enabled. True by default. # It can be set to an array that will enable params authentication only for the diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb index c5a21e0..0241813 100644 --- a/config/initializers/simple_form.rb +++ b/config/initializers/simple_form.rb @@ -32,10 +32,10 @@ def input_html_classes b.use :min_max b.use :maxlength b.use :placeholder - + b.optional :pattern b.optional :readonly - + b.wrapper tag: 'div', class: 'col-md-4 col-xs-12' do |ba| ba.use :label end diff --git a/db/seeds.rb b/db/seeds.rb index a07e204..83e05d7 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,23 +5,24 @@ def rand5; rand(5) + 1; end ActiveRecord::Base.logger = Logger.new($stdout) unless ENV['DEBUG'].blank? -d, p = Domain.create(name: 'example.org'), 'whatever' -alice = d.mailboxes.create username: 'alice', password: p, admin: true -bob = d.mailboxes.create username: 'bob', password: p -carol = d.mailboxes.create username: 'carol', password: p -dan = d.mailboxes.create username: 'dan', password: p +d, p = Domain.create!(name: 'example.org'), 'whatever' +alice = d.mailboxes.create! username: 'alice', password: p, admin: true +bob = d.mailboxes.create! username: 'bob', password: p +carol = d.mailboxes.create! username: 'carol', password: p +dan = d.mailboxes.create! username: 'dan', password: p d.catch_all_address = alice.email d.save! -puts < :mailbox - association :item, :factory => :domain + role { 'owner' } + association :subject, factory: :mailbox + association :item, factory: :domain end end diff --git a/test/functional/mailboxes_controller_test.rb b/test/functional/mailboxes_controller_test.rb index 4db5fee..1361e85 100644 --- a/test/functional/mailboxes_controller_test.rb +++ b/test/functional/mailboxes_controller_test.rb @@ -41,7 +41,7 @@ class MailboxesControllerTest < ActionController::TestCase end should respond_with :redirect - should set_the_flash.to /successfully updated/i + should set_the_flash.to(/successfully updated/i) should 'have new name' do assert_equal 'Foo', @mailbox.name diff --git a/test/test_helper.rb b/test/test_helper.rb index 86d855b..06a06a2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,4 @@ -ENV["RAILS_ENV"] = "test" +ENV['RAILS_ENV'] = 'test' require 'coveralls' Coveralls.wear!