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

Commit

Permalink
Merge branch 'master' into rails4
Browse files Browse the repository at this point in the history
Conflicts:
	app/models/permission.rb
  • Loading branch information
nning committed Feb 25, 2014
2 parents 8d349cb + 970cb59 commit 46077dd
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 22 deletions.
3 changes: 3 additions & 0 deletions app/controllers/admin/aliases_controller.rb
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/admin/domains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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] }
Expand Down
1 change: 1 addition & 0 deletions app/controllers/admin/mailboxes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Mailboxes controller.
class Admin::MailboxesController < Admin::AddressesController
load_and_authorize_resource :mailbox, through: :domain

Expand Down
4 changes: 3 additions & 1 deletion app/helpers/aliases_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 1 addition & 2 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion app/models/permission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Permission < ActiveRecord::Base
include Permission::Validations

has_paper_trail

belongs_to :subject, polymorphic: true
belongs_to :item, polymorphic: true
belongs_to :creator, class_name: 'Mailbox'
Expand Down
2 changes: 1 addition & 1 deletion app/models/permission/scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion config/deploy.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require File.expand_path('../../config/environment', __FILE__)

set :application, Rails.application.class.parent_name.downcase
set :hostname, Settings.host

Expand Down
4 changes: 2 additions & 2 deletions config/initializers/simple_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<O
$stdout << "
Created mailboxes
alice@example.org with admin rights,
bob@example.org as owner of some domains,
carol@example.org as editor of some domains,
dan@example.org without special rights
(all with password "#{p}")
O
(all with password #{p})
"

rand5.times do
d = FactoryGirl.create :domain
Expand Down
4 changes: 3 additions & 1 deletion lib/permissionable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ module Permissionable
included do
has_many :permissions, as: :item
end


# Dummy method for easier use in simple_form.
def permissions_count
permissions.count
end

# Does a Mailbox have at least role permission?
def permission?(role, mailbox)
# Deny if mailbox is nil.
return false unless mailbox
Expand Down
6 changes: 3 additions & 3 deletions test/factories/permission.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FactoryGirl.define do
factory :permission do
role { "owner" }
association :subject, :factory => :mailbox
association :item, :factory => :domain
role { 'owner' }
association :subject, factory: :mailbox
association :item, factory: :domain
end
end
2 changes: 1 addition & 1 deletion test/functional/mailboxes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ENV["RAILS_ENV"] = "test"
ENV['RAILS_ENV'] = 'test'

require 'coveralls'
Coveralls.wear!
Expand Down

0 comments on commit 46077dd

Please sign in to comment.