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

Commit

Permalink
Coding style (blank lines, case indentation, parentheses around regex…
Browse files Browse the repository at this point in the history
… arguments).
  • Loading branch information
nning committed Feb 15, 2014
1 parent fddbbf1 commit e56569b
Show file tree
Hide file tree
Showing 43 changed files with 65 additions and 155 deletions.
2 changes: 0 additions & 2 deletions app/controllers/admin/addresses_controller.rb
@@ -1,6 +1,5 @@
# Shared code for Aliases and Mailboxes controller.
class Admin::AddressesController < AdminController

inherit_resources

load_and_authorize_resource :domain
Expand All @@ -17,5 +16,4 @@ class Admin::AddressesController < AdminController
end
end
end

end
2 changes: 0 additions & 2 deletions app/controllers/admin/aliases_controller.rb
@@ -1,5 +1,3 @@
class Admin::AliasesController < Admin::AddressesController

load_and_authorize_resource :alias, through: :domain

end
2 changes: 0 additions & 2 deletions app/controllers/admin/domains_controller.rb
@@ -1,6 +1,5 @@
# Domains controller.
class Admin::DomainsController < AdminController

load_and_authorize_resource

inherit_resources
Expand Down Expand Up @@ -35,5 +34,4 @@ def update
success.html { redirect_to [:edit, :admin, resource] }
end
end

end
2 changes: 0 additions & 2 deletions app/controllers/admin/mailboxes_controller.rb
@@ -1,5 +1,3 @@
class Admin::MailboxesController < Admin::AddressesController

load_and_authorize_resource :mailbox, through: :domain

end
2 changes: 0 additions & 2 deletions app/controllers/admin/permissions_controller.rb
@@ -1,6 +1,5 @@
# Permissions controller.
class Admin::PermissionsController < AdminController

inherit_resources
actions :all, except: :show

Expand All @@ -21,5 +20,4 @@ def create
rescue
redirect_to [:new, :admin, parent, :permission], flash: { error: 'Permission already existing.' }
end

end
2 changes: 0 additions & 2 deletions app/controllers/admin/versions_controller.rb
@@ -1,6 +1,5 @@
# Versions controller.
class Admin::VersionsController < AdminController

load_and_authorize_resource

inherit_resources
Expand All @@ -21,5 +20,4 @@ def revert
redirect_to [:admin, :versions], flash: { error: "Impossible to revert #{@version.event}." }
end
end

end
2 changes: 0 additions & 2 deletions app/controllers/admin_controller.rb
@@ -1,6 +1,5 @@
# Shared code for all admin controllers.
class AdminController < ApplicationController

authorize_resource

before_filter :access?
Expand All @@ -11,5 +10,4 @@ class AdminController < ApplicationController
def access?
render_404 and return if current_mailbox.nil? || !current_mailbox.manager?
end

end
4 changes: 1 addition & 3 deletions app/controllers/application_controller.rb
@@ -1,12 +1,11 @@
# Application controller.
class ApplicationController < ActionController::Base

check_authorization unless: :devise_controller?

protect_from_forgery

rescue_from CanCan::AccessDenied do |exception|
#redirect_to root_url, flash: { alert: exception.message }
# redirect_to root_url, flash: { alert: exception.message }
render_404
end

Expand All @@ -31,5 +30,4 @@ def render_404
def user_for_paper_trail
mailbox_signed_in? ? current_mailbox : 'Unknown'
end

end
2 changes: 0 additions & 2 deletions app/controllers/development_login_controller.rb
@@ -1,6 +1,5 @@
# DevelopmentLogin controller for quick login in development environment.
class DevelopmentLoginController < ApplicationController

skip_authorization_check

# Change logged in Mailbox in development environment.
Expand All @@ -12,5 +11,4 @@ def update
sign_in mailbox
redirect_to after_sign_in_path_for mailbox
end

end
2 changes: 0 additions & 2 deletions app/controllers/mailboxes_controller.rb
@@ -1,6 +1,5 @@
# Mailboxes controller.
class MailboxesController < InheritedResources::Base

load_and_authorize_resource

# Work-around for something, I did not understand.
Expand All @@ -19,5 +18,4 @@ def update
success.html { redirect_to [:edit, :mailbox] }
end
end

end
2 changes: 0 additions & 2 deletions app/controllers/sessions_controller.rb
@@ -1,6 +1,5 @@
# Sessions controller.
class SessionsController < Devise::SessionsController

before_filter :prepare_params, only: :create

private
Expand All @@ -19,5 +18,4 @@ def prepare_params

pm.delete(:email)
end

end
18 changes: 6 additions & 12 deletions app/helpers/addresses_helper.rb
@@ -1,9 +1,5 @@
# Shared helpers for Alias and Mailbox models.
module AddressesHelper

class DomainNotFound < StandardError; end
class AddressNotFound < StandardError; end

# A shortcut for Alias or Mailbox Domain.
def parent
resource.domain
Expand All @@ -27,16 +23,14 @@ def link_to_alias_or_mailbox(email_or_object)

# E-Mail address and Alias or Mailbox object as an Array.
def email_and_object(email_or_object)
case email_or_object.class.to_s
when 'Alias', 'Mailbox'
o = email_or_object
email = o.email
else
o = Lookup.by_email(email_or_object)
email = email_or_object
if %w[Alias Mailbox].include? email_or_object.class.to_s
o = email_or_object
email = o.email
else
o = Lookup.by_email(email_or_object)
email = email_or_object
end

[email, o]
end

end
2 changes: 0 additions & 2 deletions app/helpers/aliases_helper.rb
@@ -1,6 +1,5 @@
# Helper for aliases views.
module AliasesHelper

include AddressesHelper

# Insert links to existing Aliases or Mailboxes in String list of E-Mail
Expand All @@ -22,5 +21,4 @@ def address_list(string)

html.join.html_safe
end

end
2 changes: 0 additions & 2 deletions app/helpers/application_helper.rb
@@ -1,6 +1,5 @@
# Helper methods available in any view.
module ApplicationHelper

# Check if controller is currently used. Returns 'active', if it is.
def active_navigation(controller)
'active' if params[:controller] == controller
Expand Down Expand Up @@ -42,5 +41,4 @@ def icon(name, options = {})
name = name.to_s.gsub(/_/, '-')
content_tag :span, nil, class: "glyphicon glyphicon-#{name} #{options[:class]}"
end

end
2 changes: 0 additions & 2 deletions app/helpers/domains_helper.rb
@@ -1,10 +1,8 @@
# Helper for domains views.
module DomainsHelper

# Link to edit action of domain. Argument can be a String or a Domain instance.
def link_to_domain(domain)
domain = Domain.where(name: domain).first if domain.is_a? String
link_to domain.name, [:edit, :admin, domain]
end

end
2 changes: 0 additions & 2 deletions app/helpers/mailboxes_helper.rb
@@ -1,6 +1,5 @@
# Helper for mailboxes views.
module MailboxesHelper

include AddressesHelper

# Link to edit action of Mailbox by id.
Expand All @@ -9,5 +8,4 @@ def link_to_mailbox(id)
m = Mailbox.find(id)
link_to(m, [:edit, :admin, m.domain, m]).html_safe
end

end
2 changes: 0 additions & 2 deletions app/helpers/permissions_helper.rb
@@ -1,6 +1,4 @@
# Helper for permissions views.
module PermissionsHelper

include AddressesHelper

end
49 changes: 24 additions & 25 deletions app/helpers/versions_helper.rb
@@ -1,19 +1,18 @@
# Helper for versions views.
module VersionsHelper

include MailboxesHelper

# Icons for version events.
def icon_for_event(event)
case event
when 'create'
icon :plus
when 'destroy'
icon :trash
when 'update'
icon :edit
else
raise "No icon for event '#{event}'."
when 'create'
icon :plus
when 'destroy'
icon :trash
when 'update'
icon :edit
else
raise "No icon for event '#{event}'."
end
end

Expand All @@ -40,8 +39,9 @@ def link_to_object(version)
html = object.to_s

# Link if object is existing.
if object.persisted? and url = url_for_object(object)
html = link_to object.to_s, url
if object.persisted?
url = url_for_object(object)
html = link_to object.to_s, url if url
end

html.html_safe
Expand All @@ -63,20 +63,20 @@ def summarize_changes(changes)
# URL for link to object referenced by version.
def url_for_object(object)
url_for case object.class.to_s
when 'Domain'
[:edit, :admin, object]
when 'Alias'
[:edit, :admin, object.domain, object]
when 'Mailbox'
[:edit, :admin, object.domain, object]
when 'Permission'
if object.item
[:edit, :admin, object.item, object]
else
return nil
end
when 'Domain'
[:edit, :admin, object]
when 'Alias'
[:edit, :admin, object.domain, object]
when 'Mailbox'
[:edit, :admin, object.domain, object]
when 'Permission'
if object.item
[:edit, :admin, object.item, object]
else
raise "No URL for object class '#{object.class.to_s}'."
return nil
end
else
raise "No URL for object class '#{object.class.to_s}'."
end
end

Expand All @@ -88,5 +88,4 @@ def object_changes_to_hash(version)
end
h
end

end
2 changes: 0 additions & 2 deletions app/models/ability.rb
@@ -1,6 +1,5 @@
# CanCan ability definitions.
class Ability

include CanCan::Ability

def initialize(mailbox)
Expand Down Expand Up @@ -34,5 +33,4 @@ def initialize(mailbox)
end
end
end

end
2 changes: 0 additions & 2 deletions app/models/alias.rb
@@ -1,6 +1,5 @@
# Alias model.
class Alias < ActiveRecord::Base

include AddressValidations

belongs_to :domain
Expand Down Expand Up @@ -34,5 +33,4 @@ def to_s
end
end
end

end
2 changes: 0 additions & 2 deletions app/models/domain.rb
@@ -1,6 +1,5 @@
# Domain model.
class Domain < ActiveRecord::Base

include Permissionable

has_many :aliases, dependent: :destroy
Expand Down Expand Up @@ -80,5 +79,4 @@ def self.managable(mailbox)
)
end
end

end
2 changes: 0 additions & 2 deletions app/models/mailbox.rb
@@ -1,6 +1,5 @@
# Mailbox model (also used for login to Møil).
class Mailbox < ActiveRecord::Base

include AddressValidations

belongs_to :domain
Expand Down Expand Up @@ -101,5 +100,4 @@ def create_relocation
def password_required?
!(persisted? || password.nil? || password_confirmation.nil?)
end

end
2 changes: 0 additions & 2 deletions app/models/permission.rb
@@ -1,6 +1,5 @@
# Permission model.
class Permission < ActiveRecord::Base

ROLES = %w(owner editor)

# Thrown if the last admin/owner tries to remove itself.
Expand Down Expand Up @@ -47,5 +46,4 @@ def to_s
# Return String representation.
"#{s} is #{role} of #{i}"
end

end
2 changes: 0 additions & 2 deletions app/models/relocation.rb
@@ -1,6 +1,5 @@
# Relocation model for moving of mailbox directories.
class Relocation < ActiveRecord::Base

belongs_to :mailbox

attr_accessible :old_username, :old_domain, :mailbox_id
Expand All @@ -20,5 +19,4 @@ class Relocation < ActiveRecord::Base
def perform
"mv /srv/mail/#{old_domain}/#{old_username} /srv/mail/#{mailbox.domain.name}/#{mailbox.username}"
end

end
2 changes: 0 additions & 2 deletions lib/address_validations.rb
@@ -1,6 +1,5 @@
# Shared validations for Alias and Mailbox models.
module AddressValidations

extend ActiveSupport::Concern

included do
Expand All @@ -21,5 +20,4 @@ module AddressValidations

validates :domain_id, presence: true
end

end

0 comments on commit e56569b

Please sign in to comment.