Skip to content
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
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ gem "rqrcode"
gem "redcarpet"
gem "rouge"
gem "jbuilder"
gem "actiontext-lexical", bc: "actiontext-lexical"
gem "actiontext-lexical", bc: "actiontext-lexical", branch: "flavorjones/unfurl-url"
gem "image_processing", "~> 1.14"
gem "platform_agent"
gem "aws-sdk-s3", require: false
gem "rich_link", bc: "rich_link"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's great to have a gem to centralize this logic! For your consideration: I think it would be fine if the gem just exposed the API to unfurl the link (e.g: to get the title for the link), and then the host app introduces its own controller using that gem. That would simplify the authentication stuff and, more importantly, would allow different apps to configure the unfurl logic differently. This goes in the line of the suggestion about whether Lexical should support getting arbitrary HTML replacements for links.

For example, In Fizzy, we could choose to present "Fizzy links" with some custom HTML, while in Basecamp, we present those as regular links. Or we could choose to unfurl other types of links differently (E.g: PDF links using the PDF viewer in Basecamp). Both apps could use the same API to extract the title of "supported apps links", but would assume how to present the links (even if we duplicate the same rendering logic in both apps, I think that's fine).


# 37id and Queenbee integration
gem "signal_id", bc: "signal_id", branch: "rails4"
Expand Down
17 changes: 16 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
GIT
remote: https://github.com/basecamp/actiontext-lexical
revision: 109735daa044233236cf7a72f30043e5c790e853
revision: 9f47937e22e1f374bf43215d9f62a2a29fe19728
branch: flavorjones/unfurl-url
specs:
actiontext-lexical (0.1.0)
rails (>= 8.0.2)
Expand Down Expand Up @@ -73,6 +74,17 @@ GIT
json
rails (>= 6.0.0)

GIT
remote: https://github.com/basecamp/rich_link
revision: ef56fd6aaa10ade1fc5e0865b1426bd5446e5533
specs:
rich_link (0.1.0)
faraday
faraday-follow_redirects
nokogiri
rails (>= 8.0.2)
signal_id

GIT
remote: https://github.com/basecamp/service_concurrency_prevention
revision: 320da99431718615ed86f8723e8b9d3259c602a3
Expand Down Expand Up @@ -291,6 +303,8 @@ GEM
faraday-net_http (>= 2.0, < 3.5)
json
logger
faraday-follow_redirects (0.3.0)
faraday (>= 1, < 3)
faraday-multipart (1.1.1)
multipart-post (~> 2.0)
faraday-net_http (3.4.1)
Expand Down Expand Up @@ -607,6 +621,7 @@ DEPENDENCIES
rails!
rails_structured_logging!
redcarpet
rich_link!
rouge
rqrcode
rubocop-rails-omakase
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/concerns/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module Authentication
extend ActiveSupport::Concern

included do
include RichLink::Authentication

# Checking for tenant must happen first so we redirect before trying to access the db.
before_action :require_tenant

Expand Down Expand Up @@ -39,7 +41,7 @@ def require_tenant
end

def require_authentication
resume_session || request_authentication
resume_session || authenticate_by_rich_link_token || request_authentication
end

def resume_session
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/rich_text_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ def commands_prompt
def cards_prompt
content_tag "lexical-prompt", "", trigger: "#", src: prompts_cards_path, name: "card", "insert-editable-text": true, "remote-filtering": true
end

def rich_link_unfurl_url
File.join(request.script_name, RichLink::Engine.routes.url_helpers.unfurl_path)
end
end
11 changes: 9 additions & 2 deletions app/models/current.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
class Current < ActiveSupport::CurrentAttributes
attribute :session
attribute :session, :user
attribute :http_method, :request_id, :user_agent, :ip_address, :referrer
attribute :account

delegate :user, to: :session, allow_nil: true
def session=(session)
super
Current.user = session&.user
end

def signal_user=(signal_user)
self.user = signal_user&.peer
end
end
3 changes: 2 additions & 1 deletion app/views/cards/comments/_new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
local_save_key_value: "comment-#{card.id}",
action: "turbo:submit-end->local-save#submit keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel:stop" } do |form| %>
<%= form.rich_textarea :body, required: true, placeholder: new_comment_placeholder(card),
data: { local_save_target: "input", action: "actiontext:change->local-save#save turbo:morph-element->local-save#restoreContent" } do %>
data: { local_save_target: "input", unfurl_url: rich_link_unfurl_url,
action: "actiontext:change->local-save#save turbo:morph-element->local-save#restoreContent" } do %>
<%= mentions_prompt(@card.collection) %>
<%= cards_prompt %>
<% end %>
Expand Down
3 changes: 2 additions & 1 deletion app/views/cards/comments/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<div class="comment__body rich-text-content txt-align-start">
<%= form_with model: [ @card, @comment ], class: "flex flex-column gap full-width",
data: { controller: "form", action: "keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel:stop" } do |form| %>
<%= form.rich_textarea :body, required: true, autofocus: true, placeholder: new_comment_placeholder(@card) do %>
<%= form.rich_textarea :body, required: true, autofocus: true, placeholder: new_comment_placeholder(@card),
data: { unfurl_url: rich_link_unfurl_url } do %>
<%= mentions_prompt(@card.collection) %>
<%= cards_prompt %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/cards/container/_title.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<div class="card__description rich-text-content margin-block-start-half margin-block-end">
<%= form.rich_textarea :description, class: "card-field__description",
placeholder: "Add some notes, context, pictures, or video about this…",
data: { action: "actiontext:change->auto-save#change focusout->auto-save#submit keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel:stop" } do %>
data: { unfurl_url: rich_link_unfurl_url, action: "actiontext:change->auto-save#change focusout->auto-save#submit keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel:stop" } do %>
<%= mentions_prompt(card.collection) %>
<%= cards_prompt %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/cards/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<%= form.rich_textarea :description, class: "card-field__description rich-text-content",
placeholder: "Add some notes, context, pictures, or video about this…",
data: { action: "keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel:stop" } do %>
data: { unfurl_url: rich_link_unfurl_url, action: "keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel:stop" } do %>
<%= mentions_prompt(@card.collection) %>
<%= cards_prompt %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/collections/edit/_publication.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<%= form_with model: collection, class: "txt-align-start", data: { controller: "form" } do |form| %>
<%= form.rich_textarea :public_description, class: "rich-text-content txt-small",
placeholder: "Add a public note about this collection…",
data: { action: "keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel:stop" } %>
data: { unfurl_url: rich_link_unfurl_url, action: "keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel:stop" } %>
<%= form.button "Save changes", type: :submit, class: "btn txt-small" %>
<% end %>
</div>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
root "events#index"

Queenbee.routes(self)
mount RichLink::Engine => "/rich_link"

namespace :admin do
mount MissionControl::Jobs::Engine, at: "/jobs"
Expand Down