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
|
||||
|
||||
def create
|
||||
@client = OpenAPI::Client.new(client_params)
|
||||
authorize @client
|
||||
if @client.save
|
||||
@projets = OpenAPI::Client.new(client_params)
|
||||
authorize @projets
|
||||
if @projets.save
|
||||
render status: :created
|
||||
else
|
||||
render json: @client.errors, status: :unprocessable_entity
|
||||
render json: @projets.errors, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@client = OpenAPI::Client.find(params[:id])
|
||||
authorize @client
|
||||
if @client.update(client_params)
|
||||
@projets = OpenAPI::Client.find(params[:id])
|
||||
authorize @projets
|
||||
if @projets.update(client_params)
|
||||
render status: :ok
|
||||
else
|
||||
render json: @client.errors, status: :unprocessable_entity
|
||||
render json: @projets.errors, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def reset_token
|
||||
@client = OpenAPI::Client.find(params[:id])
|
||||
authorize @client
|
||||
@client.regenerate_token
|
||||
@projets = OpenAPI::Client.find(params[:id])
|
||||
authorize @projets
|
||||
@projets.regenerate_token
|
||||
end
|
||||
|
||||
def destroy
|
||||
@client = OpenAPI::Client.find(params[:id])
|
||||
authorize @client
|
||||
@client.destroy
|
||||
@projets = OpenAPI::Client.find(params[:id])
|
||||
authorize @projets
|
||||
@projets.destroy
|
||||
head 204
|
||||
end
|
||||
|
||||
|
@ -3,11 +3,18 @@
|
||||
# API Controller for resources of type Openlab::Projects
|
||||
# Openlab::Projects are Projects shared between different instances
|
||||
class API::OpenlabProjectsController < API::ApiController
|
||||
PROJECTS = Openlab::Projects.new
|
||||
before_action :init_openlab
|
||||
|
||||
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
|
||||
render json: { errors: ['service unavailable'] }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def init_openlab
|
||||
client = Openlab::Client.new(app_secret: Setting.get('openlab_app_secret'))
|
||||
@projets = Openlab::Projects.new(client)
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,4 @@
|
||||
class OpenAPI::CallsCountTracing < ApplicationRecord
|
||||
belongs_to :client, foreign_key: :open_api_client_id
|
||||
validates :client, :at, presence: true
|
||||
belongs_to :projets, foreign_key: :open_api_client_id
|
||||
validates :projets, :at, presence: true
|
||||
end
|
||||
|
@ -79,8 +79,8 @@ class AccountingExportService
|
||||
invoice.payment_means.each do |details|
|
||||
rows << row(
|
||||
invoice,
|
||||
account(invoice, :client, means: details[:means]),
|
||||
account(invoice, :client, means: details[:means], type: :label),
|
||||
account(invoice, :projets, means: details[:means]),
|
||||
account(invoice, :projets, means: details[:means], type: :label),
|
||||
details[:amount] / 100.00,
|
||||
line_label: label(invoice),
|
||||
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)
|
||||
def account(invoice, account, type: :code, means: :other)
|
||||
case account
|
||||
when :client
|
||||
when :projets
|
||||
Setting.find_by(name: "accounting_#{means}_client_#{type}")&.value
|
||||
when :vat
|
||||
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.partial! 'api/open_api_clients/client', client: client
|
||||
json.partial! 'api/open_api_clients/client', projets: client
|
||||
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
|
||||
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
|
||||
|
@ -6,7 +6,12 @@ class OpenlabWorker
|
||||
sidekiq_options queue: 'default', retry: true
|
||||
|
||||
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)
|
||||
LOGGER&.debug ['Openlab sync', action, "project ID: #{project_id}"]
|
||||
@ -14,12 +19,12 @@ class OpenlabWorker
|
||||
case action.to_s
|
||||
when /create/
|
||||
project = Project.find(project_id)
|
||||
response = OPENLAB_CLIENT.create(project.openlab_attributes)
|
||||
response = @projets.create(project.openlab_attributes)
|
||||
when /update/
|
||||
project = Project.find(project_id)
|
||||
response = OPENLAB_CLIENT.update(project_id, project.openlab_attributes)
|
||||
response = @projets.update(project_id, project.openlab_attributes)
|
||||
when /destroy/
|
||||
response = OPENLAB_CLIENT.destroy(project_id)
|
||||
response = @projets.destroy(project_id)
|
||||
else
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user