-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#256] Ability to connect another integration
- Loading branch information
Showing
13 changed files
with
141 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class UsersController < ApplicationController | ||
def show | ||
@user = find_user | ||
@github_auth = @user.user_references.find { |reference| reference.auth_provider == OmniauthConstants::GITHUB } | ||
@gitlab_auth = @user.user_references.find { |reference| reference.auth_provider == OmniauthConstants::GITLAB } | ||
end | ||
|
||
private | ||
|
||
def find_user | ||
authorize User.includes(user_references: :auth_info).find(params[:id]), :show?, policy_class: UserPolicy | ||
end | ||
end |
This file contains 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 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,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class UserPolicy < ApplicationPolicy | ||
def show? | ||
return true if user.system_role == UserConstants::SystemRoles::ADMIN | ||
|
||
user.actual_user == record | ||
end | ||
end |
This file contains 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 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,51 @@ | ||
# frozen_string_literal: true | ||
|
||
module Auth | ||
class AnotherServiceConnection | ||
def initialize(auth_info_presenter, current_user) | ||
@auth_info_presenter = auth_info_presenter | ||
@current_user = current_user | ||
end | ||
|
||
def call | ||
user_reference = UserReference.find_by(auth_uid: @auth_info_presenter.uid, auth_provider: @auth_info_presenter.provider) | ||
ensure_user_is_ready!(user_reference) | ||
|
||
ActiveRecord::Base.transaction do | ||
user_reference = user_reference.present? ? update_reference(user_reference) : create_reference | ||
create_auth_info(user_reference) | ||
end | ||
|
||
ReturnValue.ok(@current_user.actual_user) | ||
rescue ::Auth::NotPermittedError => error | ||
ReturnValue.error(errors: error.message) | ||
end | ||
|
||
private | ||
|
||
def ensure_user_is_ready!(user_reference) | ||
checker = Auth::AccessibilityCheck.new(user_reference, @auth_info_presenter.email) | ||
checker.ensure_reference_is_not_connected! | ||
checker.ensure_email_is_the_same!(@current_user) | ||
end | ||
|
||
def update_reference(user_reference) | ||
user_reference.update!(user: @current_user.actual_user) | ||
user_reference | ||
end | ||
|
||
def create_reference | ||
UserReference.create!( | ||
user: @current_user.actual_user, | ||
auth_uid: @auth_info_presenter.uid, | ||
auth_provider: @auth_info_presenter.provider, | ||
full_name: @auth_info_presenter.full_name | ||
) | ||
end | ||
|
||
def create_auth_info(user_reference) | ||
auth_info_params = Auth::AuthInfoParamsBuilder.new(@auth_info_presenter, user_reference).call | ||
AuthInfo.create!(auth_info_params) | ||
end | ||
end | ||
end |
This file contains 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 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 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 |
---|---|---|
|
@@ -24,5 +24,9 @@ def email | |
def token | ||
auth_info.token | ||
end | ||
|
||
def actual_user | ||
@user | ||
end | ||
end | ||
end |
This file contains 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 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,23 @@ | ||
.container | ||
= render partial: "shared/breadcrumb", locals: {\ | ||
text_link_hash: {\ | ||
"User" => nil\ | ||
}, | ||
class: "mt-4" } | ||
|
||
|
||
.d-flex.justify-content-between.mt-4 | ||
h1 = current_user.full_name | ||
.mt-4 | ||
p | ||
= image_pack_tag("media/images/logos/github-logo.svg", size: "32x32", class: "mr-2") | ||
- if @github_auth.present? | ||
span.text-success Github integration connected! | ||
- else | ||
= link_to "Click to connect Github", omniauth_path("github"), method: :post | ||
p | ||
= image_pack_tag("media/images/logos/gitlab-logo.svg", size: "32x32", class: "mr-2") | ||
- if @gitlab_auth.present? | ||
span.text-success Gitlab integration connected! | ||
- else | ||
= link_to "Click to connect Gitlab", omniauth_path("gitlab", some_data: "123"), method: :post |
This file contains 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