Upstream sync
This commit is contained in:
@@ -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
|
||||
@@ -21,7 +21,7 @@ class ZoomGateway
|
||||
end
|
||||
|
||||
def HOST_ROLE
|
||||
"#{self.USER_TYPE_NAME}-directme-host"
|
||||
self.host_role_name(self.USER_TYPE_NAME)
|
||||
end
|
||||
|
||||
def ACCOUNT_NUMBER
|
||||
@@ -35,6 +35,10 @@ class ZoomGateway
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user