resolve structure conflict

This commit is contained in:
olegphenomenon 2021-10-28 09:49:15 +03:00
parent f6e46b8fe6
commit d56c61bf84
7 changed files with 106 additions and 10 deletions

View file

@ -2,17 +2,23 @@ module Repp
module V1
module Registrar
class AccreditationInfoController < BaseController
api :GET, 'repp/v1/registrar/accreditation_info'
api :GET, 'repp/v1/registrar/accreditation/get_info'
desc 'check login user and return data'
def index
@login = current_user
registrar = current_user.registrar
# name = registrar.name
# reg_no = registrar.reg_no
# rubocop:disable Style/AndOr
render_success(data: nil) and return unless @login
# rubocop:enable Style/AndOr
data = @login.as_json
data = @login.as_json(only: %i[id username name reg_no uuid roles accreditation_date accreditation_expire_date])
data[:registrar_name] = registrar.name
data[:registrar_reg_no] = registrar.reg_no
render_success(data: data)
end

View file

@ -0,0 +1,75 @@
module Repp
module V1
module Registrar
class AccreditationResultsController < ActionController::API
before_action :authenticate_admin
# api :POST, 'repp/v1/registrar/push_results'
api :GET, 'repp/v1/registrar/accreditation/push_results'
desc 'added datetime results'
def index
@login = @current_user
# rubocop:disable Style/AndOr
render_success(data: nil) and return unless @login
# rubocop:enable Style/AndOr
data = @login
render_success(data: data)
end
# def create
# @login = current_user
# registrar = current_user.registrar
# rubocop:disable Style/AndOr
# render_success(data: nil) and return unless @login
# rubocop:enable Style/AndOr
# user = ApiUser.find(params[:user_id])
# user.accreditation_date = Date.now
# user.save
# data = @login.as_json(only: %i[id username name reg_no uuid roles accreditation_date accreditation_expire_date])
# data[:registrar_name] = registrar.name
# data[:registrar_reg_no] = registrar.reg_no
# render_success(data: data)
# end
private
def authenticate_admin
# TODO: ADD MORE CONDITIONS FOR ACCR ADMIN REQUESTS
username, password = Base64.urlsafe_decode64(basic_token).split(':')
@current_user ||= User.find_by(username: username, plain_text_password: password)
return if @current_user
# return if @current_user.roles.include? "admin"
raise(ArgumentError)
rescue NoMethodError, ArgumentError
@response = { code: 2202, message: 'Invalid authorization information' }
render(json: @response, status: :unauthorized)
end
def basic_token
pattern = /^Basic /
header = request.headers['Authorization']
header = header.gsub(pattern, '') if header&.match(pattern)
header.strip
end
def render_success(code: nil, message: nil, data: nil)
@response = { code: code || 1000, message: message || 'Command completed successfully',
data: data || {} }
render(json: @response, status: :ok)
end
end
end
end
end

View file

@ -72,9 +72,10 @@ Rails.application.routes.draw do
get '/all_notifications', to: 'notifications#all_notifications'
end
end
resource :accreditation_info, only: [:index] do
resource :accreditation, only: [:index] do
collection do
get '/', to: 'accreditation_info#index'
get '/get_info', to: 'accreditation_info#index'
get '/push_results', to: 'accreditation_results#index'
end
end
resources :nameservers do

View file

@ -0,0 +1,6 @@
class AddFieldToUser < ActiveRecord::Migration[6.1]
def change
add_column :users, :accreditation_date, :datetime
add_column :users, :accreditation_expire_date, :datetime
end
end

View file

@ -0,0 +1,5 @@
class AddColumnToUser < ActiveRecord::Migration[6.1]
def change
add_column :users, :uuid, :uuid, default: 'gen_random_uuid()'
end
end

View file

@ -2582,7 +2582,10 @@ CREATE TABLE public.users (
remember_created_at timestamp without time zone,
failed_attempts integer DEFAULT 0 NOT NULL,
locked_at timestamp without time zone,
legacy_id integer
legacy_id integer,
accreditation_date timestamp without time zone,
accreditation_expire_date timestamp without time zone,
uuid uuid DEFAULT public.gen_random_uuid()
);
@ -5230,6 +5233,6 @@ INSERT INTO "schema_migrations" (version) VALUES
('20210616112332'),
('20210629074044'),
('20210628090353'),
('20210708131814');
('20210708131814'),
('20210729131100'),
('20210729134625');

View file

@ -10,7 +10,7 @@ class ReppV1AccreditationInfoTest < ActionDispatch::IntegrationTest
end
def test_valid_login
get '/repp/v1/registrar/accreditation_info', headers: @auth_headers
get '/repp/v1/registrar/accreditation/get_info', headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
@ -24,7 +24,7 @@ class ReppV1AccreditationInfoTest < ActionDispatch::IntegrationTest
auth_headers = { 'Authorization' => token }
get '/repp/v1/registrar/accreditation_info', headers: auth_headers
get '/repp/v1/registrar/accreditation/get_info', headers: auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :unauthorized