Skip to content
Open
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 app/controllers/leaderboards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ def index
country: country,
leaderboard: leaderboard_metadata(leaderboard),
is_logged_in: current_user.present?,
github_uid_blank: current_user&.github_uid.blank? || false,
repo_host_account_blank: !current_user&.repo_host_connected?,
github_auth_path: "/auth/github",
gitlab_auth_path: "/auth/gitlab",
settings_path: my_settings_path,
entries: InertiaRails.defer { entries_payload(leaderboard, leaderboard_scope, country) }
}
Expand Down
13 changes: 7 additions & 6 deletions app/controllers/my/project_repo_mappings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class My::ProjectRepoMappingsController < InertiaController
layout "inertia", only: [ :index ]

before_action :ensure_current_user
before_action :require_github_oauth, only: [ :edit, :update ]
before_action :require_repo_host_oauth, only: [ :edit, :update ]
before_action :set_project_repo_mapping_for_edit, only: [ :edit, :update ]
before_action :set_project_repo_mapping, only: [ :archive, :unarchive ]

Expand All @@ -14,8 +14,9 @@ def index
index_path: my_projects_path,
show_archived: archived,
archived_count: current_user.project_repo_mappings.archived.count,
github_connected: current_user.github_uid.present?,
repo_host_connected: current_user.repo_host_connected?,
github_auth_path: github_auth_path,
gitlab_auth_path: gitlab_auth_path,
settings_path: my_settings_path(anchor: "user_github_account"),
interval: selected_interval,
from: params[:from],
Expand Down Expand Up @@ -60,9 +61,9 @@ def ensure_current_user
redirect_to root_path, alert: "You must be logged in to view this page" unless current_user
end

def require_github_oauth
unless current_user.github_uid.present?
flash[:alert] = "Please connect your GitHub account to map repositories."
def require_repo_host_oauth
unless current_user.repo_host_connected?
flash[:alert] = "Please connect your GitHub or GitLab account to map repositories."
redirect_to my_projects_path
end
end
Expand Down Expand Up @@ -142,7 +143,7 @@ def projects_payload(archived:)
repo_url: mapping&.repo_url,
repository: repository_payload(mapping&.repository, latest_user_commit_at_by_repo_id),
broken_name: broken,
manage_enabled: current_user.github_uid.present? && url_safe,
manage_enabled: current_user.repo_host_connected? && url_safe,
edit_path: url_safe ? edit_my_project_repo_mapping_path(project_key) : nil,
update_path: url_safe ? my_project_repo_mapping_path(project_key) : nil,
archive_path: url_safe ? archive_my_project_repo_mapping_path(project_key) : nil,
Expand Down
57 changes: 56 additions & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,66 @@ def github_unlink
return
end

current_user.update!(github_access_token: nil, github_uid: nil, github_username: nil)
current_user.update!(github_access_token: nil, github_uid: nil, github_username: nil, github_avatar_url: nil)
Rails.logger.info "GitHub account unlinked for User ##{current_user.id}"
redirect_to my_settings_path, notice: "GitHub account unlinked successfully"
end

def gitlab_new
unless current_user
redirect_to root_path, alert: "Please sign in first to link your GitLab account"
return
end

redirect_uri = url_for(action: :gitlab_create, only_path: false)
oauth_nonce = SecureRandom.hex(24)
session[:gitlab_oauth_state_nonce] = oauth_nonce
Rails.logger.info "Starting GitLab OAuth flow with redirect URI: #{redirect_uri}"
redirect_to User.gitlab_authorize_url(redirect_uri, state: oauth_nonce),
allow_other_host: "https://gitlab.com"
end

def gitlab_create
unless current_user
redirect_to root_path, alert: "Please sign in first to link your GitLab account"
return
end

redirect_uri = url_for(action: :gitlab_create, only_path: false)

if params[:error].present?
report_message("GitLab OAuth error: #{params[:error]}")
redirect_to my_settings_path, alert: "Failed to authenticate with GitLab. Error ID: #{Sentry.last_event_id}"
return
end

unless valid_oauth_state?(provider: "GitLab", session_key: :gitlab_oauth_state_nonce, received_nonce: params[:state])
redirect_to my_settings_path, alert: "Failed to link GitLab account"
return
end

@user = User.from_gitlab_token(params[:code], redirect_uri, current_user)

if @user&.persisted?
PosthogService.capture(@user, "gitlab_linked")
redirect_to my_settings_path, notice: "Successfully linked GitLab account!"
else
report_message("Failed to link GitLab account")
redirect_to my_settings_path, alert: "Failed to link GitLab account"
end
end

def gitlab_unlink
unless current_user
redirect_to root_path, alert: "Please sign in first"
return
end

current_user.update!(gitlab_access_token: nil, gitlab_uid: nil, gitlab_username: nil, gitlab_avatar_url: nil)
Rails.logger.info "GitLab account unlinked for User ##{current_user.id}"
redirect_to my_settings_path, notice: "GitLab account unlinked successfully"
end

def email
email = params[:email].downcase
continue_param = params[:continue]
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/settings/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def user_props
can_request_deletion: @user.can_request_deletion?,
github_uid: @user.github_uid,
github_username: @user.github_username,
gitlab_uid: @user.gitlab_uid,
gitlab_username: @user.gitlab_username,
slack_uid: @user.slack_uid
}
end
Expand All @@ -96,6 +98,8 @@ def paths_props
slack_auth_path: slack_auth_path,
github_auth_path: github_auth_path,
github_unlink_path: github_unlink_path,
gitlab_auth_path: gitlab_auth_path,
gitlab_unlink_path: gitlab_unlink_path,
add_email_path: add_email_auth_path,
unlink_email_path: unlink_email_auth_path,
rotate_api_key_path: my_settings_rotate_api_key_path,
Expand Down
7 changes: 6 additions & 1 deletion app/controllers/settings/integrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ def section_props
}
},
github: {
connected: @user.github_uid.present?,
connected: @user.github_connected?,
username: @user.github_username,
profile_url: (@user.github_username.present? ? "https://github.com/#{@user.github_username}" : nil)
},
gitlab: {
connected: @user.gitlab_connected?,
username: @user.gitlab_username,
profile_url: (@user.gitlab_username.present? ? "https://gitlab.com/#{@user.gitlab_username}" : nil)
},
emails: @user.email_addresses.map { |email|
{
email: email.email,
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/static_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ def signed_in_props
ssp_message: @ssp_message,
ssp_users_recent: @ssp_users_recent || [],
ssp_users_size: @ssp_users_size || @ssp_users_recent&.size || 0,
github_uid_blank: current_user&.github_uid.blank?,
repo_host_account_blank: !current_user&.repo_host_connected?,
github_auth_path: github_auth_path,
gitlab_auth_path: gitlab_auth_path,
wakatime_setup_path: my_wakatime_setup_path,
dashboard_stats: InertiaRails.defer { dashboard_stats_payload }
}
Expand Down
10 changes: 6 additions & 4 deletions app/javascript/pages/Home/SignedIn.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@
ssp_message,
ssp_users_recent,
ssp_users_size,
github_uid_blank,
repo_host_account_blank,
github_auth_path,
gitlab_auth_path,
wakatime_setup_path,
dashboard_stats,
}: {
Expand All @@ -78,8 +79,9 @@
ssp_message?: string | null;
ssp_users_recent: SocialProofUser[];
ssp_users_size: number;
github_uid_blank: boolean;
repo_host_account_blank: boolean;
github_auth_path: string;
gitlab_auth_path: string;
wakatime_setup_path: string;
dashboard_stats?: {
filterable_dashboard_data: FilterableDashboardData;
Expand Down Expand Up @@ -125,8 +127,8 @@
{ssp_users_recent}
{ssp_users_size}
/>
{:else if github_uid_blank}
<GitHubLinkBanner {github_auth_path} />
{:else if repo_host_account_blank}
<GitHubLinkBanner {github_auth_path} {gitlab_auth_path} />
{/if}

<Deferred data="dashboard_stats">
Expand Down
29 changes: 21 additions & 8 deletions app/javascript/pages/Home/signedIn/GitHubLinkBanner.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<script lang="ts">
let { github_auth_path }: { github_auth_path: string } = $props();
let {
github_auth_path,
gitlab_auth_path,
}: {
github_auth_path: string;
gitlab_auth_path: string;
} = $props();
</script>

<div class="bg-dark border border-primary/40 rounded-xl p-4 md:p-5 mb-4">
Expand All @@ -19,14 +25,21 @@
/></svg
>
<span class="text-surface-content"
>Link your GitHub account to unlock project linking, show what you're
working on, and qualify for leaderboards!</span
>Link GitHub or GitLab to unlock project linking, show what you're
working on, and qualify for leaderboards.</span
>
</div>
<div class="flex w-full flex-col gap-2 md:w-fit md:flex-row">
<a
href={github_auth_path}
class="bg-primary hover:opacity-90 text-on-primary font-medium px-4 py-2 rounded-lg transition-colors duration-200 shrink-0 text-center w-full md:w-fit"
data-turbo="false">Connect GitHub</a
>
<a
href={gitlab_auth_path}
class="bg-surface-100 hover:bg-surface-200 text-surface-content font-medium px-4 py-2 rounded-lg transition-colors duration-200 shrink-0 text-center w-full md:w-fit"
data-turbo="false">Connect GitLab</a
>
</div>
<a
href={github_auth_path}
class="bg-primary hover:opacity-90 text-on-primary font-medium px-4 py-2 rounded-lg transition-colors duration-200 shrink-0 text-center w-full md:w-fit"
data-turbo="false">Connect GitHub</a
>
</div>
</div>
19 changes: 14 additions & 5 deletions app/javascript/pages/Leaderboards/Index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
country,
leaderboard,
is_logged_in,
github_uid_blank,
repo_host_account_blank,
github_auth_path,
gitlab_auth_path,
settings_path,
entries,
}: {
Expand All @@ -33,8 +34,9 @@
country: LeaderboardCountry;
leaderboard: LeaderboardMeta | null;
is_logged_in: boolean;
github_uid_blank: boolean;
repo_host_account_blank: boolean;
github_auth_path: string;
gitlab_auth_path: string;
settings_path: string;
entries?: LeaderboardEntriesPayload;
} = $props();
Expand Down Expand Up @@ -136,14 +138,21 @@
</p>
{/if}

{#if github_uid_blank}
{#if repo_host_account_blank}
<div
class="bg-darker border border-primary rounded-lg p-4 flex flex-col sm:flex-row sm:items-center gap-3"
>
<span class="text-surface-content"
>Connect your GitHub to qualify for the leaderboard.</span
>Connect GitHub or GitLab to qualify for the leaderboard.</span
>
<Button href={github_auth_path} native size="md">Connect GitHub</Button>
<div class="flex flex-col gap-2 sm:flex-row">
<Button href={github_auth_path} native size="md"
>Connect GitHub</Button
>
<Button href={gitlab_auth_path} native size="md" variant="surface"
>Connect GitLab</Button
>
</div>
</div>
{/if}

Expand Down
24 changes: 17 additions & 7 deletions app/javascript/pages/Projects/Index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
index_path: string;
show_archived: boolean;
archived_count: number;
github_connected: boolean;
repo_host_connected: boolean;
github_auth_path: string;
gitlab_auth_path: string;
settings_path: string;
interval?: string | null;
from?: string | null;
Expand All @@ -57,8 +58,9 @@
index_path,
show_archived,
archived_count,
github_connected,
repo_host_connected,
github_auth_path,
gitlab_auth_path,
settings_path,
interval = "",
from = "",
Expand Down Expand Up @@ -204,15 +206,23 @@
</div>
</div>

{#if !github_connected}
{#if !repo_host_connected}
<div class="mb-4 rounded-xl border border-yellow/30 bg-yellow/10 p-4">
<p class="text-base font-medium text-surface-content">
Heads up! You can't link projects to GitHub until you connect your
account.
Heads up! You can't link projects to GitHub or GitLab until you connect
an account.
</p>
<div class="mt-3 flex flex-wrap gap-2">
<Button href={github_auth_path} native class="w-full sm:w-fit">
Sign in with GitHub
Connect GitHub
</Button>
<Button
href={gitlab_auth_path}
native
variant="surface"
class="w-full sm:w-fit"
>
Connect GitLab
</Button>
<Button href={settings_path} variant="surface" class="w-full sm:w-fit">
Open settings
Expand Down Expand Up @@ -511,7 +521,7 @@
type="url"
name="project_repo_mapping[repo_url]"
bind:value={repoUrlDraft}
placeholder="https://github.com/owner/repo"
placeholder="https://github.com/owner/repo or https://gitlab.com/group/subgroup/repo"
class="w-full rounded-lg border border-surface-200 bg-darker px-3 py-2 text-sm text-surface-content focus:border-primary focus:outline-none"
/>

Expand Down
Loading