Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: Implement ProblemCheck for plugin configuration. Improved error logging and updated Webinar composer UI #90

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 32 additions & 35 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,82 +1,79 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (7.1.3.3)
activesupport (7.2.1)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.8)
concurrent-ruby (1.2.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
drb (2.2.1)
i18n (1.14.5)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
json (2.7.2)
language_server-protocol (3.17.0.3)
minitest (5.23.1)
mutex_m (0.2.0)
parallel (1.24.0)
parser (3.3.1.0)
logger (1.6.1)
minitest (5.25.1)
parallel (1.26.3)
parser (3.3.5.0)
ast (~> 2.4.1)
racc
prettier_print (1.2.1)
racc (1.8.0)
rack (3.0.11)
racc (1.8.1)
rack (3.1.7)
rainbow (3.1.1)
regexp_parser (2.9.2)
rexml (3.3.6)
strscan
rubocop (1.64.0)
rubocop (1.66.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
regexp_parser (>= 2.4, < 3.0)
rubocop-ast (>= 1.32.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.3)
rubocop-ast (1.32.3)
parser (>= 3.3.1.0)
rubocop-capybara (2.20.0)
rubocop-capybara (2.21.0)
rubocop (~> 1.41)
rubocop-discourse (3.8.0)
rubocop-discourse (3.8.1)
activesupport (>= 6.1)
rubocop (>= 1.59.0)
rubocop-capybara (>= 2.0.0)
rubocop-factory_bot (>= 2.0.0)
rubocop-rails (>= 2.25.0)
rubocop-rspec (>= 2.25.0)
rubocop-factory_bot (2.25.1)
rubocop (~> 1.41)
rubocop-rails (2.25.0)
rubocop-rspec (>= 3.0.1)
rubocop-rspec_rails (>= 2.30.0)
rubocop-factory_bot (2.26.1)
rubocop (~> 1.61)
rubocop-rails (2.26.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop (>= 1.52.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rspec (2.29.2)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
rubocop-rspec_rails (~> 2.28)
rubocop-rspec_rails (2.28.3)
rubocop (~> 1.40)
rubocop-rspec (3.1.0)
rubocop (~> 1.61)
rubocop-rspec_rails (2.30.0)
rubocop (~> 1.61)
rubocop-rspec (~> 3, >= 3.0.1)
ruby-progressbar (1.13.0)
strscan (3.1.0)
securerandom (0.3.1)
syntax_tree (6.2.0)
prettier_print (>= 1.2.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
unicode-display_width (2.6.0)

PLATFORMS
ruby
Expand Down
5 changes: 5 additions & 0 deletions app/services/problem_check/s2s_webinar_subscription.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class ProblemCheck::S2sWebinarSubscription < ProblemCheck::InlineProblemCheck
self.priority = "high"
end
16 changes: 8 additions & 8 deletions app/views/zoom/webinars/sdk.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script src="https://source.zoom.us/3.1.6/lib/vendor/react.min.js" nonce="<%= csp_nonce_placeholder %>"></script>
<script src="https://source.zoom.us/3.1.6/lib/vendor/react-dom.min.js" nonce="<%= csp_nonce_placeholder %>"></script>
<script src="https://source.zoom.us/3.1.6/lib/vendor/redux.min.js" nonce="<%= csp_nonce_placeholder %>"></script>
<script src="https://source.zoom.us/3.1.6/lib/vendor/redux-thunk.min.js" nonce="<%= csp_nonce_placeholder %>"></script>
<script src="https://source.zoom.us/3.1.6/lib/vendor/lodash.min.js" nonce="<%= csp_nonce_placeholder %>"></script>
<script src="https://source.zoom.us/zoom-meeting-3.1.6.min.js" nonce="<%= csp_nonce_placeholder %>"></script>
<link type="text/css" rel="stylesheet" href="https://source.zoom.us/3.1.6/css/bootstrap.css" />
<link type="text/css" rel="stylesheet" href="https://source.zoom.us/3.1.6/css/react-select.css" />
<script src="https://source.zoom.us/3.9.0/lib/vendor/react.min.js" nonce="<%= csp_nonce_placeholder %>"></script>
<script src="https://source.zoom.us/3.9.0/lib/vendor/react-dom.min.js" nonce="<%= csp_nonce_placeholder %>"></script>
<script src="https://source.zoom.us/3.9.0/lib/vendor/redux.min.js" nonce="<%= csp_nonce_placeholder %>"></script>
<script src="https://source.zoom.us/3.9.0/lib/vendor/redux-thunk.min.js" nonce="<%= csp_nonce_placeholder %>"></script>
<script src="https://source.zoom.us/3.9.0/lib/vendor/lodash.min.js" nonce="<%= csp_nonce_placeholder %>"></script>
<script src="https://source.zoom.us/zoom-meeting-3.9.0.min.js" nonce="<%= csp_nonce_placeholder %>"></script>
<link type="text/css" rel="stylesheet" href="https://source.zoom.us/3.9.0/css/bootstrap.css" />
<link type="text/css" rel="stylesheet" href="https://source.zoom.us/3.9.0/css/react-select.css" />

<script type="text/javascript" src="<%= asset_path('/plugins/discourse-zoom/javascripts/webinar-join.js') %>" nonce="<%= csp_nonce_placeholder %>"></script>

Expand Down
29 changes: 18 additions & 11 deletions assets/javascripts/discourse/components/modal/webinar-picker.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class WebinarPicker extends Component {
} catch (error) {
this.webinar = null;
this.selected = false;
this.error = true;
this.error = error.jqXHR.responseJSON.errors[0];
} finally {
this.loading = false;
}
Expand Down Expand Up @@ -250,7 +250,7 @@ export default class WebinarPicker extends Component {
{{else}}
{{#if this.error}}
<div class="alert alert-error">
{{i18n "zoom.error"}}
{{this.error}}
</div>
{{/if}}

Expand Down Expand Up @@ -285,15 +285,22 @@ export default class WebinarPicker extends Component {
{{else}}
<div class="webinar-picker-wrapper">
<div class="inline-form webinar-picker-input">
<Input
@type="text"
@value={{this.webinarIdInput}}
class="webinar-builder-id"
/>
<DButton
@action={{fn this.selectWebinar this.webinarIdInput}}
@icon="plus"
/>
<label>
<span>{{i18n "zoom.webinar_picker.webinar_id"}}</span>
<div class="inline-form">
<Input
@type="text"
@value={{this.webinarIdInput}}
class="webinar-builder-id"
/>

<DButton
@action={{fn this.selectWebinar this.webinarIdInput}}
@icon="plus"
/>
</div>
</label>

</div>
<div class="webinar-picker-add-past">
<DButton
Expand Down
10 changes: 10 additions & 0 deletions assets/stylesheets/common/webinar-picker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@

.webinar-picker-input {
text-align: center;

label {
display: flex;
flex-direction: column;
font-size: var(--font-0);

span {
margin-bottom: 0.5rem;
}
}
}

.webinar-picker-wrapper {
Expand Down
7 changes: 7 additions & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ en:
zoom_id:
webinar_in_use: "Another topic is already associated with this webinar."

zoom_plugin_errors:
s2s_oauth_authorization: "OAuth app is not authorized to make this request"
meeting_not_found: "Meeting not found or has expired"

dashboard:
problem:
s2s_webinar_subscription: "Zooom Plugin: Webinar plan is missing. You must suscribe to the webinar plan to have access to this feature"
system_messages:
webinar_reminder:
title: "Upcoming Webinar"
Expand Down
33 changes: 22 additions & 11 deletions lib/oauth_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,28 @@ def send_request(method, body = nil)
},
body: body&.to_json,
)

if [400, 401].include?(response.status) && @tries < @max_tries
get_oauth
response = send_request(method, body)
elsif [400, 401].include?(response.status) && @tries == @max_tries
self.parse_response_body(response)
# This code 200 is a code sent by Zoom not the request status
if response&.body&.dig(:code) == 200
ProblemCheckTracker["s2s_webinar_subscription"].problem!(
details: {
message: response.body[:message],
},
)
end

authorization_invalid
end

log("Zoom verbose log:\n API error = #{response.inspect}") if response.status != 200

if response&.body.present?
result = JSON.parse(response.body)
meeting_not_found if (response.status) == 404 && result["code"] == 3001
log("Zoom verbose log:\n API result = #{result.inspect}")
end
response
Expand Down Expand Up @@ -103,19 +113,20 @@ def get_oauth
end
end

def authorization_invalid
if @oauth
custom_mesasge =
"s2s_
oauth_authorization"
else
custom_mesasge = "custom_authorization"
end
def authorization_invalid(custom_message = nil)
custom_message = "s2s_oauth_authorization" if @oauth

raise Discourse::InvalidAccess.new(
"zoom_plugin_authorization_invalid",
"zoom_plugin_errors",
SiteSetting.s2s_oauth_token,
custom_message: "zoom_plugin_authorization_invalid.#{custom_mesasge}",
custom_message: "zoom_plugin_errors.#{custom_message}",
)
end

def meeting_not_found
raise Discourse::NotFound.new(
I18n.t("zoom_plugin_errors.meeting_not_found"),
custom_message: "zoom_plugin_errors.meeting_not_found",
)
end
end
Expand Down
2 changes: 2 additions & 0 deletions plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
register_svg_icon "video"

after_initialize do
require_relative "app/services/problem_check/s2s_webinar_subscription.rb"
register_problem_check ProblemCheck::S2sWebinarSubscription
module ::Zoom
PLUGIN_NAME ||= "discourse-zoom".freeze

Expand Down
4 changes: 2 additions & 2 deletions public/javascripts/webinar-join.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ window.onload = (event) => {

let request = new XMLHttpRequest();
request.open("GET", `/zoom/webinars/${meetingId}/signature.json`, true);

request.onload = function () {
if (this.status >= 200 && this.status < 400) {
let res = JSON.parse(this.response);
Expand All @@ -44,7 +44,7 @@ window.onload = (event) => {
userEmail: res.email,
success: function (res) {},
error: function (join_result) {
console.log(join_result);
// console.log(join_result);
if (join_result.errorCode === 1) {
const params = getParams(window.location.href);
if (params.fallback) {
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/oauth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
Authorization: "Bearer not_a_valid_token",
Host: "api.zoom.us",
},
).to_return(status: 400)
).to_return(body: ZoomApiStubs.get_webinar(user.id), status: 400)
end
describe "valid/present" do
before { SiteSetting.s2s_oauth_token = valid_token }
Expand Down Expand Up @@ -91,7 +91,7 @@
headers: {
content_type: "application/json",
},
status: 200,
status: 400,
)
end
it "can't request a new oauth_token" do
Expand Down
Loading