mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-20 09:52:19 +01:00
use openlab_app_secret from db w/ openlab_ruby gem
This commit is contained in:
parent
88f2fb3749
commit
f78eb10c75
@ -11,35 +11,35 @@ class API::OpenAPIClientsController < API::ApiController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@client = OpenAPI::Client.new(client_params)
|
@projets = OpenAPI::Client.new(client_params)
|
||||||
authorize @client
|
authorize @projets
|
||||||
if @client.save
|
if @projets.save
|
||||||
render status: :created
|
render status: :created
|
||||||
else
|
else
|
||||||
render json: @client.errors, status: :unprocessable_entity
|
render json: @projets.errors, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@client = OpenAPI::Client.find(params[:id])
|
@projets = OpenAPI::Client.find(params[:id])
|
||||||
authorize @client
|
authorize @projets
|
||||||
if @client.update(client_params)
|
if @projets.update(client_params)
|
||||||
render status: :ok
|
render status: :ok
|
||||||
else
|
else
|
||||||
render json: @client.errors, status: :unprocessable_entity
|
render json: @projets.errors, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_token
|
def reset_token
|
||||||
@client = OpenAPI::Client.find(params[:id])
|
@projets = OpenAPI::Client.find(params[:id])
|
||||||
authorize @client
|
authorize @projets
|
||||||
@client.regenerate_token
|
@projets.regenerate_token
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@client = OpenAPI::Client.find(params[:id])
|
@projets = OpenAPI::Client.find(params[:id])
|
||||||
authorize @client
|
authorize @projets
|
||||||
@client.destroy
|
@projets.destroy
|
||||||
head 204
|
head 204
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,11 +3,18 @@
|
|||||||
# API Controller for resources of type Openlab::Projects
|
# API Controller for resources of type Openlab::Projects
|
||||||
# Openlab::Projects are Projects shared between different instances
|
# Openlab::Projects are Projects shared between different instances
|
||||||
class API::OpenlabProjectsController < API::ApiController
|
class API::OpenlabProjectsController < API::ApiController
|
||||||
PROJECTS = Openlab::Projects.new
|
before_action :init_openlab
|
||||||
|
|
||||||
def index
|
def index
|
||||||
render json: PROJECTS.search(params[:q], page: params[:page], per_page: params[:per_page]).response.body
|
render json: @projets.search(params[:q], page: params[:page], per_page: params[:per_page]).response.body
|
||||||
rescue StandardError
|
rescue StandardError
|
||||||
render json: { errors: ['service unavailable'] }
|
render json: { errors: ['service unavailable'] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def init_openlab
|
||||||
|
client = Openlab::Client.new(app_secret: Setting.get('openlab_app_secret'))
|
||||||
|
@projets = Openlab::Projects.new(client)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
class OpenAPI::CallsCountTracing < ApplicationRecord
|
class OpenAPI::CallsCountTracing < ApplicationRecord
|
||||||
belongs_to :client, foreign_key: :open_api_client_id
|
belongs_to :projets, foreign_key: :open_api_client_id
|
||||||
validates :client, :at, presence: true
|
validates :projets, :at, presence: true
|
||||||
end
|
end
|
||||||
|
@ -79,8 +79,8 @@ class AccountingExportService
|
|||||||
invoice.payment_means.each do |details|
|
invoice.payment_means.each do |details|
|
||||||
rows << row(
|
rows << row(
|
||||||
invoice,
|
invoice,
|
||||||
account(invoice, :client, means: details[:means]),
|
account(invoice, :projets, means: details[:means]),
|
||||||
account(invoice, :client, means: details[:means], type: :label),
|
account(invoice, :projets, means: details[:means], type: :label),
|
||||||
details[:amount] / 100.00,
|
details[:amount] / 100.00,
|
||||||
line_label: label(invoice),
|
line_label: label(invoice),
|
||||||
debit_method: :debit_client,
|
debit_method: :debit_client,
|
||||||
@ -179,7 +179,7 @@ class AccountingExportService
|
|||||||
# Get the account code (or label) for the given invoice and the specified line type (client, vat, subscription or reservation)
|
# Get the account code (or label) for the given invoice and the specified line type (client, vat, subscription or reservation)
|
||||||
def account(invoice, account, type: :code, means: :other)
|
def account(invoice, account, type: :code, means: :other)
|
||||||
case account
|
case account
|
||||||
when :client
|
when :projets
|
||||||
Setting.find_by(name: "accounting_#{means}_client_#{type}")&.value
|
Setting.find_by(name: "accounting_#{means}_client_#{type}")&.value
|
||||||
when :vat
|
when :vat
|
||||||
Setting.find_by(name: "accounting_VAT_#{type}")&.value
|
Setting.find_by(name: "accounting_VAT_#{type}")&.value
|
||||||
|
@ -1 +1 @@
|
|||||||
json.partial! 'api/open_api_clients/client', client: @client
|
json.partial! 'api/open_api_clients/client', projets: @projets
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
json.array! @clients do |client|
|
json.array! @clients do |client|
|
||||||
json.partial! 'api/open_api_clients/client', client: client
|
json.partial! 'api/open_api_clients/client', projets: client
|
||||||
end
|
end
|
||||||
|
@ -1 +1 @@
|
|||||||
json.partial! 'api/open_api_clients/client', client: @client
|
json.partial! 'api/open_api_clients/client', projets: @projets
|
||||||
|
@ -1 +1 @@
|
|||||||
json.partial! 'api/open_api_clients/client', client: @client
|
json.partial! 'api/open_api_clients/client', projets: @projets
|
||||||
|
@ -4,7 +4,7 @@ class OpenAPITraceCallsCountWorker < Sidekiq::Workers
|
|||||||
|
|
||||||
def perform
|
def perform
|
||||||
OpenAPI::Client.find_each do |client|
|
OpenAPI::Client.find_each do |client|
|
||||||
OpenAPI::CallsCountTracing.create!(client: client, calls_count: client.calls_count, at: DateTime.current)
|
OpenAPI::CallsCountTracing.create!(projets: client, calls_count: client.calls_count, at: DateTime.current)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,12 @@ class OpenlabWorker
|
|||||||
sidekiq_options queue: 'default', retry: true
|
sidekiq_options queue: 'default', retry: true
|
||||||
|
|
||||||
LOGGER = Sidekiq.logger.level == Logger::DEBUG ? Sidekiq.logger : nil
|
LOGGER = Sidekiq.logger.level == Logger::DEBUG ? Sidekiq.logger : nil
|
||||||
OPENLAB_CLIENT = Openlab::Projects.new
|
|
||||||
|
def initialize
|
||||||
|
client = Openlab::Client.new(app_secret: Setting.get('openlab_app_secret'))
|
||||||
|
@projets = Openlab::Projects.new(client)
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
def perform(action, project_id)
|
def perform(action, project_id)
|
||||||
LOGGER&.debug ['Openlab sync', action, "project ID: #{project_id}"]
|
LOGGER&.debug ['Openlab sync', action, "project ID: #{project_id}"]
|
||||||
@ -14,12 +19,12 @@ class OpenlabWorker
|
|||||||
case action.to_s
|
case action.to_s
|
||||||
when /create/
|
when /create/
|
||||||
project = Project.find(project_id)
|
project = Project.find(project_id)
|
||||||
response = OPENLAB_CLIENT.create(project.openlab_attributes)
|
response = @projets.create(project.openlab_attributes)
|
||||||
when /update/
|
when /update/
|
||||||
project = Project.find(project_id)
|
project = Project.find(project_id)
|
||||||
response = OPENLAB_CLIENT.update(project_id, project.openlab_attributes)
|
response = @projets.update(project_id, project.openlab_attributes)
|
||||||
when /destroy/
|
when /destroy/
|
||||||
response = OPENLAB_CLIENT.destroy(project_id)
|
response = @projets.destroy(project_id)
|
||||||
else
|
else
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user