mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-28 09:24:24 +01:00
initial commit
This commit is contained in:
parent
1099adb208
commit
711b18f6cd
2
Gemfile
2
Gemfile
@ -137,3 +137,5 @@ gem 'chroma'
|
||||
gem 'protected_attributes'
|
||||
|
||||
gem 'message_format'
|
||||
|
||||
gem 'openlab_ruby'
|
||||
|
@ -174,6 +174,9 @@ GEM
|
||||
http-cookie (1.0.2)
|
||||
domain_name (~> 0.5)
|
||||
http_parser.rb (0.6.0)
|
||||
httparty (0.13.7)
|
||||
json (~> 1.8)
|
||||
multi_xml (>= 0.5.2)
|
||||
i18n (0.7.0)
|
||||
ice_nine (0.11.1)
|
||||
jbuilder (2.2.12)
|
||||
@ -242,6 +245,8 @@ GEM
|
||||
omniauth-oauth2 (1.3.1)
|
||||
oauth2 (~> 1.0)
|
||||
omniauth (~> 1.2)
|
||||
openlab_ruby (0.0.2)
|
||||
httparty (~> 0.13)
|
||||
orm_adapter (0.5.0)
|
||||
pdf-core (0.5.1)
|
||||
pg (0.18.1)
|
||||
@ -458,6 +463,7 @@ DEPENDENCIES
|
||||
oj
|
||||
omniauth
|
||||
omniauth-oauth2
|
||||
openlab_ruby
|
||||
pg
|
||||
prawn
|
||||
prawn-table
|
||||
|
@ -1,6 +1,7 @@
|
||||
class Project < ActiveRecord::Base
|
||||
include AASM
|
||||
include NotifyWith::NotificationAttachedObject
|
||||
include OpenlabSync
|
||||
|
||||
# elastic initialisations
|
||||
include Elasticsearch::Model
|
||||
|
54
app/models/project/openlab_sync.rb
Normal file
54
app/models/project/openlab_sync.rb
Normal file
@ -0,0 +1,54 @@
|
||||
module Project::OpenlabSync
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
after_create :openlab_create, if: :openlab_sync_active?
|
||||
after_update :openlab_update, if: :openlab_sync_active?
|
||||
after_destroy :openlab_destroy, if: :openlab_sync_active?
|
||||
|
||||
def openlab_create
|
||||
OpenlabSync.perform_async(:create, self.id) if self.published?
|
||||
end
|
||||
|
||||
def openlab_update
|
||||
if self.published?
|
||||
if self.state_was == 'draft'
|
||||
OpenlabSync.perform_async(:create, self.id)
|
||||
else
|
||||
OpenlabSync.perform_async(:update, self.id)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def openlab_destroy
|
||||
OpenlabSync.perform_async(:destroy, self.id)
|
||||
end
|
||||
|
||||
def openlab_attributes
|
||||
{
|
||||
id: id, name: name, description: description, tags: tags,
|
||||
machines: machines.map(&:name),
|
||||
components: components.map(&:name),
|
||||
themes: themes.map(&:name),
|
||||
author: author.profile.full_name,
|
||||
collaborators: users.map { |u| u.profile.full_name },
|
||||
steps_body: steps_body
|
||||
}
|
||||
end
|
||||
|
||||
def steps_body
|
||||
|
||||
end
|
||||
|
||||
def openlab_sync_active?
|
||||
self.class.openlab_sync_active?
|
||||
end
|
||||
end
|
||||
|
||||
class_methods do
|
||||
def openlab_sync_active?
|
||||
Rails.application.secrets.openlab_app_secret.present?
|
||||
end
|
||||
end
|
||||
end
|
22
app/workers/openlab_worker.rb
Normal file
22
app/workers/openlab_worker.rb
Normal file
@ -0,0 +1,22 @@
|
||||
class OpenlabWorker
|
||||
include Sidekiq::Worker
|
||||
sidekiq_options queue: 'default', retry: true
|
||||
|
||||
Logger = Sidekiq.logger.level == Logger::DEBUG ? Sidekiq.logger : nil
|
||||
openlab_client = Openlab::Projects.new
|
||||
|
||||
def perform(action, project_id)
|
||||
logger.debug ["Openlab sync", action, "project ID: #{project_id}"]
|
||||
|
||||
case action.to_s
|
||||
when /create/
|
||||
project = Project.find(project_id)
|
||||
openlab_client.create(project.openlab_attributes)
|
||||
when /update/
|
||||
project = Project.find(project_id)
|
||||
openlab_client.update(project_id, project.openlab_attributes)
|
||||
when /destroy/
|
||||
openlab_client.destroy(project_id)
|
||||
end
|
||||
end
|
||||
end
|
@ -47,3 +47,5 @@ TIME_ZONE: 'Paris'
|
||||
WEEK_STARTING_DAY: 'monday'
|
||||
D3_DATE_FORMAT: '%d/%m/%y'
|
||||
UIB_DATE_FORMAT: 'dd/MM/yyyy'
|
||||
|
||||
OPENLAB_APP_SECRET: 'fSF9jZEWxjHyqjAzzg34jd92'
|
||||
|
4
config/initializers/openlab_ruby.rb
Normal file
4
config/initializers/openlab_ruby.rb
Normal file
@ -0,0 +1,4 @@
|
||||
Openlab.configure do |config|
|
||||
config.app_secret = Rails.application.secrets.openfablab_app_secret
|
||||
config.base_uri = Rails.env.production? ? "https://urltochange.nawak" : "localhost:3300/api/v1"
|
||||
end
|
@ -28,6 +28,7 @@ development:
|
||||
messageformat_locale: <%= ENV["MESSAGEFORMAT_LOCALE"] %>
|
||||
fullcalendar_locale: <%= ENV["FULLCALENDAR_LOCALE"] %>
|
||||
elasticsearch_language_analyzer: <%= ENV["ELASTICSEARCH_LANGUAGE_ANALYZER"] %>
|
||||
openlab_app_secret: <%= ENV["OPENLAB_APP_SECRET"] %>
|
||||
|
||||
test:
|
||||
secret_key_base: 83daf5e7b80d990f037407bab78dff9904aaf3c195a50f84fa8695a22287e707dfbd9524b403b1dcf116ae1d8c06844c3d7ed942564e5b46be6ae3ead93a9d30
|
||||
@ -47,7 +48,7 @@ test:
|
||||
messageformat_locale: en
|
||||
fullcalendar_locale: en
|
||||
elasticsearch_language_analyzer: french
|
||||
|
||||
openlab_app_secret:
|
||||
|
||||
staging:
|
||||
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
|
||||
@ -74,6 +75,7 @@ staging:
|
||||
messageformat_locale: <%= ENV["MESSAGEFORMAT_LOCALE"] %>
|
||||
fullcalendar_locale: <%= ENV["FULLCALENDAR_LOCALE"] %>
|
||||
elasticsearch_language_analyzer: <%= ENV["ELASTICSEARCH_LANGUAGE_ANALYZER"] %>
|
||||
openlab_app_secret: <%= ENV["OPENLAB_APP_SECRET"] %>
|
||||
|
||||
# Do not keep production secrets in the repository,
|
||||
# instead read values from the environment.
|
||||
@ -102,3 +104,4 @@ production:
|
||||
messageformat_locale: <%= ENV["MESSAGEFORMAT_LOCALE"] %>
|
||||
fullcalendar_locale: <%= ENV["FULLCALENDAR_LOCALE"] %>
|
||||
elasticsearch_language_analyzer: <%= ENV["ELASTICSEARCH_LANGUAGE_ANALYZER"] %>
|
||||
openlab_app_secret: <%= ENV["OPENLAB_APP_SECRET"] %>
|
||||
|
Loading…
Reference in New Issue
Block a user