Skip to content

Conversation

@rsmithlal
Copy link
Member

@rsmithlal rsmithlal commented Jun 11, 2024

Summary of Changes

This pull request adds GitHub OAuth Integration to the Community Engine, enabling users to sign in using their GitHub accounts. It also introduces a new PersonPlatformIntegration model to track external platform connections (starting with GitHub), along with supporting views, controllers, and tests.


Key Changes

1. OAuth Support for GitHub Sign-In

  • Added omniauth, omniauth-github, and omniauth-rails_csrf_protection gems.
  • Configured Devise to support omniauthable with GitHub as a provider.
  • Implemented a custom OmniauthCallbacksController to handle GitHub authentication flow.

2. New PersonPlatformIntegration Model

  • Tracks the link between a Person and external platforms like GitHub.
  • Stores provider details (e.g., uid, access_token, profile_url).
  • Supports token refresh and re-authentication when required.

3. GitHub API Client

  • Added a BetterTogether::Github class for interacting with GitHub’s API using app installation tokens.
  • This prepares the foundation for future GitHub-powered features (like repository management or commits tracking).

4. New CRUD Interface for Managing Integrations

  • Admin views to list, view, edit, and delete platform integrations.
  • Fully scaffolded PersonPlatformIntegrationsController with views.
  • Supports direct management via web UI.

5. Updated User Model

  • User is now omniauthable, with a has_many :person_platform_integrations association.
  • Adds logic to map an OAuth auth hash into a user account, including automatic person creation if needed.

6. Migration and Database Changes

  • New better_together_person_platform_integrations table.
  • Supports storing token data, provider metadata, and raw auth hashes for auditing.

7. Gem and Dependency Updates

  • Added required gems to the gemspec and Gemfile.
  • Bumped redis, rubocop, and aws-sdk versions as part of routine updates.

Affected Files

  • 37 files changed
  • 854 additions, 27 deletions
  • New files include controllers, models, views, helpers, factories, specs, and migrations for the new integration system.

Why These Changes?

This is part of ongoing work to improve developer experience and make it easier for contributors to link their Community Engine accounts to external platforms. The GitHub integration lays the groundwork for:

  • Linking contributions (like commits and issues) to platform users.
  • Supporting future features such as GitHub-backed content imports, repository links, and contribution tracking.
  • Enabling flexible future authentication via additional OAuth providers (Google, Facebook, LinkedIn).

Testing

  • Basic feature specs added for the PersonPlatformIntegrationsController.
  • Manual flow tested locally: GitHub login, linking existing accounts, creating new accounts, and managing linked platforms.
  • Integration works with Devise confirmation, ensuring new users must confirm their email after signing up via GitHub.

Migration Required

✅ Run bin/rails db:migrate to apply the new better_together_person_platform_integrations table.


@rsmithlal rsmithlal self-assigned this Jun 11, 2024
@rsmithlal rsmithlal added the enhancement New feature or request label Jun 11, 2024
@rsmithlal rsmithlal changed the base branch from main to dev March 1, 2025 04:47
@rsmithlal rsmithlal changed the base branch from dev to main March 1, 2025 14:43
@rsmithlal rsmithlal changed the title WIP: test devise github oauth integration feature/ github oauth integration Mar 7, 2025
@rsmithlal rsmithlal changed the base branch from dev to main June 28, 2025 12:07
@rsmithlal rsmithlal requested a review from Copilot July 5, 2025 15:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR integrates GitHub OAuth into Community Engine and scaffolds new CRUD interfaces and tests for PersonPlatformIntegration and Seed models.

  • Adds empty view specs for seeds and authorizations to improve test coverage.
  • Introduces PersonPlatformIntegrationController with matching views and routes.
  • Implements model logic in PersonPlatformIntegration for handling tokens, but contains a minor bug.
  • Updates helper documentation and corrects a small typo.

Reviewed Changes

Copilot reviewed 82 out of 86 changed files in this pull request and generated no comments.

Show a summary per file
File Description
spec/views/better_together/seeds/show.html.erb_spec.rb Empty test stub—needs render and assertions
spec/views/better_together/person_platform_integrations/show.html.erb_spec.rb Empty test stub—needs render and assertions
app/controllers/better_together/person_platform_integrations_controller.rb Incorrect instance variable used in create action
app/models/better_together/person_platform_integration.rb Class method references undefined variable in attributes_from_omniauth
app/helpers/better_together/person_platform_integrations_helper.rb Spelling typo in module documentation
Comments suppressed due to low confidence (11)

spec/views/better_together/seeds/show.html.erb_spec.rb:11

  • Implement the render call and add expectations (e.g., expect(rendered).to match(...)) so this view spec actually verifies the output.
    # render

spec/views/better_together/seeds/new.html.erb_spec.rb:11

  • Uncomment and use render plus assert_select assertions to verify the form elements are present.
    # render

spec/views/better_together/seeds/index.html.erb_spec.rb:14

  • Add render and assertions (e.g., assert_select) to verify each seed is rendered in the list.
    # render

spec/views/better_together/seeds/edit.html.erb_spec.rb:15

  • Use render and assert_select to confirm the edit form targets the correct path and fields.
    # render

spec/views/better_together/person_platform_integrations/show.html.erb_spec.rb:11

  • Call render and then assert that the key attributes (provider, uid, etc.) actually appear in the output.
    # render

spec/views/better_together/person_platform_integrations/new.html.erb_spec.rb:11

  • Uncomment and implement the assert_select blocks after render to validate the new integration form fields.
    # render

spec/views/better_together/person_platform_integrations/index.html.erb_spec.rb:11

  • Add a render call and use assert_select to check that each integration is displayed correctly.
    # render

spec/views/better_together/person_platform_integrations/edit.html.erb_spec.rb:15

  • Include render and assert_select to ensure the edit form is rendered with correct action and input fields.
    # render

app/controllers/better_together/person_platform_integrations_controller.rb:27

  • The create action initializes @better_together_person_platform_integration but then calls @person_platform_integration.save. Rename the variable or call @better_together_person_platform_integration.save to avoid nil errors.
      @better_together_person_platform_integration = BetterTogether::PersonPlatformIntegration.new(person_platform_integration_params)

app/models/better_together/person_platform_integration.rb:82

  • attributes_from_omniauth is a class method and references person_platform_integration, which is undefined. Replace this check with if auth.persisted? or move it into an instance context.
      attributes[:profile_url] = auth.info.urls.first.last unless person_platform_integration.persisted?

app/helpers/better_together/person_platform_integrations_helper.rb:4

  • Fix typo: change conains to contains.
  # This module conains helper methods for PersonPLatformIntegrations

Copy link
Member Author

Choose a reason for hiding this comment

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

This needs to be removed

Copy link
Member Author

@rsmithlal rsmithlal left a comment

Choose a reason for hiding this comment

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

needs a lot of cleanup to remove the commits from the other feature branches

class PagesController < FriendlyResourceController # rubocop:todo Metrics/ClassLength
before_action :set_page, only: %i[show edit update destroy]

skip_before_action :check_platform_setup, unless: -> { ::BetterTogether::Platform.where(host: true).any? }
Copy link
Member Author

Choose a reason for hiding this comment

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

Update check to use host scope instead of where query

Copy link
Member Author

Choose a reason for hiding this comment

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

This needs to be removed or moved to seed branch

def locale_options_for_select(selected_locale = I18n.locale)
options_for_select(
I18n.available_locales.map { |locale| [I18n.t("locales.#{locale}", locale:), locale] },
I18n.available_locales.map { |locale| [I18n.t("better_together.languages.#{locale}", locale:), locale] },
Copy link
Member Author

Choose a reason for hiding this comment

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

Check this key

Copy link
Member Author

Choose a reason for hiding this comment

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

remove this

Copy link
Member Author

Choose a reason for hiding this comment

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

check these keys

Copy link
Member Author

Choose a reason for hiding this comment

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

remove and/or move to seeds branch

Copy link
Member Author

Choose a reason for hiding this comment

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

remove and/or move to seeds branch

Copy link
Member Author

Choose a reason for hiding this comment

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

remove and/or move to seeds branch

spec.add_dependency 'activerecord-postgis-adapter'
spec.add_dependency 'active_storage_svg_sanitizer'
spec.add_dependency 'active_storage_validations'
spec.add_dependency 'acts_as_tenant'
Copy link
Member Author

Choose a reason for hiding this comment

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

remove this change

active_storage_validations
activerecord-import
activerecord-postgis-adapter
acts_as_tenant
Copy link
Member Author

Choose a reason for hiding this comment

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

remove

# PATCH/PUT /seeds/1
def update
if @seed.update(seed_params)
redirect_to @seed, notice: 'Seed was successfully updated.', status: :see_other

Check notice

Code scanning / Brakeman

Possible unprotected redirect. Note

Possible unprotected redirect.
@@ -0,0 +1,10 @@
<p style="color: green"><%= notice %></p>

<%= render @person_platform_integration %>

Check notice

Code scanning / Brakeman

Render path contains parameter value. Note

Render path contains parameter value.
@@ -0,0 +1,10 @@
<p style="color: green"><%= notice %></p>

<%= render @seed %>

Check notice

Code scanning / Brakeman

Render path contains parameter value. Note

Render path contains parameter value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants