mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
Better flash messages, sessions spec
This commit is contained in:
parent
662806d8c9
commit
482d77c319
12 changed files with 77 additions and 8 deletions
|
@ -1,7 +1,6 @@
|
||||||
body {
|
body {
|
||||||
padding-top: 40px;
|
padding-top: 40px;
|
||||||
padding-bottom: 40px;
|
padding-bottom: 40px;
|
||||||
background-color: #eee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-signin {
|
.form-signin {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
class Admin::ContactsController < ApplicationController
|
class Admin::ContactsController < AdminController
|
||||||
# TODO created_by and updated_by ids
|
# TODO created_by and updated_by ids
|
||||||
before_action :set_contact, only: [:show, :destroy, :edit, :update]
|
before_action :set_contact, only: [:show, :destroy, :edit, :update]
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
class Admin::DomainsController < ApplicationController
|
class Admin::DomainsController < AdminController
|
||||||
before_action :set_domain, only: [:show, :edit, :update, :destroy]
|
before_action :set_domain, only: [:show, :edit, :update, :destroy]
|
||||||
before_action :verify_deletion, only: [:destroy]
|
before_action :verify_deletion, only: [:destroy]
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
class Admin::RegistrarsController < ApplicationController
|
class Admin::RegistrarsController < AdminController
|
||||||
def search
|
def search
|
||||||
render json: Registrar.search_by_query(params[:q])
|
render json: Registrar.search_by_query(params[:q])
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
class Admin::SettingGroupsController < ApplicationController
|
class Admin::SettingGroupsController < AdminController
|
||||||
before_action :set_setting_group, only: [:show, :update]
|
before_action :set_setting_group, only: [:show, :update]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|
7
app/controllers/admin_controller.rb
Normal file
7
app/controllers/admin_controller.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
class AdminController < ApplicationController
|
||||||
|
before_action :verify_admin
|
||||||
|
|
||||||
|
def verify_admin
|
||||||
|
redirect_to client_root_path unless current_user.try(:admin?)
|
||||||
|
end
|
||||||
|
end
|
|
@ -2,7 +2,8 @@ class Client::DomainsController < ClientController
|
||||||
include Shared::CommonDomain
|
include Shared::CommonDomain
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@q = current_user.registrar.domains.search(params[:q])
|
@q = Domain.search(params[:q]) if current_user.admin?
|
||||||
|
@q = current_user.registrar.domains.search(params[:q]) unless current_user.admin?
|
||||||
@domains = @q.result.page(params[:page])
|
@domains = @q.result.page(params[:page])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
class SessionsController < Devise::SessionsController
|
class SessionsController < Devise::SessionsController
|
||||||
def create
|
def create
|
||||||
if Rails.env.development?
|
if Rails.env.development? || Rails.env.test?
|
||||||
@user = User.find_by(username: 'gitlab') if params[:gitlab]
|
@user = User.find_by(username: 'gitlab') if params[:gitlab]
|
||||||
@user = User.find_by(username: 'zone') if params[:zone]
|
@user = User.find_by(username: 'zone') if params[:zone]
|
||||||
|
|
||||||
|
flash[:notice] = I18n.t('shared.welcome')
|
||||||
sign_in_and_redirect @user, :event => :authentication
|
sign_in_and_redirect @user, :event => :authentication
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,9 +14,13 @@
|
||||||
%body
|
%body
|
||||||
.container
|
.container
|
||||||
.form-signin
|
.form-signin
|
||||||
|
- display = (flash.empty?) ? 'none' : 'block'
|
||||||
|
#flash{style: "display: #{display};"}
|
||||||
|
- type = (flash[:notice]) ? 'bg-success' : 'bg-danger'
|
||||||
|
.alert{class: type}= flash[:notice] || flash[:alert]
|
||||||
%h2.form-signin-heading.text-center Eesti Interneti SA
|
%h2.form-signin-heading.text-center Eesti Interneti SA
|
||||||
%hr
|
%hr
|
||||||
- if Rails.env.development?
|
- if Rails.env.development? || Rails.env.test?
|
||||||
= button_to 'ID card (gitlab)', 'sessions', class: 'btn btn-lg btn-primary btn-block', name: 'gitlab'
|
= button_to 'ID card (gitlab)', 'sessions', class: 'btn btn-lg btn-primary btn-block', name: 'gitlab'
|
||||||
= button_to 'ID card (zone)', 'sessions', class: 'btn btn-lg btn-primary btn-block', name: 'zone'
|
= button_to 'ID card (zone)', 'sessions', class: 'btn btn-lg btn-primary btn-block', name: 'zone'
|
||||||
-else
|
-else
|
||||||
|
|
|
@ -297,3 +297,4 @@ en:
|
||||||
domain_was_not_found: 'Domain was not found!'
|
domain_was_not_found: 'Domain was not found!'
|
||||||
domain_list: 'Domain list'
|
domain_list: 'Domain list'
|
||||||
register_new_domain: 'Register new domain'
|
register_new_domain: 'Register new domain'
|
||||||
|
welcome: 'Welcome!'
|
||||||
|
|
8
spec/fabricators/user_fabricator.rb
Normal file
8
spec/fabricators/user_fabricator.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
Fabricator(:user) do
|
||||||
|
username 'gitlab'
|
||||||
|
password 'ghyt9e4fu'
|
||||||
|
email 'info@gitlab.eu'
|
||||||
|
identity_code '37810013108'
|
||||||
|
admin true
|
||||||
|
registrar
|
||||||
|
end
|
47
spec/features/sessions_spec.rb
Normal file
47
spec/features/sessions_spec.rb
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
feature 'Sessions', type: :feature do
|
||||||
|
let(:elkdata) { Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) }
|
||||||
|
let(:zone) { Fabricate(:registrar) }
|
||||||
|
|
||||||
|
background do
|
||||||
|
Fabricate(:user, registrar: zone)
|
||||||
|
Fabricate(:user, registrar: zone, username: 'zone', admin: false)
|
||||||
|
Fabricate(:domain_validation_setting_group)
|
||||||
|
Fabricate.times(2, :domain, registrar: zone)
|
||||||
|
Fabricate.times(2, :domain, registrar: elkdata)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Admin logs in' do
|
||||||
|
visit root_path
|
||||||
|
expect(page).to have_button('ID card (gitlab)')
|
||||||
|
expect(page).to have_button('ID card (zone)')
|
||||||
|
|
||||||
|
click_on 'ID card (gitlab)'
|
||||||
|
expect(page).to have_text('Welcome!')
|
||||||
|
|
||||||
|
uri = URI.parse(current_url)
|
||||||
|
expect(uri.path).to eq(admin_root_path)
|
||||||
|
|
||||||
|
expect(page).to have_link('Elkdata', count: 2)
|
||||||
|
expect(page).to have_link('Zone Media OÜ', count: 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Client logs in' do
|
||||||
|
visit root_path
|
||||||
|
|
||||||
|
click_on 'ID card (zone)'
|
||||||
|
expect(page).to have_text('Welcome!')
|
||||||
|
|
||||||
|
uri = URI.parse(current_url)
|
||||||
|
expect(uri.path).to eq(client_root_path)
|
||||||
|
|
||||||
|
zone.domains.pluck(:name).each do |name|
|
||||||
|
expect(page).to have_link(name)
|
||||||
|
end
|
||||||
|
|
||||||
|
elkdata.domains.pluck(:name).each do |name|
|
||||||
|
expect(page).to_not have_link(name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue