mirror of
https://github.com/internetee/registry.git
synced 2025-05-30 01:20:04 +02:00
Refactor user to admin and api user
This commit is contained in:
parent
f3215680d5
commit
037cb57e00
34 changed files with 551 additions and 551 deletions
|
@ -1,22 +1,22 @@
|
|||
class Admin::UsersController < AdminController
|
||||
class Admin::AdminUsersController < AdminController
|
||||
load_and_authorize_resource
|
||||
before_action :set_user, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@q = User.search(params[:q])
|
||||
@users = @q.result.page(params[:page])
|
||||
@q = AdminUser.search(params[:q])
|
||||
@admin_users = @q.result.page(params[:page])
|
||||
end
|
||||
|
||||
def new
|
||||
@user = User.new
|
||||
@admin_user = AdminUser.new
|
||||
end
|
||||
|
||||
def create
|
||||
@user = User.new(user_params)
|
||||
@admin_user = AdminUser.new(admin_user_params)
|
||||
|
||||
if @user.save
|
||||
if @admin_user.save
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @user]
|
||||
redirect_to [:admin, @admin_user]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_create_record')
|
||||
render 'new'
|
||||
|
@ -28,9 +28,9 @@ class Admin::UsersController < AdminController
|
|||
def edit; end
|
||||
|
||||
def update
|
||||
if @user.update(user_params)
|
||||
if @admin_user.update(admin_user_params)
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
redirect_to [:admin, @user]
|
||||
redirect_to [:admin, @admin_user]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_record')
|
||||
render 'edit'
|
||||
|
@ -38,7 +38,7 @@ class Admin::UsersController < AdminController
|
|||
end
|
||||
|
||||
def destroy
|
||||
if @user.destroy
|
||||
if @admin_user.destroy
|
||||
flash[:notice] = I18n.t('record_deleted')
|
||||
redirect_to admin_users_path
|
||||
else
|
||||
|
@ -50,10 +50,10 @@ class Admin::UsersController < AdminController
|
|||
private
|
||||
|
||||
def set_user
|
||||
@user = User.find(params[:id])
|
||||
@admin_user = AdminUser.find(params[:id])
|
||||
end
|
||||
|
||||
def user_params
|
||||
params.require(:user).permit(:username, :password, :identity_code, :email, :country_code, { roles: [] })
|
||||
def admin_user_params
|
||||
params.require(:admin_user).permit(:username, :password, :identity_code, :email, :country_code, { roles: [] })
|
||||
end
|
||||
end
|
|
@ -15,10 +15,10 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def user_for_paper_trail
|
||||
if defined?(current_api_user) && current_api_user.present?
|
||||
# Most of the time it's not loaded in correct time because PaperTrail before filter kicks in
|
||||
# before current_api_user is defined. PaperTrail is triggered also at current_api_user
|
||||
api_user_log_str(current_api_user)
|
||||
if defined?(current_user) && current_user.present?
|
||||
# Most of the time it's not loaded in correct time because PaperTrail before filter kicks in
|
||||
# before current_user is defined. PaperTrail is triggered also at current_user
|
||||
api_user_log_str(current_user)
|
||||
elsif current_user.present?
|
||||
"#{current_user.id}-#{current_user.username}"
|
||||
else
|
||||
|
|
|
@ -5,9 +5,9 @@ module Shared::UserStamper
|
|||
# return false if obj.nil? || !obj.has_attribute?(:created_by_id && :updated_by_id)
|
||||
|
||||
# if obj.new_record?
|
||||
# obj.created_by_id = current_api_user.id
|
||||
# obj.created_by_id = current_user.id
|
||||
# else
|
||||
# obj.updated_by_id = current_api_user.id
|
||||
# obj.updated_by_id = current_user.id
|
||||
# end
|
||||
|
||||
# true
|
||||
|
|
|
@ -3,7 +3,7 @@ class Epp::ContactsController < EppController
|
|||
|
||||
def create
|
||||
@contact = Contact.new(contact_and_address_attributes)
|
||||
@contact.registrar = current_api_user.registrar
|
||||
@contact.registrar = current_user.registrar
|
||||
render_epp_response '/epp/contacts/create' and return if @contact.save
|
||||
handle_errors(@contact)
|
||||
end
|
||||
|
@ -108,7 +108,7 @@ class Epp::ContactsController < EppController
|
|||
return false unless xml_attrs_present?(@ph, [['id']])
|
||||
@contact = find_contact
|
||||
return false unless @contact
|
||||
return true if current_api_user.registrar == @contact.registrar || xml_attrs_present?(@ph, [%w(authInfo pw)])
|
||||
return true if current_user.registrar == @contact.registrar || xml_attrs_present?(@ph, [%w(authInfo pw)])
|
||||
false
|
||||
end
|
||||
|
||||
|
@ -126,7 +126,7 @@ class Epp::ContactsController < EppController
|
|||
|
||||
def owner?(with_errors = true)
|
||||
return false unless find_contact
|
||||
return true if @contact.registrar == current_api_user.registrar
|
||||
return true if @contact.registrar == current_user.registrar
|
||||
return false unless with_errors
|
||||
epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error') }
|
||||
false
|
||||
|
@ -135,7 +135,7 @@ class Epp::ContactsController < EppController
|
|||
def rights?
|
||||
pw = @ph.try(:[], :authInfo).try(:[], :pw)
|
||||
|
||||
return true if current_api_user.try(:registrar) == @contact.try(:registrar)
|
||||
return true if current_user.try(:registrar) == @contact.try(:registrar)
|
||||
return true if pw && @contact.auth_info_matches(pw) # @contact.try(:auth_info_matches, pw)
|
||||
|
||||
epp_errors << { code: '2200', msg: t('errors.messages.epp_authentication_error') }
|
||||
|
|
|
@ -176,7 +176,7 @@ class Epp::DomainsController < EppController
|
|||
|
||||
{
|
||||
name: name,
|
||||
registrar_id: current_api_user.registrar.try(:id),
|
||||
registrar_id: current_user.registrar.try(:id),
|
||||
registered_at: Time.now,
|
||||
period: (period.to_i == 0) ? 1 : period.to_i,
|
||||
period_unit: Epp::EppDomain.parse_period_unit_from_frame(params[:parsed_frame]) || 'y'
|
||||
|
@ -187,7 +187,7 @@ class Epp::DomainsController < EppController
|
|||
res = {}
|
||||
res[:pw] = params[:parsed_frame].css('pw').first.try(:text)
|
||||
res[:action] = params[:parsed_frame].css('transfer').first[:op]
|
||||
res[:current_user] = current_api_user
|
||||
res[:current_user] = current_user
|
||||
res
|
||||
end
|
||||
|
||||
|
@ -206,7 +206,7 @@ class Epp::DomainsController < EppController
|
|||
|
||||
return domain if domain.auth_info == params[:parsed_frame].css('authInfo pw').text
|
||||
|
||||
if (domain.registrar != current_api_user.registrar && secure[:secure] == true) &&
|
||||
if (domain.registrar != current_user.registrar && secure[:secure] == true) &&
|
||||
epp_errors << {
|
||||
code: '2302',
|
||||
msg: I18n.t('errors.messages.domain_exists_but_belongs_to_other_registrar'),
|
||||
|
|
|
@ -6,7 +6,7 @@ class Epp::KeyrelaysController < EppController
|
|||
|
||||
handle_errors(@domain) and return unless @domain
|
||||
handle_errors(@domain) and return unless @domain.authenticate(params[:parsed_frame].css('pw').text)
|
||||
handle_errors(@domain) and return unless @domain.keyrelay(params[:parsed_frame], current_api_user.registrar)
|
||||
handle_errors(@domain) and return unless @domain.keyrelay(params[:parsed_frame], current_user.registrar)
|
||||
|
||||
render_epp_response '/epp/shared/success'
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ class Epp::PollsController < EppController
|
|||
end
|
||||
|
||||
def req_poll
|
||||
@message = current_api_user.queued_messages.last
|
||||
@message = current_user.queued_messages.last
|
||||
render_epp_response 'epp/poll/poll_no_messages' and return unless @message
|
||||
|
||||
if @message.attached_obj_type && @message.attached_obj_id
|
||||
|
@ -20,7 +20,7 @@ class Epp::PollsController < EppController
|
|||
end
|
||||
|
||||
def ack_poll
|
||||
@message = current_api_user.queued_messages.find_by(id: params[:parsed_frame].css('poll').first['msgID'])
|
||||
@message = current_user.queued_messages.find_by(id: params[:parsed_frame].css('poll').first['msgID'])
|
||||
|
||||
unless @message
|
||||
epp_errors << {
|
||||
|
|
|
@ -16,7 +16,7 @@ class Epp::SessionsController < EppController
|
|||
end
|
||||
|
||||
def logout
|
||||
@api_user = current_api_user # cache current_api_user for logging
|
||||
@api_user = current_user # cache current_user for logging
|
||||
epp_session[:api_user_id] = nil
|
||||
response.headers['X-EPP-Returncode'] = '1500'
|
||||
render_epp_response('logout')
|
||||
|
|
|
@ -3,7 +3,7 @@ class EppController < ApplicationController
|
|||
before_action :generate_svtrid
|
||||
before_action :validate_request
|
||||
layout false
|
||||
helper_method :current_api_user
|
||||
helper_method :current_user
|
||||
|
||||
def generate_svtrid
|
||||
# rubocop: disable Style/VariableName
|
||||
|
@ -21,13 +21,13 @@ class EppController < ApplicationController
|
|||
EppSession.find_or_initialize_by(session_id: cookie['session'])
|
||||
end
|
||||
|
||||
def current_api_user
|
||||
@current_api_user ||= ApiUser.find_by_id(epp_session[:api_user_id])
|
||||
def current_user
|
||||
@current_user ||= ApiUser.find_by_id(epp_session[:api_user_id])
|
||||
# by default PaperTrail uses before filter and at that
|
||||
# time current_api_user is not yet present
|
||||
::PaperTrail.whodunnit = api_user_log_str(@current_api_user)
|
||||
# time current_user is not yet present
|
||||
::PaperTrail.whodunnit = api_user_log_str(@current_user)
|
||||
::PaperSession.session = epp_session.session_id if epp_session.session_id.present?
|
||||
@current_api_user
|
||||
@current_user
|
||||
end
|
||||
|
||||
# ERROR + RESPONSE HANDLING
|
||||
|
@ -203,8 +203,8 @@ class EppController < ApplicationController
|
|||
request_successful: epp_errors.empty?,
|
||||
request_object: params[:epp_object_type],
|
||||
response: @response,
|
||||
api_user_name: api_user_log_str(@api_user || current_api_user),
|
||||
api_user_registrar: @api_user.try(:registrar).try(:to_s) || current_api_user.try(:registrar).try(:to_s),
|
||||
api_user_name: api_user_log_str(@api_user || current_user),
|
||||
api_user_registrar: @api_user.try(:registrar).try(:to_s) || current_user.try(:registrar).try(:to_s),
|
||||
ip: request.ip
|
||||
})
|
||||
end
|
||||
|
|
|
@ -3,8 +3,8 @@ class SessionsController < Devise::SessionsController
|
|||
# TODO: Create ID Card login here:
|
||||
# this is just testing config
|
||||
# if Rails.env.development? || Rails.env.test?
|
||||
@user = User.first if params[:user1]
|
||||
@user = User.second if params[:user2]
|
||||
@user = AdminUser.first if params[:user1]
|
||||
@user = AdminUser.second if params[:user2]
|
||||
|
||||
return redirect_to :back, alert: 'No user' if @user.blank?
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue