Taskme update

This commit is contained in:
Senad Uka
2020-06-30 05:08:23 +02:00
parent 1cd125382f
commit 71ad502cc1
210 changed files with 6316 additions and 766 deletions

View File

@@ -10,5 +10,6 @@ require_relative "./brayniac_ai/edl_parse"
require_relative "./brayniac_ai/edl_parse_result"
require_relative "./brayniac_ai/facial_recognition"
require_relative "./brayniac_ai/facial_recognition_result"
require_relative "./brayniac_ai/qr_matching"
require_relative "./brayniac_ai/tag"
require_relative "./brayniac_ai/validation"

View File

@@ -0,0 +1,4 @@
module BrayniacAI
class QrMatching < Base
end
end

View File

@@ -33,6 +33,8 @@ if Rails.env.development? || Rails.env.test? || Rails.env.review?
material_release: true,
music_release: true,
talent_release: true,
medical_release: true,
misc_release: true,
video_analysis: true,
})

View File

@@ -1,4 +1,3 @@
require 'zoom_gateway'
namespace :zoom do
desc "Setup necessary zoom roles and users"
task :setup => :environment do
@@ -17,4 +16,30 @@ namespace :zoom do
Rails.logger.info "Created role #{ZoomGateway.HOST_ROLE}."
end
end
desc "Synchronize ActiveRecord users with current account state"
task :sync => :environment do
zoom = Zoom.new
roles = zoom.roles_list["roles"]
ActiveRecord::Base.transaction do
ZoomUser.tiers.keys.each do |tier|
full_role_name = ZoomGateway.host_role_name(tier)
role_id = roles.select { |r| r["name"] == full_role_name }.first["id"]
user_ids = zoom.roles_members(role_id: role_id).dig("members").pluck("id")
# Invalid db users (not existing on the given Zoom account, but existing in the app db)
ZoomUser.current_account.public_send(tier).where.not(api_id: user_ids).each do |zu|
zu.api_id = nil
zu.destroy
end
# Missing zoom users (existing in given Zoom account, but not existing in the app db)
(user_ids - ZoomUser.current_account.public_send(tier).pluck(:api_id)).each do |api_user_id|
ZoomUser.current_account.public_send(tier).create(api_id: api_user_id)
end
end
end
end
end

View File

@@ -1,8 +1,13 @@
# frozen_string_literal: true
require './lib/zoom_wrapper_monkeypatch'
class ZoomGateway
class AuthenticationError < StandardError; end
class MeetingExpired < StandardError; end
class UserNotFound < StandardError; end
class TooManyHosts < StandardError; end
class UserAlreadyExists < StandardError; end
class << self
def USER_TYPE_NAME
@@ -20,12 +25,24 @@ class ZoomGateway
end
def HOST_ROLE
"#{self.USER_TYPE_NAME}-directme-host"
self.host_role_name(self.USER_TYPE_NAME)
end
def ACCOUNT_NUMBER
ENV['ZOOM_ACCOUNT_NUMBER']
end
def enable_recordings?
ENV['ZOOM_ENABLE_RECORDINGS'] == 'true'
end
def apply_limits?
self.USER_TYPE_NAME == 'pro'
end
def host_role_name(user_type_name)
"#{user_type_name}-directme-host"
end
end
def initialize
@@ -33,12 +50,14 @@ class ZoomGateway
end
def create_meeting(host_id, **kwargs)
recording_type = self.class.enable_recordings? ? 'cloud' : 'none'
meeting = @client.meeting_create({ user_id: host_id,
topic: kwargs[:topic],
type: 1, # Instant meeting
settings: {
host_video: true,
participant_video: true
participant_video: true,
auto_recording: recording_type,
} })
meeting["id"]
end
@@ -50,6 +69,23 @@ class ZoomGateway
parse_zoom_error(e)
end
# Update user with custom settings
def update_user_settings(user_id)
custom_defaults = {
id: user_id,
in_meeting: {
auto_saving_chat: true,
co_host: true,
non_verbal_feedback: true,
breakout_room: true,
group_hd: true,
far_end_camera_control: true,
allow_live_streaming: true
}
}
@client.user_settings_update custom_defaults
end
def create_host(host_email)
# Find role
host_role = @client.roles_list["roles"].try(:select) { |r| r["name"] == self.class.HOST_ROLE }.try(:first)
@@ -67,6 +103,8 @@ class ZoomGateway
type: self.class.USER_TYPE
})
update_user_settings(host_user["id"])
# Assign role to user
@client.roles_assign role_id: host_role["id"], members: [{id: host_user["id"]}]
@@ -78,6 +116,10 @@ class ZoomGateway
@client.user_delete(id: host_id)
end
def delete_recording(meeting_id, recording_id)
@client.recording_delete(meeting_id: meeting_id, recording_id: recording_id)
end
private
def parse_zoom_error(error)
@@ -87,6 +129,8 @@ class ZoomGateway
raise UserNotFound, error.message
elsif error.status_code == 3001
raise MeetingExpired, error.message
elsif error.status_code == 1005
raise UserAlreadyExists, error.message
else
raise error
end

View File

@@ -0,0 +1,25 @@
# frozen_string_literal: true
module Zoom
module Actions
module User
def user_settings_update(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
permitted_in_meeting_params = %i[
auto_saving_chat
co_host
non_verbal_feedback
breakout_room
group_hd
far_end_camera_control
allow_live_streaming
]
permitted_params = { in_meeting: permitted_in_meeting_params }
params.require(:id).permit permitted_params
request_body = params.except(:id).to_json
resp = self.class.patch("/users/#{params[:id]}/settings", body: request_body, headers: request_headers)
Utils.parse_response resp
end
end
end
end