-
Notifications
You must be signed in to change notification settings - Fork 5
feature/ github oauth integration #561
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
Draft
rsmithlal
wants to merge
80
commits into
main
Choose a base branch
from
feature/github-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 14 commits
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
d4828f5
WIP: test devise github oauth integration
rsmithlal 7cc86e2
Update omniauth routes
rsmithlal fb4885b
update github oauth action
rsmithlal 68ea4bf
WIP: github oauth
rsmithlal 72a0030
WIP: github oauth use correct user class reference
rsmithlal a1a9b0a
WIP: github oauth use correct user method to process auth env data
rsmithlal 042249f
Only show oauth login links if param oauth_login=true
rsmithlal b7f8af6
adjustment for frozen arrays
rsmithlal ed709f5
WIP: initial foundation to integrate GitHub API using Octokit gem
rsmithlal 8f2f392
rubocop fixes
rsmithlal 163baea
WIP: Initial scaffolding of PersonPlatformIntegrations
rsmithlal 56253fe
WIP: Flesh out PersonPlatformIntegration
rsmithlal d0afb15
rubocop fixes
rsmithlal 1ec7f73
rubocop fixes
rsmithlal 8bc4afa
WIP: attempt to correctly sign_in the user after oauth
rsmithlal 3bdbd69
Rubocop fixes
rsmithlal 72272b1
Merge branch 'main' into feature/github-integration
rsmithlal ba905b6
Merge branch 'main' into feature/github-integration
rsmithlal e9caf22
Update Gemfile.lock
rsmithlal 4292d62
Improved references to ::BetterTogether modules
rsmithlal d2f638c
Improved success rate for generating page view urls
rsmithlal 4ac9afb
Add BetterTogether::Metrics::PageViewReport
rsmithlal 81bfbf2
Improve metrics reporting page with tabbed layout and add page view r…
rsmithlal ee4ff34
Add BetterTogether::Metrics::Pageable concern
rsmithlal 0cf31b7
Default locale to current_person's locale if not in params and person…
rsmithlal 93149c0
Rubocop fixes
rsmithlal fe025da
Address misaligned locale count and url csv headers
rsmithlal 12a9d28
Adjust heading level of new page view report header
rsmithlal df59892
Update rubyonrails.yml
rsmithlal dfb4dd0
rubocop:disable Style/CombinableLoops for page view report csv headers
rsmithlal 1254186
Relocate model concerns to models/concerns directory
rsmithlal 04ea923
Rename Metrics::Pageable concern to Viewable
rsmithlal 850edda
Add LinkClickReport and new tabbed section in link click report metri…
rsmithlal 4af60c2
Render conversations inside of communicator view
rsmithlal d9a4a1a
Re-implement flexible invitation model
rsmithlal 275fd16
Re-implement Post model
rsmithlal a773b3b
Re-implement Authorship system
rsmithlal e11d25a
Adjust page migration to use the bt_privacy helper
rsmithlal d12eee2
Make Community Searchable
rsmithlal 25c4405
Rubocop fixes
rsmithlal adbd0ea
Allow navigation items to have fallback urls that include their ident…
rsmithlal d3712d5
Improve structure of importmap channels
rsmithlal ce61d54
Add initial feature spec for setup wizard. Coverage 28.87%
rsmithlal bab1aeb
Disable html content for posts for now
rsmithlal 4872016
Set post slugged after slugged attribute is defined
rsmithlal 5bebdd0
Rubocop fixes
rsmithlal 09eda33
Merge branch 'dev' into feature/github-integration
rsmithlal ba02c2f
adjust omniauth route definitions
rsmithlal 1598daf
Rubocop fixes
rsmithlal e6f76c2
Potential fix for code scanning alert no. 7: CSRF protection weakened…
rsmithlal 2c28bd7
Rubocop fixes
rsmithlal 96f0560
Merge branch 'dev' into feature/github-integration
rsmithlal 71a142d
Merge branch 'dev' into feature/github-integration
rsmithlal 6324d4e
Build(deps): Bump active_storage_validations from 1.4.0 to 2.0.2
dependabot[bot] 4afdb1f
Build(deps): Bump redis from 5.3.0 to 5.4.0
dependabot[bot] b61e6b6
Build(deps): Bump aws-sdk-s3 from 1.181.0 to 1.182.0
dependabot[bot] df2125c
Build(deps): Bump ruby-openai from 7.3.1 to 7.4.0
dependabot[bot] ba84c40
Build(deps-dev): Bump rubocop from 1.72.2 to 1.73.0
dependabot[bot] d0ff490
Add ActsAsTenant to gemspec and Gemfile.lock
rsmithlal fdc0f66
Remove unlisted as an option for privacy
rsmithlal 728680a
No longer excluding db schema and migrations from string literal rubo…
rsmithlal 8700a1b
Improve the SetupWizard platform details page
rsmithlal 4add9dd
Move time zone control into a stimulus controller
rsmithlal d063df6
Move language translation keys under better_together namespace
rsmithlal 590b59a
Customize default theme colours
rsmithlal 4f616f6
Allow viewing default informational and promo pages without a host pl…
rsmithlal 20d1abc
Improve platform setup page copywriting
rsmithlal 7170747
Add BetterTogether::Seed
rsmithlal ea3b6df
refactor admin_creation setup wizard step to use same style as platfo…
rsmithlal b7c0c68
Add custom seed data config for BetterTogether::Wizard
rsmithlal 8ac0493
Merge branch 'dev' into feature/github-integration
rsmithlal eb7d6f9
Merge branch 'dev' into feature/github-integration
rsmithlal b7ef209
Merge branch 'main' into feature/github-integration
rsmithlal 61181ef
Merge branch 'main' into feature/github-integration
rsmithlal 6a7b670
Merge branch 'main' into feature/github-integration
rsmithlal 6bdb807
Merge branch 'main' into feature/github-integration
rsmithlal e623c52
Rubocop fixes
rsmithlal 0e1d92a
Rubocop fixes
rsmithlal 10d44f0
Rubocop fixes
rsmithlal 81bd298
Refactor destroy? method placement in PersonBlockPolicy
rsmithlal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
app/controllers/better_together/omniauth_callbacks_controller.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module BetterTogether | ||
| class OmniauthCallbacksController < Devise::OmniauthCallbacksController # rubocop:todo Style/Documentation | ||
| # See https://github.com/omniauth/omniauth/wiki/FAQ#rails-session-is-clobbered-after-callback-on-developer-strategy | ||
| skip_before_action :verify_authenticity_token, only: %i[github] | ||
|
||
|
|
||
| before_action :set_person_platform_integration, except: [:failure] | ||
| before_action :set_user, except: [:failure] | ||
|
|
||
| attr_reader :person_platform_integration, :user | ||
|
|
||
| def github | ||
| handle_auth 'Github' | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def handle_auth(kind) | ||
| if user_signed_in? | ||
| flash[:success] = t 'devise_omniauth_callbacks.success', kind: kind if is_navigational_format? | ||
| redirect_to edit_user_registration_path | ||
| else | ||
| flash[:alert] = | ||
| t 'devise_omniauth_callbacks.failure', kind:, reason: "#{auth.info.email} is not authorized" | ||
| redirect_to new_user_registration_path | ||
| end | ||
| end | ||
|
|
||
| def auth | ||
| request.env['omniauth.auth'] | ||
| end | ||
|
|
||
| def set_person_platform_integration | ||
| @person_platform_integration = PersonPlatformIntegration.find_by(provider: auth.provider, uid: auth.uid) | ||
| end | ||
|
|
||
| def set_user | ||
| @user = ::BetterTogether.user_class.from_omniauth(person_platform_integration:, auth:, current_user:) | ||
| end | ||
|
|
||
| def failure | ||
| flash[:error] = 'There was a problem signing you in. Please register or try signing in later.' | ||
| redirect_to helpers.base_url | ||
| end | ||
| end | ||
| end | ||
66 changes: 66 additions & 0 deletions
66
app/controllers/better_together/person_platform_integrations_controller.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module BetterTogether | ||
| # Allows for the management of PersonPlatformIntegrations | ||
| class PersonPlatformIntegrationsController < ApplicationController | ||
| before_action :set_person_platform_integration, only: %i[show edit update destroy] | ||
|
|
||
| # GET /better_together/person_platform_integrations | ||
| def index | ||
| @person_platform_integrations = BetterTogether::PersonPlatformIntegration.all | ||
| end | ||
|
|
||
| # GET /better_together/person_platform_integrations/1 | ||
| def show; end | ||
|
|
||
| # GET /better_together/person_platform_integrations/new | ||
| def new | ||
| @person_platform_integration = BetterTogether::PersonPlatformIntegration.new | ||
| end | ||
|
|
||
| # GET /better_together/person_platform_integrations/1/edit | ||
| def edit; end | ||
|
|
||
| # POST /better_together/person_platform_integrations | ||
| def create | ||
| # rubocop:todo Layout/LineLength | ||
| @better_together_person_platform_integration = BetterTogether::PersonPlatformIntegration.new(person_platform_integration_params) | ||
| # rubocop:enable Layout/LineLength | ||
|
|
||
| if @person_platform_integration.save | ||
| redirect_to @person_platform_integration, notice: 'PersonPlatformIntegration was successfully created.' | ||
| else | ||
| render :new, status: :unprocessable_entity | ||
| end | ||
| end | ||
|
|
||
| # PATCH/PUT /better_together/person_platform_integrations/1 | ||
| def update | ||
| if @person_platform_integration.update(person_platform_integration_params) | ||
| redirect_to @person_platform_integration, notice: 'PersonPlatformIntegration was successfully updated.', | ||
| status: :see_other | ||
| else | ||
| render :edit, status: :unprocessable_entity | ||
| end | ||
| end | ||
|
|
||
| # DELETE /better_together/person_platform_integrations/1 | ||
| def destroy | ||
| @person_platform_integration.destroy! | ||
| redirect_to person_platform_integrations_url, notice: 'PersonPlatformIntegration was successfully destroyed.', | ||
| status: :see_other | ||
| end | ||
|
|
||
| private | ||
|
|
||
| # Use callbacks to share common setup or constraints between actions. | ||
| def set_person_platform_integration | ||
| @person_platform_integration = BetterTogether::PersonPlatformIntegration.find(params[:id]) | ||
| end | ||
|
|
||
| # Only allow a list of trusted parameters through. | ||
| def person_platform_integration_params | ||
| params.require(:person_platform_integration).permit(:provider, :uid, :token, :secret, :profile_url, :user_id) | ||
| end | ||
| end | ||
| end |
7 changes: 7 additions & 0 deletions
7
app/helpers/better_together/person_platform_integrations_helper.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module BetterTogether | ||
| # This module conains helper methods for PersonPLatformIntegrations | ||
| module PersonPlatformIntegrationsHelper | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'octokit' | ||
|
|
||
| module BetterTogether | ||
| # This class allows integration with the GitHub API | ||
| class Github | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nest this under an Integrations namespace |
||
| def access_token | ||
| Octokit::Client.new(bearer_token: jwt).create_app_installation_access_token(Rails.application.credentials.dig( | ||
| :github, :installation_id | ||
| ))[:token] | ||
| end | ||
|
|
||
| def jwt | ||
| payload = { | ||
| iat: Time.now.to_i - 60, # issued at time | ||
| exp: Time.now.to_i + (10 * 60), | ||
| iss: Rails.application.credentials.dig(:github, :app_id) | ||
| } | ||
| JWT.encode(payload, private_key, 'RS256') | ||
| end | ||
|
|
||
| def private_key | ||
| @private_key ||= OpenSSL::PKey::RSA.new(private_pem) | ||
| end | ||
|
|
||
| def private_pem | ||
| @private_pem ||= Rails.application.credentials.dig(:github, :private_pem) | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.