mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Remove Registrar from User
This commit is contained in:
parent
9c8fed999d
commit
2c35aa1471
14 changed files with 12 additions and 72 deletions
|
@ -53,7 +53,7 @@ class Admin::UsersController < AdminController
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_params
|
def user_params
|
||||||
params.require(:user).permit(:username, :password, :identity_code, :email, :registrar_id,
|
params.require(:user).permit(:username, :password, :identity_code, :email,
|
||||||
:admin, :registrar_typeahead, :country_id)
|
:admin, :country_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,6 @@ class Registrar < ActiveRecord::Base
|
||||||
has_many :domains, dependent: :restrict_with_error
|
has_many :domains, dependent: :restrict_with_error
|
||||||
has_many :contacts, dependent: :restrict_with_error
|
has_many :contacts, dependent: :restrict_with_error
|
||||||
has_many :epp_users, dependent: :restrict_with_error
|
has_many :epp_users, dependent: :restrict_with_error
|
||||||
has_many :users, dependent: :restrict_with_error
|
|
||||||
has_many :messages
|
has_many :messages
|
||||||
|
|
||||||
validates :name, :reg_no, :address, :country, presence: true
|
validates :name, :reg_no, :address, :country, presence: true
|
||||||
|
|
|
@ -7,29 +7,19 @@ class User < ActiveRecord::Base
|
||||||
# TODO: Estonian id validation
|
# TODO: Estonian id validation
|
||||||
|
|
||||||
belongs_to :role
|
belongs_to :role
|
||||||
belongs_to :registrar
|
|
||||||
belongs_to :country
|
belongs_to :country
|
||||||
|
|
||||||
validates :username, :password, presence: true
|
validates :username, :password, presence: true
|
||||||
validates :identity_code, uniqueness: true, allow_blank: true
|
validates :identity_code, uniqueness: true, allow_blank: true
|
||||||
validates :identity_code, presence: true, if: -> { country.iso == 'EE' }
|
validates :identity_code, presence: true, if: -> { country.iso == 'EE' }
|
||||||
validates :email, presence: true, if: -> { country.iso != 'EE' }
|
validates :email, presence: true, if: -> { country.iso != 'EE' }
|
||||||
validates :registrar, presence: true, if: -> { !admin }
|
|
||||||
|
|
||||||
validate :validate_identity_code
|
validate :validate_identity_code
|
||||||
|
|
||||||
before_save -> { self.registrar = nil if admin? }
|
|
||||||
|
|
||||||
attr_accessor :registrar_typeahead
|
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
username
|
username
|
||||||
end
|
end
|
||||||
|
|
||||||
def registrar_typeahead
|
|
||||||
@registrar_typeahead || registrar || nil
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def validate_identity_code
|
def validate_identity_code
|
||||||
|
|
|
@ -44,26 +44,6 @@
|
||||||
|
|
||||||
%dt= t('shared.billing_address')
|
%dt= t('shared.billing_address')
|
||||||
%dd= @registrar.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
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
|
|
|
@ -25,13 +25,6 @@
|
||||||
.form-group
|
.form-group
|
||||||
= f.label :email
|
= f.label :email
|
||||||
= f.text_field(:email, class: 'form-control')
|
= 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
|
.form-group
|
||||||
.checkbox
|
.checkbox
|
||||||
%label{for: 'user_admin'}
|
%label{for: 'user_admin'}
|
||||||
|
@ -41,19 +34,3 @@
|
||||||
.row
|
.row
|
||||||
.col-md-12.text-right
|
.col-md-12.text-right
|
||||||
= button_tag(t('shared.save'), class: 'btn btn-primary')
|
= 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
= sort_link(@q, 'identity_code', t('shared.identity_code'))
|
= sort_link(@q, 'identity_code', t('shared.identity_code'))
|
||||||
%th{class: 'col-xs-2'}
|
%th{class: 'col-xs-2'}
|
||||||
= sort_link(@q, 'admin', t('shared.admin'))
|
= sort_link(@q, 'admin', t('shared.admin'))
|
||||||
%th{class: 'col-xs-2'}
|
|
||||||
= sort_link(@q, 'registrar', t('shared.registrar'))
|
|
||||||
%tbody
|
%tbody
|
||||||
- @users.each do |x|
|
- @users.each do |x|
|
||||||
%tr
|
%tr
|
||||||
|
@ -28,7 +26,6 @@
|
||||||
%td= x.email
|
%td= x.email
|
||||||
%td= x.identity_code
|
%td= x.identity_code
|
||||||
%td= x.admin
|
%td= x.admin
|
||||||
%td= x.registrar
|
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
= paginate @users
|
= paginate @users
|
||||||
|
|
|
@ -39,8 +39,5 @@
|
||||||
%dt= t('shared.email')
|
%dt= t('shared.email')
|
||||||
%dd= @user.email
|
%dd= @user.email
|
||||||
|
|
||||||
%dt= t('shared.registrar')
|
|
||||||
%dd= @user.registrar
|
|
||||||
|
|
||||||
%dt= t('shared.admin')
|
%dt= t('shared.admin')
|
||||||
%dd= @user.admin
|
%dd= @user.admin
|
||||||
|
|
5
db/migrate/20141216133831_remove_registrar_from_user.rb
Normal file
5
db/migrate/20141216133831_remove_registrar_from_user.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class RemoveRegistrarFromUser < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
remove_column :users, :registrar_id
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20141215085117) do
|
ActiveRecord::Schema.define(version: 20141216133831) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -326,7 +326,6 @@ ActiveRecord::Schema.define(version: 20141215085117) do
|
||||||
t.inet "last_sign_in_ip"
|
t.inet "last_sign_in_ip"
|
||||||
t.boolean "admin", default: false
|
t.boolean "admin", default: false
|
||||||
t.string "identity_code"
|
t.string "identity_code"
|
||||||
t.integer "registrar_id"
|
|
||||||
t.integer "country_id"
|
t.integer "country_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,5 +5,4 @@ Fabricator(:user) do
|
||||||
identity_code '37810013108'
|
identity_code '37810013108'
|
||||||
admin true
|
admin true
|
||||||
country
|
country
|
||||||
registrar
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,8 +6,8 @@ feature 'Sessions', type: :feature do
|
||||||
|
|
||||||
background do
|
background do
|
||||||
create_settings
|
create_settings
|
||||||
Fabricate(:user, registrar: nil, identity_code: '37810013261')
|
Fabricate(:user, identity_code: '37810013261')
|
||||||
Fabricate(:user, registrar: zone, username: 'zone', admin: false, identity_code: '37810013087')
|
Fabricate(:user, username: 'zone', admin: false, identity_code: '37810013087')
|
||||||
Fabricate.times(2, :domain, registrar: zone)
|
Fabricate.times(2, :domain, registrar: zone)
|
||||||
Fabricate.times(2, :domain, registrar: elkdata)
|
Fabricate.times(2, :domain, registrar: elkdata)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
feature 'Setting management', type: :feature do
|
feature 'Setting management', type: :feature do
|
||||||
let(:zone) { Fabricate(:registrar) }
|
let(:user) { Fabricate(:user, username: 'user1', admin: true, identity_code: '37810013087') }
|
||||||
let(:zone_user) { Fabricate(:user, registrar: zone, username: 'user1', admin: true, identity_code: '37810013087') }
|
|
||||||
|
|
||||||
background { create_settings }
|
background { create_settings }
|
||||||
|
|
||||||
scenario 'User changes a setting' do
|
scenario 'User changes a setting' do
|
||||||
sign_in zone_user
|
sign_in user
|
||||||
visit admin_settings_path
|
visit admin_settings_path
|
||||||
|
|
||||||
val_min = find_field('_settings_ns_min_count').value
|
val_min = find_field('_settings_ns_min_count').value
|
||||||
|
|
|
@ -4,6 +4,5 @@ describe Registrar do
|
||||||
it { should belong_to(:country) }
|
it { should belong_to(:country) }
|
||||||
it { should have_many(:domains) }
|
it { should have_many(:domains) }
|
||||||
it { should have_many(:epp_users) }
|
it { should have_many(:epp_users) }
|
||||||
it { should have_many(:users) }
|
|
||||||
it { should have_many(:messages) }
|
it { should have_many(:messages) }
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,5 +2,4 @@ require 'rails_helper'
|
||||||
|
|
||||||
describe User do
|
describe User do
|
||||||
it { should belong_to(:role) }
|
it { should belong_to(:role) }
|
||||||
it { should belong_to(:registrar) }
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue