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

Add Mastodon connector to settings / profile #1173

Merged
merged 20 commits into from
Feb 2, 2024

Conversation

jmcharter
Copy link
Contributor

Related to #1141

Adds a profile connector for Mastodon to settings and public profile.

This is similar to how GitHub and Twitter are currently handled, but with a key difference: There's no central app registration. Each instance requires OAuth app registration. I've handled this by registering with an instance the first time a user connects and storing the client_id and client_secret for future connections.

@pushcx
Copy link
Member

pushcx commented Apr 26, 2023

Thanks for taking on such a big feature! The Twitter endpoint is getting less reliable, so this is pretty timely.

It looks like you’ve made a solid start. I can see you’re still working on this, so please @mention me when you’re ready for a review

</p>

<div class="boxline">
<%= f.label :mastodon_instance_name, "Mastodon Instance:", :class => "required" %>
Copy link
Member

Choose a reason for hiding this comment

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

We have a few placeholder attributes in the code, I think this would be a good place for one. With the way you wrote sanitized_instance_name, you don’t even need to include the instruction above about not including https.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, good point! I added sanitized_instance_name later. I'll await further review before making any changes, but I've noted this.

@jmcharter
Copy link
Contributor Author

@pushcx no problem. I'll be very happy to see Mastodon added as social connection option.
I was fighting with github actions to get the tests to pass, but this should be in a good state to review as it is. If you pull and run it locally you'll be able to successfully connect a Mastodon account.

Please review whenever you have time.

@jmcharter jmcharter requested a review from pushcx May 3, 2023 10:35
@pushcx pushcx mentioned this pull request May 3, 2023
13 tasks
Copy link
Member

@pushcx pushcx left a comment

Choose a reason for hiding this comment

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

This is a solid start, I see how you got it working with a minimum of fuss. I left some small notes, but this also needs some high-level rearranging.

The User model should has_one :mastodon_instance rather than repeating the instance name. The functions in Mastodon that take instance_name as an argument should move into MastodonInstance (perhaps register_application should be a factory?).

:scope => "read"
).body
ps = JSON.parse(res)
puts "ps:", ps
Copy link
Member

Choose a reason for hiding this comment

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

Remove debugging statements.

:post,
:client_id => client_id,
:client_secret => client_secret,
:redirect_uri => "http://localhost:3000/settings/mastodon_callback?instance=#{instance}",
Copy link
Member

Choose a reason for hiding this comment

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

Replace local host with Rails.application.domain

extras/mastodon.rb Outdated Show resolved Hide resolved
extras/mastodon.rb Outdated Show resolved Hide resolved
extras/mastodon.rb Outdated Show resolved Hide resolved
app/views/settings/index.html.erb Show resolved Hide resolved
<% end %>

<div class="box wide">
<%= form_with url: "/settings/mastodon_auth", method: :get do |f| %>
Copy link
Member

Choose a reason for hiding this comment

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

Use the Rails url generation here and above. Run rails routes in your console to see the name for this endpoint, then add _path to generate a relative URL.

return mastodon_disconnect
end

return redirect_to "/settings"
Copy link
Member

Choose a reason for hiding this comment

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

settings_path, redundant return


<div class="boxline">
<%= f.label :mastodon_instance_name, "Mastodon Instance:", :class => "required" %>
<%= f.text_field :mastodon_instance_name, :autofocus => true %>
Copy link
Member

Choose a reason for hiding this comment

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

Remove autofocus

return redirect_to "/settings"
end

tok, username = Mastodon.token_and_user_from_code(params[:instance], params[:code])
Copy link
Member

Choose a reason for hiding this comment

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

I think this creates duplicate MastodonInstances when two users use the same Instance. You probably want MastodonInstance.find_or_create_by

@jmcharter
Copy link
Contributor Author

@pushcx thanks for taking the time to review this PR. My inexperience with Ruby / Rails is shining through, clearly.
I'll go through the changes you've suggest at some point this weekend and come back to you if I have any questions; otherwise I'll make the the changes and ping you for another review once I'm done.

@pushcx pushcx force-pushed the master branch 2 times, most recently from 1944bdd to 1c73b2a Compare August 31, 2023 15:07
@jmcharter jmcharter closed this Oct 21, 2023
@jmcharter jmcharter reopened this Oct 21, 2023
@pushcx
Copy link
Member

pushcx commented Feb 2, 2024

@jmcharter Thanks for taking this on. I had some free dev time so I decided to get this over the line.

@pushcx pushcx merged commit 67c1959 into lobsters:master Feb 2, 2024
1 check failed
@jmcharter
Copy link
Contributor Author

jmcharter commented Feb 2, 2024

@pushcx thanks for doing so - I've always meant to come back to this, but you know how it is. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants