From f5068a3a7ea03431b9e1d6523f9107d476ddd3ec Mon Sep 17 00:00:00 2001 From: bilal Date: Fri, 19 Jun 2020 12:14:22 +0200 Subject: [PATCH 1/3] update zoom user settings after creating zoom user --- lib/zoom_gateway.rb | 19 +++++++ lib/zoom_wrapper_monkeypatch.rb | 25 ++++++++++ spec/lib/zoom_gateway_spec.rb | 3 ++ spec/lib/zoom_wrapper_monkeypatch_spec.rb | 60 +++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 lib/zoom_wrapper_monkeypatch.rb create mode 100644 spec/lib/zoom_wrapper_monkeypatch_spec.rb diff --git a/lib/zoom_gateway.rb b/lib/zoom_gateway.rb index 764c2f9..2225908 100644 --- a/lib/zoom_gateway.rb +++ b/lib/zoom_gateway.rb @@ -1,3 +1,7 @@ +# frozen_string_literal: true + +require './lib/zoom_wrapper_monkeypatch' + class ZoomGateway class AuthenticationError < StandardError; end class MeetingExpired < StandardError; end @@ -82,6 +86,21 @@ class ZoomGateway type: self.class.USER_TYPE }) + # Update user with custom settings + custom_defaults = { + id: host_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 + # Assign role to user @client.roles_assign role_id: host_role["id"], members: [{id: host_user["id"]}] diff --git a/lib/zoom_wrapper_monkeypatch.rb b/lib/zoom_wrapper_monkeypatch.rb new file mode 100644 index 0000000..bb9e0dc --- /dev/null +++ b/lib/zoom_wrapper_monkeypatch.rb @@ -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 \ No newline at end of file diff --git a/spec/lib/zoom_gateway_spec.rb b/spec/lib/zoom_gateway_spec.rb index 0b48a24..dc41514 100644 --- a/spec/lib/zoom_gateway_spec.rb +++ b/spec/lib/zoom_gateway_spec.rb @@ -5,6 +5,7 @@ RSpec.describe ZoomGateway do let(:host_user_hash) { {"email" => "user1@directme", "id" => "host_user_id"} } let(:roles_members_response) { {"members" => [host_user_hash]} } let(:user_create_response) { {"id" => "new_host_id"} } + let(:user_settings_update_response) { "User settings updated" } let(:roles_assign_response) { {"ids" => ["new_host_id"]} } let(:meeting_hash) { {"id" => "meeting_id", "start_url" => "https://start_url", "join_url" => "https://join_url"} } let(:gateway) { ZoomGateway.new } @@ -121,7 +122,9 @@ RSpec.describe ZoomGateway do it "returns new host id" do allow_any_instance_of(Zoom.new.class).to receive(:user_create).and_return(user_create_response) allow_any_instance_of(Zoom.new.class).to receive(:roles_assign).and_return(roles_assign_response) + allow_any_instance_of(Zoom.new.class).to receive(:user_settings_update).and_return(user_settings_update_response) + expect_any_instance_of(Zoom.new.class).to receive(:user_settings_update) expect(gateway.create_host("host-email@address")).to eq("new_host_id") end diff --git a/spec/lib/zoom_wrapper_monkeypatch_spec.rb b/spec/lib/zoom_wrapper_monkeypatch_spec.rb new file mode 100644 index 0000000..7f653e6 --- /dev/null +++ b/spec/lib/zoom_wrapper_monkeypatch_spec.rb @@ -0,0 +1,60 @@ +require 'rails_helper' + +RSpec.describe Zoom::Actions::User do + let(:wrapper) { Zoom.new } + + describe '.update_user_settings' do + it 'raises exception if id param is missing' do + params = { + in_meeting: { + not_allowed_param: 1 + } + } + + expect do + wrapper.user_settings_update(params) + end.to raise_exception(Zoom::ParameterMissing) + end + + it 'raises exception if not allowed param is present' do + params = { + id: 'dw3-3sd33', + in_meeting: { + not_allowed_param: 1 + } + } + + expect do + wrapper.user_settings_update(params) + end.to raise_exception(Zoom::ParameterNotPermitted) + end + + it 'sends PATCH request to the Zoom API endpoint' do + params = { + id: 'zoom-120-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 + } + } + + allow(Zoom::Utils).to receive(:parse_response).and_return 'Success!' + + path = "/users/#{params[:id]}/settings" + body_params = { body: params.except(:id).to_json } + allow(wrapper.class) + .to receive(:patch) + .with(path, hash_including(body_params)) + .and_return({}) + + mock_response = wrapper.user_settings_update params + expect(mock_response).to eq 'Success!' + end + end + +end -- 2.47.3 From 219bc5abd1e66b6310e22dfe39c5c0c8269c8230 Mon Sep 17 00:00:00 2001 From: bilal Date: Tue, 23 Jun 2020 11:31:44 +0200 Subject: [PATCH 2/3] add data migration to change zoom user default settings --- ...1803_change_existing_zoom_user_settings.rb | 9 ++++++ lib/zoom_gateway.rb | 32 +++++++++++-------- 2 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 db/data_migrations/20200623111803_change_existing_zoom_user_settings.rb diff --git a/db/data_migrations/20200623111803_change_existing_zoom_user_settings.rb b/db/data_migrations/20200623111803_change_existing_zoom_user_settings.rb new file mode 100644 index 0000000..e690376 --- /dev/null +++ b/db/data_migrations/20200623111803_change_existing_zoom_user_settings.rb @@ -0,0 +1,9 @@ +class ChangeExistingZoomUsersSettings < ActiveRecord::DataMigration + def up + gateway = ZoomGateway.new + + ZoomUser.find_each do |zu| + gateway.update_user_settings zu.api_id + end + end +end \ No newline at end of file diff --git a/lib/zoom_gateway.rb b/lib/zoom_gateway.rb index 2225908..60e8798 100644 --- a/lib/zoom_gateway.rb +++ b/lib/zoom_gateway.rb @@ -69,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) @@ -86,20 +103,7 @@ class ZoomGateway type: self.class.USER_TYPE }) - # Update user with custom settings - custom_defaults = { - id: host_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 + update_user_settings(host_user["id"]) # Assign role to user @client.roles_assign role_id: host_role["id"], members: [{id: host_user["id"]}] -- 2.47.3 From 60fc1d467df419bd02032fb76f35b964dbe81289 Mon Sep 17 00:00:00 2001 From: bilal Date: Tue, 23 Jun 2020 17:36:48 +0200 Subject: [PATCH 3/3] rebase --- db/structure.sql | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/db/structure.sql b/db/structure.sql index 3ad5cad..62abbd1 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -9,20 +9,6 @@ SET xmloption = content; SET client_min_messages = warning; SET row_security = off; --- --- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: - --- - -CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; - - --- --- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: - --- - -COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; - - -- -- Name: fuzzystrmatch; Type: EXTENSION; Schema: -; Owner: - -- -- 2.47.3