This repository has been archived by the owner on Mar 3, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some refactoring to make pullreview.com happier.
- Loading branch information
Showing
41 changed files
with
151 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Domains controller. | ||
class Admin::DomainsController < AdminController | ||
|
||
load_and_authorize_resource | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Permissions controller. | ||
class Admin::PermissionsController < AdminController | ||
|
||
inherit_resources | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Versions controller. | ||
class Admin::VersionsController < AdminController | ||
|
||
load_and_authorize_resource | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Shared code for all admin controllers. | ||
class AdminController < ApplicationController | ||
|
||
authorize_resource | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Mailboxes controller. | ||
class MailboxesController < InheritedResources::Base | ||
|
||
load_and_authorize_resource | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,56 @@ | ||
# Shared helpers for Alias and Mailbox models. | ||
module AddressesHelper | ||
|
||
class DomainNotFound < StandardError | ||
end | ||
|
||
class AddressNotFound < StandardError | ||
end | ||
|
||
|
||
def parent | ||
Domain.where(id: params[:domain_id]).first | ||
end | ||
|
||
def link_to_alias_or_mailbox(email_or_object) | ||
return nil if email_or_object.blank? | ||
|
||
if email_or_object.is_a? Alias or email_or_object.is_a? Mailbox | ||
o = email_or_object | ||
email = o.email | ||
else | ||
username, domain = email_or_object.split('@') | ||
domain = Domain.where(name: domain).first | ||
begin | ||
email, o = email_and_object(email_or_object) | ||
rescue DomainNotFound, AddressNotFound | ||
return email_or_object | ||
end | ||
|
||
return email_or_object if domain.nil? | ||
link_to email, [:edit, :admin, o.domain, o] | ||
end | ||
|
||
o = domain.aliases.where(username: username).first | ||
o ||= domain.mailboxes.where(username: username).first | ||
|
||
return email_or_object if o.nil? | ||
private | ||
|
||
email = email_or_object | ||
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 | ||
email, o = search_object_by_email(email_or_object) | ||
end | ||
|
||
link_to email, [:edit, :admin, o.domain, o] | ||
[email, o] | ||
end | ||
|
||
def search_object_by_email(email) | ||
username, domain = email.split('@') | ||
domain = Domain.where(name: domain).first | ||
|
||
raise DomainNotFound if domain.nil? | ||
|
||
o = domain.aliases.where(username: username).first | ||
o ||= domain.mailboxes.where(username: username).first | ||
|
||
raise AddressNotFound if o.nil? | ||
|
||
[email, o] | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Helper for aliases views. | ||
module AliasesHelper | ||
|
||
include AddressesHelper | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Helper methods available in any view. | ||
module ApplicationHelper | ||
|
||
def active_navigation(controller) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Helper for domains views. | ||
module DomainsHelper | ||
|
||
def link_to_domain(domain) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Helper for mailboxes views. | ||
module MailboxesHelper | ||
|
||
include AddressesHelper | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Domain model. | ||
class Domain < ActiveRecord::Base | ||
|
||
include Permissionable | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Permission model. | ||
class Permission < ActiveRecord::Base | ||
|
||
ROLES = %w(owner editor) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Relocation model for moving of mailbox directories. | ||
class Relocation < ActiveRecord::Base | ||
|
||
belongs_to :mailbox | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Shared validations for Alias and Mailbox models. | ||
module AddressValidations | ||
|
||
extend ActiveSupport::Concern | ||
|
||
included do | ||
validates :username, | ||
presence: true, | ||
uniqueness: { | ||
scope: :domain_id, | ||
message: 'Combination of username and domain is not unique.' | ||
}, | ||
format: { | ||
with: /\A[a-zA-Z0-9.\-_]+\z/, | ||
message: 'Username contains invalid characters.' | ||
}, | ||
exclusion: { | ||
in: Settings.blocked_usernames, | ||
message: 'Username is blocked.' | ||
} | ||
|
||
validates :domain_id, presence: true | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.