Remove Registrar from User

This commit is contained in:
Martin Lensment 2014-12-16 15:58:34 +02:00
parent 9c8fed999d
commit 2c35aa1471
14 changed files with 12 additions and 72 deletions

View file

@ -53,7 +53,7 @@ class Admin::UsersController < AdminController
end
def user_params
params.require(:user).permit(:username, :password, :identity_code, :email, :registrar_id,
:admin, :registrar_typeahead, :country_id)
params.require(:user).permit(:username, :password, :identity_code, :email,
:admin, :country_id)
end
end

View file

@ -3,7 +3,6 @@ class Registrar < ActiveRecord::Base
has_many :domains, dependent: :restrict_with_error
has_many :contacts, dependent: :restrict_with_error
has_many :epp_users, dependent: :restrict_with_error
has_many :users, dependent: :restrict_with_error
has_many :messages
validates :name, :reg_no, :address, :country, presence: true

View file

@ -7,29 +7,19 @@ class User < ActiveRecord::Base
# TODO: Estonian id validation
belongs_to :role
belongs_to :registrar
belongs_to :country
validates :username, :password, presence: true
validates :identity_code, uniqueness: true, allow_blank: true
validates :identity_code, presence: true, if: -> { country.iso == 'EE' }
validates :email, presence: true, if: -> { country.iso != 'EE' }
validates :registrar, presence: true, if: -> { !admin }
validate :validate_identity_code
before_save -> { self.registrar = nil if admin? }
attr_accessor :registrar_typeahead
def to_s
username
end
def registrar_typeahead
@registrar_typeahead || registrar || nil
end
private
def validate_identity_code

View file

@ -44,26 +44,6 @@
%dt= t('shared.billing_address')
%dd= @registrar.billing_address
.row
.col-md-12
#users.panel.panel-default
.panel-heading.clearfix
= t('shared.users')
.table-responsive
%table.table.table-hover.table-bordered.table-condensed
%thead
%tr
%th{class: 'col-xs-3'}= t('shared.username')
%th{class: 'col-xs-3'}= t('shared.email')
%th{class: 'col-xs-3'}= t('shared.identity_code')
%th{class: 'col-xs-3'}= t('shared.admin')
%tbody
- @registrar.users.each do |x|
%tr
%td= link_to(x, [:admin, x])
%td= x.email
%td= x.identity_code
%td= x.admin
.row
.col-md-12

View file

@ -25,13 +25,6 @@
.form-group
= f.label :email
= f.text_field(:email, class: 'form-control')
.form-group
.form-group.has-feedback.js-typeahead-container
= f.label :registrar_typeahead, t('shared.registrar')
= f.text_field(:registrar_typeahead, class: 'form-control js-registrar-typeahead', placeholder: t('shared.registrar'), autocomplete: 'off')
%span.glyphicon.glyphicon-ok.form-control-feedback.js-typeahead-ok.hidden
%span.glyphicon.glyphicon-remove.form-control-feedback.js-typeahead-remove
= f.hidden_field(:registrar_id, class: 'js-registrar-id')
.form-group
.checkbox
%label{for: 'user_admin'}
@ -41,19 +34,3 @@
.row
.col-md-12.text-right
= button_tag(t('shared.save'), class: 'btn btn-primary')
:javascript
Autocomplete.bindAdminRegistrarSearch();
toggleRegistrar();
$('#user_admin').click(function() {
toggleRegistrar();
});
function toggleRegistrar() {
if($('.js-admin').is(':checked')) {
$('.js-registrar-typeahead, .js-registrar-id').attr('disabled', true);
} else {
$('.js-registrar-typeahead, .js-registrar-id').attr('disabled', false);
}
}

View file

@ -19,8 +19,6 @@
= sort_link(@q, 'identity_code', t('shared.identity_code'))
%th{class: 'col-xs-2'}
= sort_link(@q, 'admin', t('shared.admin'))
%th{class: 'col-xs-2'}
= sort_link(@q, 'registrar', t('shared.registrar'))
%tbody
- @users.each do |x|
%tr
@ -28,7 +26,6 @@
%td= x.email
%td= x.identity_code
%td= x.admin
%td= x.registrar
.row
.col-md-12
= paginate @users

View file

@ -39,8 +39,5 @@
%dt= t('shared.email')
%dd= @user.email
%dt= t('shared.registrar')
%dd= @user.registrar
%dt= t('shared.admin')
%dd= @user.admin