A platform for community discussion. Free, open, simple.
FEATURE: add Google Meet oneboxes (#41018)
Sama55af064062f
diff --git a/app/assets/stylesheets/common/base/onebox.scss b/app/assets/stylesheets/common/base/onebox.scssindex 9bd1a0a0a29..d23eeae8ad7 100644--- a/app/assets/stylesheets/common/base/onebox.scss+++ b/app/assets/stylesheets/common/base/onebox.scss@@ -358,6 +358,69 @@ aside.onebox {@include gdocs-logo("drive");}+.google-meet-onebox {+ display: grid;+ grid-template-columns: auto minmax(0, 1fr);+ align-items: start;+ gap: 1em;+ overflow-wrap: anywhere;++ &__icon {+ display: flex;+ flex: 0 0 auto;+ align-items: center;+ justify-content: center;+ width: 3.25em;+ height: 3.25em;+ margin-block-start: 0.15em;+ color: var(--primary-medium);+ background: var(--primary-very-low);+ border: 1px solid var(--primary-low);+ border-radius: var(--d-border-radius);+ }++ &__icon .d-icon {+ width: 1.5em;+ height: 1.5em;+ }++ &__content {+ display: grid;+ min-width: 0;+ justify-items: start;+ gap: 0.55em;+ }++ &__code,+ &__description {+ margin: 0;+ color: var(--primary-high);+ }++ &__code {+ display: flex;+ flex-wrap: wrap;+ align-items: baseline;+ gap: 0.35em;+ }++ &__code-value {+ padding: 0.15em 0.35em;+ font-family: var(--d-font-family--monospace);+ background: var(--primary-very-low);+ border: 1px solid var(--primary-low);+ border-radius: var(--d-border-radius);+ }++ &__join {+ font-weight: 600;+ }+}++aside.onebox .onebox-body .google-meet-onebox__title {+ margin: 0;+}+// Google Calendar Placeholder.gdocs-onebox-splash {background-color: var(--primary-low-mid);diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 3389c6f9427..3e60a8db59d 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -5925,6 +5925,11 @@ en:onebox:discourse:user_joined_community: "Joined %{date}"+ google_meet:+ title: "Google Meet meeting"+ description: "Open this Google Meet link to join the call."+ meeting_code: "Code:"+ join: "Join meeting"gitlab:truncated_file: "This file has been truncated."show_original: "show original"diff --git a/lib/onebox/engine.rb b/lib/onebox/engine.rbindex bdc911dd5ce..9065311442b 100644--- a/lib/onebox/engine.rb+++ b/lib/onebox/engine.rb@@ -195,6 +195,7 @@ require_relative "engine/github_pull_request_onebox"require_relative "engine/google_calendar_onebox"require_relative "engine/google_docs_onebox"require_relative "engine/google_maps_onebox"+require_relative "engine/google_meet_onebox"require_relative "engine/google_play_app_onebox"require_relative "engine/image_onebox"require_relative "engine/video_onebox"diff --git a/lib/onebox/engine/google_meet_onebox.rb b/lib/onebox/engine/google_meet_onebox.rbnew file mode 100644index 00000000000..a6bcf45b311--- /dev/null+++ b/lib/onebox/engine/google_meet_onebox.rb@@ -0,0 +1,48 @@+# frozen_string_literal: true++module Onebox+ module Engine+ class GoogleMeetOnebox+ include Engine+ include LayoutSupport++ MEETING_CODE_PATH = %r{\A/(?<code>[a-z]{3}-[a-z]{4}-[a-z]{3})/?\z}i+ LOOKUP_PATH = %r{\A/lookup/[a-z0-9_-]{3,64}/?\z}i++ matches_domain("meet.google.com")+ always_https++ def self.matches_path(path)+ path.match?(MEETING_CODE_PATH) || path.match?(LOOKUP_PATH)+ end++ def inline_data+ { title: I18n.t("onebox.google_meet.title") }+ end++ private++ def data+ @data ||=+ begin+ meeting_code = parsed_meeting_code++ {+ link: link,+ domain: "Google Meet",+ title: I18n.t("onebox.google_meet.title"),+ description: meeting_code.blank? ? I18n.t("onebox.google_meet.description") : nil,+ meeting_code: meeting_code,+ meeting_code_label: I18n.t("onebox.google_meet.meeting_code"),+ join_label: I18n.t("onebox.google_meet.join"),+ }+ end+ end++ def parsed_meeting_code+ match = uri.path.match(MEETING_CODE_PATH)+ match&.[](:code)&.downcase+ end+ end+ end+enddiff --git a/lib/onebox/templates/googlemeet.mustache b/lib/onebox/templates/googlemeet.mustachenew file mode 100644index 00000000000..2d5121c943e--- /dev/null+++ b/lib/onebox/templates/googlemeet.mustache@@ -0,0 +1,26 @@+<div class="google-meet-onebox">+ <div class="google-meet-onebox__icon">+ <svg class="fa d-icon d-icon-video svg-icon svg-string" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">+ <use href="#video"></use>+ </svg>+ </div>++ <div class="google-meet-onebox__content">+ <h3 class="google-meet-onebox__title">+ <a href="{{link}}" target="_blank" rel="noopener">{{title}}</a>+ </h3>++ {{#meeting_code}}+ <p class="google-meet-onebox__code">+ <span class="google-meet-onebox__code-label">{{meeting_code_label}}</span>+ <code class="google-meet-onebox__code-value">{{meeting_code}}</code>+ </p>+ {{/meeting_code}}++ {{#description}}+ <p class="google-meet-onebox__description">{{description}}</p>+ {{/description}}++ <a class="google-meet-onebox__join" href="{{link}}" target="_blank" rel="noopener">{{join_label}}</a>+ </div>+</div>diff --git a/lib/oneboxer.rb b/lib/oneboxer.rbindex 79aa175ad63..1cbef72076b 100644--- a/lib/oneboxer.rb+++ b/lib/oneboxer.rb@@ -35,6 +35,7 @@ module Oneboxer"https://new.reddit.com","https://www.youtube.com","https://youtu.be",+ "https://meet.google.com","https://twitter.com","https://x.com",Discourse.base_url,diff --git a/lib/svg_sprite.rb b/lib/svg_sprite.rbindex b218e412a8d..9e20499c14c 100644--- a/lib/svg_sprite.rb+++ b/lib/svg_sprite.rb@@ -288,6 +288,7 @@ module SvgSpriteuser-shielduser-xmarkusers+ videowand-magicwrenchxmarkdiff --git a/spec/lib/onebox/engine/google_meet_onebox_spec.rb b/spec/lib/onebox/engine/google_meet_onebox_spec.rbnew file mode 100644index 00000000000..312f3e6e16d--- /dev/null+++ b/spec/lib/onebox/engine/google_meet_onebox_spec.rb@@ -0,0 +1,146 @@+# frozen_string_literal: true++RSpec.describe Onebox::Engine::GoogleMeetOnebox do+ let(:meeting_url) { "https://meet.google.com/ezj-ptyx-gkp" }++ it "uses an icon included in the default SVG sprite" do+ aggregate_failures do+ expect(SvgSprite.search("video")).to be_present+ expect(SvgSprite.all_icons).to include("video")+ end+ end++ describe ".===" do+ it "is selected before the generic engine" do+ engine = Onebox::Matcher.new(meeting_url, { allowed_iframe_regexes: [/.*/] }).oneboxed++ expect(engine).to be(described_class)+ end++ it "matches Google Meet meeting URLs" do+ aggregate_failures do+ expect(described_class === URI("https://meet.google.com/ezj-ptyx-gkp")).to eq(true)+ expect(described_class === URI("http://meet.google.com/ezj-ptyx-gkp")).to eq(true)+ expect(described_class === URI("https://meet.google.com/ezj-ptyx-gkp/")).to eq(true)+ expect(described_class === URI("https://meet.google.com/ezj-ptyx-gkp?authuser=0")).to eq(+ true,+ )+ expect(described_class === URI("https://meet.google.com/EZJ-PTYX-GKP")).to eq(true)+ expect(described_class === URI("https://meet.google.com/lookup/team-standup_1")).to eq(true)+ end+ end++ it "rejects non-meeting URLs" do+ aggregate_failures do+ expect(described_class === URI("https://meet.google.com.evil.com/ezj-ptyx-gkp")).to eq(+ false,+ )+ expect(described_class === URI("https://sub.meet.google.com/ezj-ptyx-gkp")).to eq(false)+ expect(described_class === URI("https://meet.google.com/unsupported")).to eq(false)+ expect(described_class === URI("https://meet.google.com/new")).to eq(false)+ expect(described_class === URI("https://meet.google.com/abcdefghij")).to eq(false)+ expect(described_class === URI("https://meet.google.com/onboarding")).to eq(false)+ expect(described_class === URI("https://meet.google.com/abc-defg-hij/extra")).to eq(false)+ expect(described_class === URI("https://google.com/ezj-ptyx-gkp")).to eq(false)+ end+ end+ end++ describe "#to_html" do+ it "renders a static meeting card" do+ html = Onebox.preview(meeting_url).to_s+ document = Nokogiri::HTML5.fragment(html)+ join_link = document.at_css(".google-meet-onebox__join")++ aggregate_failures do+ expect(document.at_css("aside.onebox.googlemeet")).to be_present+ expect(document.at_css("iframe")).to be_nil+ expect(document.at_css(".google-meet-onebox__icon use")["href"]).to eq("#video")+ expect(document.at_css(".google-meet-onebox__title").text).to include("Google Meet meeting")+ expect(document.at_css(".google-meet-onebox__code-label").text).to include("Code:")+ expect(document.at_css(".google-meet-onebox__code-value").text).to eq("ezj-ptyx-gkp")+ expect(join_link["class"]).to eq("google-meet-onebox__join")+ expect(join_link.text).to include("Join meeting")+ expect(join_link["href"]).to eq(meeting_url)+ expect(html).not_to include("Google Workspace")+ expect(html).not_to include("Online web and video conferencing calls")+ end+ end++ it "escapes malicious query strings" do+ attack_payload = %("><script>alert(1)</script>)+ malicious_url = "https://meet.google.com/tiw-gooe-vbs?authuser=#{attack_payload}"+ normalized_url = UrlHelper.normalized_encode(malicious_url).to_s+ escaped_url = Onebox::Helpers.uri_encode(normalized_url)++ Oneboxer.invalidate(normalized_url)++ html = Oneboxer.onebox(malicious_url)+ document = Nokogiri::HTML5.fragment(html)++ aggregate_failures do+ expect(document.css("script")).to be_empty+ expect(html).not_to include(attack_payload)+ expect(document.at_css("aside.onebox.googlemeet")["data-onebox-src"]).to eq(escaped_url)+ expect(document.css("a").map { |link| link["href"] }.uniq).to eq([escaped_url])+ expect(document.at_css(".google-meet-onebox__code-value").text).to eq("tiw-gooe-vbs")+ end+ end++ it "keeps the original meeting URL when Google redirects" do+ redirected_url =+ "https://meet.google.com/unsupported?meetingCode=tiw-gooe-vbs&ref=https://meet.google.com/tiw-gooe-vbs"+ head_stub =+ stub_request(:head, "https://meet.google.com/tiw-gooe-vbs").to_return(+ status: 302,+ body: "",+ headers: {+ "location" => redirected_url,+ },+ )+ redirect_stub = stub_request(:any, redirected_url)++ Oneboxer.invalidate("https://meet.google.com/tiw-gooe-vbs")++ html = Oneboxer.external_onebox("https://meet.google.com/tiw-gooe-vbs")[:onebox]+ document = Nokogiri::HTML5.fragment(html)++ aggregate_failures do+ expect(document.at_css("aside.onebox.googlemeet")).to be_present+ expect(document.at_css(".google-meet-onebox__code-value").text).to eq("tiw-gooe-vbs")+ expect(document.at_css(".google-meet-onebox__join")["href"]).to eq(+ "https://meet.google.com/tiw-gooe-vbs",+ )+ expect(html).not_to include("/unsupported")+ expect(head_stub).not_to have_been_requested+ expect(redirect_stub).not_to have_been_requested+ end+ end++ it "normalizes uppercase meeting codes" do+ html = Onebox.preview("https://meet.google.com/EZJ-PTYX-GKP").to_s+ document = Nokogiri::HTML5.fragment(html)++ expect(document.at_css(".google-meet-onebox__code-value").text).to eq("ezj-ptyx-gkp")+ end++ it "renders lookup links without a meeting code" do+ html = Onebox.preview("https://meet.google.com/lookup/team-standup_1").to_s+ document = Nokogiri::HTML5.fragment(html)++ aggregate_failures do+ expect(document.at_css("aside.onebox.googlemeet")).to be_present+ expect(document.at_css(".google-meet-onebox__code-value")).to be_nil+ expect(document.at_css(".google-meet-onebox__description").text).to include(+ "Open this Google Meet link to join the call.",+ )+ end+ end+ end++ describe "#inline_data" do+ it "returns a concise inline onebox title" do+ expect(Oneboxer.inline_data_for(meeting_url)).to eq(title: "Google Meet meeting")+ end+ end+end