Contact - Registrar relation

This commit is contained in:
Andres Keskküla 2014-10-07 16:14:36 +03:00
parent 9519538744
commit 3d652bf85b
11 changed files with 90 additions and 16 deletions

View file

@ -2,7 +2,7 @@ class Client::ContactsController < ClientController
before_action :set_contact, only: [:show, :destroy, :edit, :update]
def index
@q = Contact.search(params[:q])
@q = Contact.current_registrars(current_registrar.id).search(params[:q])
@contacts = @q.result.page(params[:page])
end
@ -11,9 +11,17 @@ class Client::ContactsController < ClientController
@contact.build_address
end
def show
if @contact.registrar != current_registrar
flash[:alert] = I18n.t('shared.authentication_error')
redirect_to client_contacts_path
end
end
def create
@contact = Contact.new(contact_params)
@contact.generate_code
@contact.registrar = current_registrar
if @contact.save
flash[:notice] = I18n.t('shared.contact_added')
redirect_to [:client, @contact]

View file

@ -2,6 +2,7 @@ module Epp::ContactsHelper
def create_contact
@contact = Contact.new(contact_and_address_attributes)
@contact.generate_code
@contact.registrar = current_epp_user.registrar
render '/epp/contacts/create' and return if stamp(@contact) && @contact.save
handle_errors(@contact)
@ -113,7 +114,8 @@ module Epp::ContactsHelper
def owner?
return false unless find_contact
return true if current_epp_user.registrar == find_contact.created_by.try(:registrar)
#return true if current_epp_user.registrar == find_contact.created_by.try(:registrar)
return true if @contact.registrar == current_epp_user.registrar
epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error') }
false
end

View file

@ -13,12 +13,14 @@ class Contact < ActiveRecord::Base
has_many :domain_contacts
has_many :domains, through: :domain_contacts
# TODO remove the x_by
belongs_to :created_by, class_name: 'EppUser', foreign_key: :created_by_id
belongs_to :updated_by, class_name: 'EppUser', foreign_key: :updated_by_id
belongs_to :registrar
accepts_nested_attributes_for :address, :disclosure
validates :code, :phone, :email, :ident, :address, presence: true
validates :code, :phone, :email, :ident, :address, :registrar,presence: true
validate :ident_must_be_valid
#validate :presence_of_one_address
@ -33,6 +35,8 @@ class Contact < ActiveRecord::Base
delegate :street, to: :address#, prefix: true
delegate :zip, to: :address#, prefix: true
#scopes
scope :current_registrars, ->(id) { where(registrar_id: id) }
# archiving
has_paper_trail class_name: 'ContactVersion'

View file

@ -4,6 +4,7 @@ class Registrar < ActiveRecord::Base
has_many :ns_sets
has_many :epp_users
has_many :users
has_many :contacts
validates :name, :reg_no, :address, :country, presence: true
validates :name, :reg_no, uniqueness: true